xymus.net: update xymus.net with the API for the mobile client
[nit.git] / lib / gamnit / display_linux.nit
index 109ff51..1dbee21 100644 (file)
@@ -19,7 +19,8 @@ import sdl
 import x11
 
 import egl # local to gamnit
-import display
+intrude import display
+intrude import textures
 
 redef class GamnitDisplay
 
@@ -31,6 +32,10 @@ redef class GamnitDisplay
        fun height=(value: Int) do requested_height = value
        private var requested_height = 1080
 
+       redef fun show_cursor do return sdl_display.show_cursor
+
+       redef fun show_cursor=(val) do sdl_display.show_cursor = val
+
        # Setup SDL, X11, EGL in order
        redef fun setup
        do
@@ -43,7 +48,7 @@ redef class GamnitDisplay
                setup_egl_display x11_display
 
                if debug_gamnit then print "Setting up EGL context"
-               select_egl_config(8, 8, 8, 8, 8, 0, 0)
+               select_egl_config(red_bits, green_bits, blue_bits, 8, 8, 0, 0)
                setup_egl_context window_handle
        end
 
@@ -89,3 +94,24 @@ redef class GamnitDisplay
                return x11_display
        end
 end
+
+redef class TextureAsset
+
+       redef fun load_from_platform
+       do
+               var path = "assets" / path # TODO use app.assets_dir
+               var sdl_tex = new SDLImage.from_file(path)
+
+               if sdl_tex.address_is_null then
+                       error = new Error("Failed to load texture at '{path}'")
+                       return
+               end
+
+               self.width = sdl_tex.width.to_f
+               self.height = sdl_tex.height.to_f
+               var format = if sdl_tex.amask > 0 then gl_RGBA else gl_RGB
+               var pixels = sdl_tex.pixels
+
+               load_from_pixels(pixels, sdl_tex.width, sdl_tex.height, format)
+       end
+end