gamnit: use API 19 services to fix premultiplied texture on Android
[nit.git] / lib / gamnit / display_android.nit
index 3ae7ee5..8e5566c 100644 (file)
@@ -37,7 +37,7 @@ redef class GamnitDisplay
                setup_egl_display native_display
 
                # We need 8 bits per color for selection by color
-               select_egl_config(8, 8, 8, 0, 8, 0, 0)
+               select_egl_config(red_bits, green_bits, blue_bits, 0, 8, 0, 0)
 
                var format = egl_config.attribs(egl_display).native_visual_id
                native_window.set_buffers_geometry(0, 0, format)
@@ -50,19 +50,24 @@ end
 
 redef class TextureAsset
 
+       private fun load_bitmap(asset_manager: AssetManager, path: String): NativeBitmap
+       do
+               return asset_manager.bitmap(path)
+       end
+
        redef fun load_from_platform
        do
                jni_env.push_local_frame 4
 
                var asset_manager = app.asset_manager
-               var bmp = asset_manager.bitmap(path)
+               var bmp = load_bitmap(asset_manager, path)
                if bmp.is_java_null then
                        error = new Error("Failed to load texture at '{path}'")
                        jni_env.pop_local_frame
                        return
                end
 
-               var buf = bmp.copy_pixels
+               var buf = bmp.copy_pixels(unmultiply=not premultiply_alpha)
                loaded = true
                width = bmp.width.to_f
                height = bmp.height.to_f