lib/gamnit: add a non-null display argument to frame_core
authorAlexis Laferrière <alexis.laf@xymus.net>
Sat, 12 Dec 2015 16:16:38 +0000 (11:16 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 14 Dec 2015 16:00:01 +0000 (11:00 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/gamnit/examples/globe/src/globe.nit
lib/gamnit/examples/triangle/src/portable_triangle.nit
lib/gamnit/gamnit.nit

index 53a3d2d..570cb5d 100644 (file)
@@ -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
index 8903c9c..9dfa49c 100644 (file)
@@ -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
index a87619b..f68e483 100644 (file)
@@ -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