Merge: Functional api
[nit.git] / contrib / model_viewer / src / globe.nit
index a5a9a62..be54bce 100644 (file)
@@ -91,12 +91,14 @@ class GlobeMaterial
        init surface do init(0, true, [1.0, 1.0, 1.0, 1.0])
 
        # Create and configure a material for the cloud layer
-       init clouds do init(4, false, [1.0, 1.0, 1.0, 0.5])
+       init clouds do init(4, false, [1.0*clouds_a, 1.0*clouds_a, 1.0*clouds_a, clouds_a])
+       private var clouds_a = 0.5
 
        # Create and configure a material for the visible atmosphere
-       init atmo do init(null, false, [0.0, 0.8, 1.0, 0.05])
+       init atmo do init(null, false, [0.0, 0.8*atmo_a, 1.0*atmo_a, atmo_a])
+       private var atmo_a = 0.05
 
-       redef fun draw(actor, model)
+       redef fun draw(actor, model, camera)
        do
                var gl_error = glGetError
                assert gl_error == gl_NO_ERROR else print gl_error
@@ -106,9 +108,6 @@ class GlobeMaterial
                var program = app.globe_program
                program.use
 
-               # Set constant program values
-               program.use
-
                # Bind textures
                glActiveTexture gl_TEXTURE0
                glBindTexture(gl_TEXTURE_2D, app.texture_earth.gl_texture)
@@ -133,7 +132,7 @@ class GlobeMaterial
                # Update camera view and light
                var p = app.world_camera.position
                program.camera.uniform(p.x, p.y, p.z)
-               program.mvp.uniform app.world_camera.mvp_matrix
+               program.mvp.uniform camera.mvp_matrix
                program.light_center.uniform(app.light.position.x, app.light.position.y, app.light.position.z)
 
                # Set attributes
@@ -228,7 +227,6 @@ class GlobeProgram
                                s += 0.05 * texture2D(tex_displace, tex_coord).r;
 
                        gl_Position = (vec4(coord.xyz * s, 1.0) * rotation + translation) * mvp;
-
                }
                """ @ glsl_vertex_shader