From bf66c8be337faed671b7af7c0e9d91b991a74e73 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sat, 12 Dec 2015 11:16:38 -0500 Subject: [PATCH] lib/gamnit: add a non-null display argument to frame_core MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/gamnit/examples/globe/src/globe.nit | 99 ++++++++++---------- .../examples/triangle/src/portable_triangle.nit | 25 +++-- lib/gamnit/gamnit.nit | 4 +- 3 files changed, 61 insertions(+), 67 deletions(-) diff --git a/lib/gamnit/examples/globe/src/globe.nit b/lib/gamnit/examples/globe/src/globe.nit index 53a3d2d..570cb5d 100644 --- a/lib/gamnit/examples/globe/src/globe.nit +++ b/lib/gamnit/examples/globe/src/globe.nit @@ -400,58 +400,55 @@ redef class App private var clock = new Clock - redef fun frame_core + redef fun frame_core(display) do - var display = display - if display != null then - var t = clock.total.to_f/3.0 + 0.75*pi - - var gl_error = glGetError - assert gl_error == gl_NO_ERROR else print gl_error - - glClear(gl_COLOR_BUFFER_BIT | gl_DEPTH_BUFFER_BIT) - program.use - - # Rotate world - # FIXME do this cleanly by moving the camera - var mvp = new Matrix.rotation(t, 0.0, 1.0, 0.0) * camera.mvp_matrix - program.mvp.uniform mvp - program.camera.uniform(-t.sin, -0.8, -t.cos) - - # Planet - program.coord.array(planet.vertices, 3) - program.tex_coord.array(planet.texture_coords, 2) - program.normal.array(planet.normals, 3) - program.tex.uniform 0 - program.use_texture.uniform true - program.color.uniform(1.0, 1.0, 1.0, 1.0) - program.is_surface.uniform true - glDrawElements(gl_TRIANGLES, planet.indices.length, gl_UNSIGNED_SHORT, planet.indices_c.native_array) - - # Clouds - program.coord.array(clouds.vertices, 3) - program.tex_coord.array(clouds.texture_coords, 2) - program.normal.array(clouds.normals, 3) - program.tex.uniform 4 - program.color.uniform(1.0, 1.0, 1.0, 0.5) # Half transparency - program.is_surface.uniform false - glDrawElements(gl_TRIANGLES, clouds.indices.length, gl_UNSIGNED_SHORT, clouds.indices_c.native_array) - - # Atmo - program.coord.array(atmo.vertices, 3) - program.tex_coord.array(atmo.texture_coords, 2) - program.normal.array(atmo.normals, 3) - program.color.uniform(0.0, 0.8, 1.0, 0.02) # Blueish - program.is_surface.uniform false - program.use_texture.uniform false - glDrawElements(gl_TRIANGLES, atmo.indices.length, gl_UNSIGNED_SHORT, atmo.indices_c.native_array) - assert program.use_texture.is_active - - display.flip - - gl_error = glGetError - assert gl_error == gl_NO_ERROR else print gl_error - end + var t = clock.total.to_f/3.0 + 0.75*pi + + var gl_error = glGetError + assert gl_error == gl_NO_ERROR else print gl_error + + glClear(gl_COLOR_BUFFER_BIT | gl_DEPTH_BUFFER_BIT) + program.use + + # Rotate world + # FIXME do this cleanly by moving the camera + var mvp = new Matrix.rotation(t, 0.0, 1.0, 0.0) * camera.mvp_matrix + program.mvp.uniform mvp + program.camera.uniform(-t.sin, -0.8, -t.cos) + + # Planet + program.coord.array(planet.vertices, 3) + program.tex_coord.array(planet.texture_coords, 2) + program.normal.array(planet.normals, 3) + program.tex.uniform 0 + program.use_texture.uniform true + program.color.uniform(1.0, 1.0, 1.0, 1.0) + program.is_surface.uniform true + glDrawElements(gl_TRIANGLES, planet.indices.length, gl_UNSIGNED_SHORT, planet.indices_c.native_array) + + # Clouds + program.coord.array(clouds.vertices, 3) + program.tex_coord.array(clouds.texture_coords, 2) + program.normal.array(clouds.normals, 3) + program.tex.uniform 4 + program.color.uniform(1.0, 1.0, 1.0, 0.5) # Half transparency + program.is_surface.uniform false + glDrawElements(gl_TRIANGLES, clouds.indices.length, gl_UNSIGNED_SHORT, clouds.indices_c.native_array) + + # Atmo + program.coord.array(atmo.vertices, 3) + program.tex_coord.array(atmo.texture_coords, 2) + program.normal.array(atmo.normals, 3) + program.color.uniform(0.0, 0.8, 1.0, 0.02) # Blueish + program.is_surface.uniform false + program.use_texture.uniform false + glDrawElements(gl_TRIANGLES, atmo.indices.length, gl_UNSIGNED_SHORT, atmo.indices_c.native_array) + assert program.use_texture.is_active + + display.flip + + gl_error = glGetError + assert gl_error == gl_NO_ERROR else print gl_error end redef fun on_stop diff --git a/lib/gamnit/examples/triangle/src/portable_triangle.nit b/lib/gamnit/examples/triangle/src/portable_triangle.nit index 8903c9c..9dfa49c 100644 --- a/lib/gamnit/examples/triangle/src/portable_triangle.nit +++ b/lib/gamnit/examples/triangle/src/portable_triangle.nit @@ -105,25 +105,22 @@ redef class App private var t = 0.0 - redef fun frame_core + redef fun frame_core(display) do - var display = display - if display != null then - glClearColor(t, t, t, 1.0) + glClearColor(t, t, t, 1.0) - assert glGetError == gl_NO_ERROR - glViewport(0, 0, display.width, display.height) - glClear gl_COLOR_BUFFER_BIT - glUseProgram program - vertex_array.enable + assert glGetError == gl_NO_ERROR + glViewport(0, 0, display.width, display.height) + glClear gl_COLOR_BUFFER_BIT + glUseProgram program + vertex_array.enable - glDrawArrays(gl_TRIANGLES, 0, 3) + glDrawArrays(gl_TRIANGLES, 0, 3) - display.flip + display.flip - t += 0.01 - if t > 1.0 then t = 0.0 - end + t += 0.01 + if t > 1.0 then t = 0.0 end redef fun on_stop diff --git a/lib/gamnit/gamnit.nit b/lib/gamnit/gamnit.nit index a87619b..f68e483 100644 --- a/lib/gamnit/gamnit.nit +++ b/lib/gamnit/gamnit.nit @@ -40,7 +40,7 @@ redef class App # Core of the frame logic, executed only when the display is visible # # This method should be redefined by user modules to customize the behavior of the game. - protected fun frame_core do end + protected fun frame_core(display: GamnitDisplay) do end # Full frame logic, executed even if the display is not visible # @@ -51,7 +51,7 @@ redef class App protected fun frame_full do var display = display - if display != null then frame_core + if display != null then frame_core(display) feed_events end -- 1.7.9.5