realtime: 32 bits safe
[nit.git] / lib / gamnit / flat.nit
index 1936763..6487ed2 100644 (file)
@@ -43,6 +43,8 @@ import gamnit
 import gamnit::cameras
 import gamnit::limit_fps
 
+import android_two_fingers_motion is conditional(android)
+
 # Image to draw on screen
 class Sprite
 
@@ -52,7 +54,7 @@ class Sprite
        # Position of this sprite in world coordinates
        var center: Point3d[Float] is writable
 
-       # Rotation on the Z axis
+       # Rotation on the Z axis, where 0.0 points right and `0.5*pi` points up
        var rotation = 0.0 is writable
 
        # Mirror `texture` horizontally, inverting each pixel on the X axis
@@ -83,7 +85,7 @@ class Sprite
                simple_2d_program.color.array_enabled = false
                simple_2d_program.scale.array_enabled = false
 
-               simple_2d_program.translation.uniform(center.x, -center.y, center.z, 0.0)
+               simple_2d_program.translation.uniform(center.x, center.y, center.z, 0.0)
                simple_2d_program.color.uniform(tint[0], tint[1], tint[2], tint[3])
                simple_2d_program.scale.uniform scale
 
@@ -95,7 +97,7 @@ class Sprite
                        else texture.texture_coords, 2)
                simple_2d_program.coord.array(texture.vertices, 3)
 
-               simple_2d_program.rotation.uniform new Matrix.rotation(rotation, 0.0, 0.0, 1.0)
+               simple_2d_program.rotation.uniform new Matrix.rotation(rotation, 0.0, 0.0, -1.0)
 
                glDrawArrays(gl_TRIANGLE_STRIP, 0, 4)
        end
@@ -166,12 +168,11 @@ redef class App
                # Prepare to draw
                for tex in all_root_textures do
                        tex.load
+                       gamnit_error = tex.error
+                       if gamnit_error != null then print_error gamnit_error
 
                        glTexParameteri(gl_TEXTURE_2D, gl_TEXTURE_MIN_FILTER, gl_LINEAR)
                        glTexParameteri(gl_TEXTURE_2D, gl_TEXTURE_MAG_FILTER, gl_LINEAR)
-
-                       gamnit_error = tex.error
-                       assert gamnit_error == null else print_error gamnit_error
                end
        end
 
@@ -360,7 +361,7 @@ class Simple2dProgram
                uniform bool use_texture;
 
                // Texture to apply on this object
-               uniform sampler2D texture;
+               uniform sampler2D texture0;
 
                // Input from the vertex shader
                varying vec4 v_color;
@@ -369,7 +370,7 @@ class Simple2dProgram
                void main()
                {
                        if(use_texture) {
-                               gl_FragColor = v_color * texture2D(texture, v_coord);
+                               gl_FragColor = v_color * texture2D(texture0, v_coord);
                                if (gl_FragColor.a == 0.0) discard;
                        } else {
                                gl_FragColor = v_color;
@@ -384,7 +385,7 @@ class Simple2dProgram
        var use_texture = uniforms["use_texture"].as(UniformBool) is lazy
 
        # Visible texture unit
-       var texture = uniforms["texture"].as(UniformSampler2D) is lazy
+       var texture = uniforms["texture0"].as(UniformSampler2D) is lazy
 
        # Coordinates on the textures, per vertex
        var tex_coord = attributes["tex_coord"].as(AttributeVec2) is lazy