Additional Comments
In addition to these demos, I also made a few nice additions to DFGame's API. Since it's mostly a grab-bag of small additions, here's a list:- Predefined colors to use for rendering
- Simplified main loop function
- mesh_render can also bind mesh attributes, which had to be defined separately before
- hashmaps can now be told to delete their contents when being destroyed
- sprites can be told to delete their source when being destroyed
- Window init now enables transparency and depth testing by default
- Function to create a new 2D camera based on a window's dimensions
- Added transformation macros for cameras, to simplify transform_FOO(camera_get_transform(c)) syntax to camera_FOO(c)
- Added a simple version of "copyadd" to data structures, which measures and copies non-pointer values
- Attempting to lerp int literals now uses float lerp, since that's what most reasonable people would expect
- Added an "almost zero" macro for testing floats and doubles
Goals
- Time Left: 3-4 weeks
- Logo Demo: Done
- Comets Demo: 90%
- Heightmap Demo: 60%
- ??? Demo: Not Started
- ??? Demo 2: Not Started
Some Code
As I mentioned in the video above, the Logo Demo was designed to present a simplified example of the init, cleanup, and looping code. To demonstrate that, here's the code:1 #include "camera.h" 2 #include "color.h" 3 #include "interpolate.h" 4 #include "mainloop.h" 5 #include "mesh.h" 6 #include "paths.h" 7 #include "shader_init.h" 8 #include "texture_loader.h" 9 #include "vector.h" 10 #include "window.h" 11 12 GLFWwindow* win; 13 camera c_main; 14 shader s_default; 15 float timer; 16 gltex t_logo; 17 vec4 color; 18 19 bool loop(mainloop l, float dt) { 20 timer += dt; 21 color.a = lerp(0.0f, 1.0f, timer) + lerp(0.0f, -1.0f, timer - 2.5); 22 23 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 24 25 glUseProgram(s_default.id); 26 shader_bind_uniform_name(s_default, "u_transform", mat4_mul(camera_get_vp(c_main), mat4_scale(mat4_ident, 400))); 27 shader_bind_uniform_name(s_default, "u_color", color); 28 shader_bind_uniform_texture_name(s_default, "u_texture", t_logo, GL_TEXTURE0); 29 mesh_render(s_default, mesh_quad(), GL_TRIANGLES, "i_pos", VT_POSITION, "i_uv", VT_TEXTURE); 30 31 glfwSwapBuffers(win); 32 return !glfwWindowShouldClose(win) && timer < 4.0f; 33 } 34 35 int main() { 36 win = window_new_default(1280, 720, "Logo Demo"); 37 init_base_resource_path(NULL); 38 shaders_init(); 39 40 s_default = shader_basic_tex_get(); 41 color = color_white; 42 c_main = window_create_2d_camera(win); 43 char* path = assets_path("logo.png", NULL); 44 t_logo = load_texture_gl(path); 45 sfree(path); 46 47 mainloop_create_run(loop); 48 49 glDeleteTextures(1, &t_logo.handle); 50 camera_free(c_main); 51 shaders_cleanup(); 52 resource_path_free(); 53 window_free_final(win); 54 55 return 0; 56 }There are still a few things that could be simplified here, but this is still much less code than would be required without DFGame. That's the primary goal of the framework, so I'm pretty happy so far!
With DFGame's release now imminent, and the upcoming 5-year anniversary of this blog, next month ought to be pretty exciting. Until then, keep on reading!
No comments:
Post a Comment