General display class, is sized and drawable

Introduced properties

fun aspect_ratio: Float

gamnit :: GamnitDisplay :: aspect_ratio

Aspect ratio of the screen, width / height
protected fun aspect_ratio=(aspect_ratio: Float)

gamnit :: GamnitDisplay :: aspect_ratio=

fun blue_bits: Int

gamnit :: GamnitDisplay :: blue_bits

Number of bits used for the blue value in the color buffer
fun check_egl_context(native_window: Pointer): Bool

gamnit :: GamnitDisplay :: check_egl_context

Check if the current configuration of native_window is still valid
fun close

gamnit :: GamnitDisplay :: close

Close this display and free underlying resources
fun close_egl

gamnit :: GamnitDisplay :: close_egl

Close the EGL context
fun close_sdl

gamnit :: GamnitDisplay :: close_sdl

Close the SDL display
fun egl_config: EGLConfig

gamnit :: GamnitDisplay :: egl_config

The selected EGL configuration
protected fun egl_config=(egl_config: EGLConfig)

gamnit :: GamnitDisplay :: egl_config=

The selected EGL configuration
fun egl_context: EGLContext

gamnit :: GamnitDisplay :: egl_context

The EGL context
protected fun egl_context=(egl_context: EGLContext)

gamnit :: GamnitDisplay :: egl_context=

The EGL context
fun egl_display: EGLDisplay

gamnit :: GamnitDisplay :: egl_display

The EGL display
protected fun egl_display=(egl_display: EGLDisplay)

gamnit :: GamnitDisplay :: egl_display=

The EGL display
fun feed_events

gamnit :: GamnitDisplay :: feed_events

Loop on available events and feed them back to the app
fun flip

gamnit :: GamnitDisplay :: flip

Flip the display buffers
fun gl_extensions: Array[String]

gamnit :: GamnitDisplay :: gl_extensions

Extensions to OpenGL ES 2.0 supported by the current configuration
protected fun gl_extensions=(gl_extensions: Array[String])

gamnit :: GamnitDisplay :: gl_extensions=

Extensions to OpenGL ES 2.0 supported by the current configuration
fun glk_view: NitGLKView

gamnit :: GamnitDisplay :: glk_view

Underlying GLKit game controller and view
protected fun glk_view=(glk_view: NitGLKView)

gamnit :: GamnitDisplay :: glk_view=

Underlying GLKit game controller and view
fun green_bits: Int

gamnit :: GamnitDisplay :: green_bits

Number of bits used for the green value in the color buffer
abstract fun height: Int

gamnit :: GamnitDisplay :: height

Height of the display, in pixels
fun height=(value: Int)

gamnit :: GamnitDisplay :: height=

Actual height or desired height of the window, can be set before calling setup
protected fun height=(height: Int)

gamnit :: GamnitDisplay :: height=

protected fun height=(height: Int)

gamnit :: GamnitDisplay :: height=

fun lock_cursor: Bool

gamnit :: GamnitDisplay :: lock_cursor

Is the cursor locked et the center of the screen?
fun lock_cursor=(lock_cursor: Bool)

gamnit :: GamnitDisplay :: lock_cursor=

Is the cursor locked et the center of the screen?
fun mix_init_flags: MixInitFlags

gamnit :: GamnitDisplay :: mix_init_flags

SDL2 mixer initialization flags
fun mix_init_flags=(mix_init_flags: MixInitFlags)

gamnit :: GamnitDisplay :: mix_init_flags=

SDL2 mixer initialization flags
fun native_window_is_invalid: Bool

gamnit :: GamnitDisplay :: native_window_is_invalid

Return value from check_egl_context, the current native window is invalid
protected fun native_window_is_invalid=(native_window_is_invalid: Bool)

gamnit :: GamnitDisplay :: native_window_is_invalid=

Return value from check_egl_context, the current native window is invalid
fun red_bits: Int

gamnit :: GamnitDisplay :: red_bits

Number of bits used for the red value in the color buffer
fun sdl_window: SDLWindow

gamnit :: GamnitDisplay :: sdl_window

The SDL display managing the window and events
protected fun sdl_window=(sdl_window: SDLWindow)

gamnit :: GamnitDisplay :: sdl_window=

The SDL display managing the window and events
fun sdl_window_flags: SDLWindowFlags

gamnit :: GamnitDisplay :: sdl_window_flags

SDL2 window initialization flags
fun sdl_window_flags=(sdl_window_flags: SDLWindowFlags)

gamnit :: GamnitDisplay :: sdl_window_flags=

SDL2 window initialization flags
protected fun select_egl_config(red: Int, green: Int, blue: Int, alpha: Int, depth: Int, stencil: Int)

gamnit :: GamnitDisplay :: select_egl_config

Select an EGL config
abstract fun setup

gamnit :: GamnitDisplay :: setup

Prepare this display
protected fun setup_egl_context(native_window: Pointer)

gamnit :: GamnitDisplay :: setup_egl_context

Setup the EGL context for the given native_window
protected fun setup_egl_display(native_display: Pointer)

gamnit :: GamnitDisplay :: setup_egl_display

Setup the EGL display for the given native_display
fun setup_sdl(window_width: Int, window_height: Int): SDLWindow

gamnit :: GamnitDisplay :: setup_sdl

Setup the SDL display and lib
fun show_cursor: Bool

gamnit :: GamnitDisplay :: show_cursor

Is the cursor visible?
fun show_cursor=(show_cursor: Bool)

gamnit :: GamnitDisplay :: show_cursor=

Is the cursor visible?
abstract fun width: Int

gamnit :: GamnitDisplay :: width

Width of the display, in pixels
protected fun width=(width: Int)

gamnit :: GamnitDisplay :: width=

fun width=(value: Int)

gamnit :: GamnitDisplay :: width=

Actual width or desired width of the window, can be set before calling setup
protected fun width=(width: Int)

gamnit :: GamnitDisplay :: width=

fun window_surface: EGLSurface

gamnit :: GamnitDisplay :: window_surface

The EGL surface for the window
protected fun window_surface=(window_surface: EGLSurface)

gamnit :: GamnitDisplay :: window_surface=

The EGL surface for the window
fun window_title: String

gamnit :: GamnitDisplay :: window_title

Title of the window, must be set before creating the window (or redef)
fun window_title=(window_title: String)

gamnit :: GamnitDisplay :: window_title=

Title of the window, must be set before creating the window (or redef)

Redefined properties

redef type SELF: GamnitDisplay

gamnit $ GamnitDisplay :: SELF

Type of this instance, automatically specialized in every class
redef fun aspect_ratio: Float

gamnit :: stereoscopic_view $ GamnitDisplay :: aspect_ratio

With stereoscopic view, the aspect ratio (in each eye) is half of the screen
redef fun aspect_ratio: Float

gamnit :: gamnit_linux $ GamnitDisplay :: aspect_ratio

Aspect ratio of the screen, width / height
redef fun close

gamnit :: display_linux $ GamnitDisplay :: close

Close EGL and SDL in reverse order of setup (nothing to do for X11)
redef fun close

gamnit :: display_android $ GamnitDisplay :: close

Close this display and free underlying resources
redef fun flip

gamnit :: egl $ GamnitDisplay :: flip

Flip the display buffers
redef fun height: Int

gamnit :: egl $ GamnitDisplay :: height

Height of the display, in pixels
redef fun height: Int

gamnit :: display_ios $ GamnitDisplay :: height

Height of the display, in pixels
redef fun height: Int

gamnit :: gamnit_android $ GamnitDisplay :: height

Height of the display, in pixels
redef fun lock_cursor: Bool

gamnit :: display_linux $ GamnitDisplay :: lock_cursor

Is the cursor locked et the center of the screen?
redef fun lock_cursor=(val: Bool)

gamnit :: display_linux $ GamnitDisplay :: lock_cursor=

Is the cursor locked et the center of the screen?
redef fun setup

gamnit :: display_ios $ GamnitDisplay :: setup

Prepare this display
redef fun setup

gamnit :: display_android $ GamnitDisplay :: setup

Prepare this display
redef fun setup

gamnit :: display_linux $ GamnitDisplay :: setup

Setup SDL, wm, EGL in order
redef fun show_cursor: Bool

gamnit :: display_linux $ GamnitDisplay :: show_cursor

Is the cursor visible?
redef fun show_cursor=(val: Bool)

gamnit :: display_linux $ GamnitDisplay :: show_cursor=

Is the cursor visible?
redef fun width: Int

gamnit :: gamnit_android $ GamnitDisplay :: width

Width of the display, in pixels
redef fun width: Int

gamnit :: display_ios $ GamnitDisplay :: width

Width of the display, in pixels
redef fun width: Int

gamnit :: egl $ GamnitDisplay :: width

Width of the display, in pixels

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun aspect_ratio: Float

gamnit :: GamnitDisplay :: aspect_ratio

Aspect ratio of the screen, width / height
protected fun aspect_ratio=(aspect_ratio: Float)

gamnit :: GamnitDisplay :: aspect_ratio=

fun blue_bits: Int

gamnit :: GamnitDisplay :: blue_bits

Number of bits used for the blue value in the color buffer
fun check_egl_context(native_window: Pointer): Bool

gamnit :: GamnitDisplay :: check_egl_context

Check if the current configuration of native_window is still valid
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun close

gamnit :: GamnitDisplay :: close

Close this display and free underlying resources
fun close_egl

gamnit :: GamnitDisplay :: close_egl

Close the EGL context
fun close_sdl

gamnit :: GamnitDisplay :: close_sdl

Close the SDL display
fun egl_config: EGLConfig

gamnit :: GamnitDisplay :: egl_config

The selected EGL configuration
protected fun egl_config=(egl_config: EGLConfig)

gamnit :: GamnitDisplay :: egl_config=

The selected EGL configuration
fun egl_context: EGLContext

gamnit :: GamnitDisplay :: egl_context

The EGL context
protected fun egl_context=(egl_context: EGLContext)

gamnit :: GamnitDisplay :: egl_context=

The EGL context
fun egl_display: EGLDisplay

gamnit :: GamnitDisplay :: egl_display

The EGL display
protected fun egl_display=(egl_display: EGLDisplay)

gamnit :: GamnitDisplay :: egl_display=

The EGL display
fun feed_events

gamnit :: GamnitDisplay :: feed_events

Loop on available events and feed them back to the app
fun flip

gamnit :: GamnitDisplay :: flip

Flip the display buffers
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun gl_extensions: Array[String]

gamnit :: GamnitDisplay :: gl_extensions

Extensions to OpenGL ES 2.0 supported by the current configuration
protected fun gl_extensions=(gl_extensions: Array[String])

gamnit :: GamnitDisplay :: gl_extensions=

Extensions to OpenGL ES 2.0 supported by the current configuration
fun glk_view: NitGLKView

gamnit :: GamnitDisplay :: glk_view

Underlying GLKit game controller and view
protected fun glk_view=(glk_view: NitGLKView)

gamnit :: GamnitDisplay :: glk_view=

Underlying GLKit game controller and view
fun green_bits: Int

gamnit :: GamnitDisplay :: green_bits

Number of bits used for the green value in the color buffer
fun hash: Int

core :: Object :: hash

The hash code of the object.
abstract fun height: Int

gamnit :: GamnitDisplay :: height

Height of the display, in pixels
protected fun height=(height: Int)

gamnit :: GamnitDisplay :: height=

fun height=(value: Int)

gamnit :: GamnitDisplay :: height=

Actual height or desired height of the window, can be set before calling setup
protected fun height=(height: Int)

gamnit :: GamnitDisplay :: height=

init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun lock_cursor: Bool

gamnit :: GamnitDisplay :: lock_cursor

Is the cursor locked et the center of the screen?
fun lock_cursor=(lock_cursor: Bool)

gamnit :: GamnitDisplay :: lock_cursor=

Is the cursor locked et the center of the screen?
fun mix_init_flags: MixInitFlags

gamnit :: GamnitDisplay :: mix_init_flags

SDL2 mixer initialization flags
fun mix_init_flags=(mix_init_flags: MixInitFlags)

gamnit :: GamnitDisplay :: mix_init_flags=

SDL2 mixer initialization flags
fun native_window_is_invalid: Bool

gamnit :: GamnitDisplay :: native_window_is_invalid

Return value from check_egl_context, the current native window is invalid
protected fun native_window_is_invalid=(native_window_is_invalid: Bool)

gamnit :: GamnitDisplay :: native_window_is_invalid=

Return value from check_egl_context, the current native window is invalid
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun red_bits: Int

gamnit :: GamnitDisplay :: red_bits

Number of bits used for the red value in the color buffer
fun sdl_window: SDLWindow

gamnit :: GamnitDisplay :: sdl_window

The SDL display managing the window and events
protected fun sdl_window=(sdl_window: SDLWindow)

gamnit :: GamnitDisplay :: sdl_window=

The SDL display managing the window and events
fun sdl_window_flags: SDLWindowFlags

gamnit :: GamnitDisplay :: sdl_window_flags

SDL2 window initialization flags
fun sdl_window_flags=(sdl_window_flags: SDLWindowFlags)

gamnit :: GamnitDisplay :: sdl_window_flags=

SDL2 window initialization flags
protected fun select_egl_config(red: Int, green: Int, blue: Int, alpha: Int, depth: Int, stencil: Int)

gamnit :: GamnitDisplay :: select_egl_config

Select an EGL config
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
abstract fun setup

gamnit :: GamnitDisplay :: setup

Prepare this display
protected fun setup_egl_context(native_window: Pointer)

gamnit :: GamnitDisplay :: setup_egl_context

Setup the EGL context for the given native_window
protected fun setup_egl_display(native_display: Pointer)

gamnit :: GamnitDisplay :: setup_egl_display

Setup the EGL display for the given native_display
fun setup_sdl(window_width: Int, window_height: Int): SDLWindow

gamnit :: GamnitDisplay :: setup_sdl

Setup the SDL display and lib
fun show_cursor: Bool

gamnit :: GamnitDisplay :: show_cursor

Is the cursor visible?
fun show_cursor=(show_cursor: Bool)

gamnit :: GamnitDisplay :: show_cursor=

Is the cursor visible?
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
abstract fun width: Int

gamnit :: GamnitDisplay :: width

Width of the display, in pixels
protected fun width=(width: Int)

gamnit :: GamnitDisplay :: width=

protected fun width=(width: Int)

gamnit :: GamnitDisplay :: width=

fun width=(value: Int)

gamnit :: GamnitDisplay :: width=

Actual width or desired width of the window, can be set before calling setup
fun window_surface: EGLSurface

gamnit :: GamnitDisplay :: window_surface

The EGL surface for the window
protected fun window_surface=(window_surface: EGLSurface)

gamnit :: GamnitDisplay :: window_surface=

The EGL surface for the window
fun window_title: String

gamnit :: GamnitDisplay :: window_title

Title of the window, must be set before creating the window (or redef)
fun window_title=(window_title: String)

gamnit :: GamnitDisplay :: window_title=

Title of the window, must be set before creating the window (or redef)
package_diagram gamnit::GamnitDisplay GamnitDisplay core::Object Object gamnit::GamnitDisplay->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

gamnit $ GamnitDisplay
# General display class, is sized and drawable
class GamnitDisplay

	# Width of the display, in pixels
	fun width: Int is abstract

	# Height of the display, in pixels
	fun height: Int is abstract

	# Aspect ratio of the screen, `width / height`
	fun aspect_ratio: Float do return width.to_f / height.to_f

	# Is the cursor locked et the center of the screen?
	var lock_cursor = false is writable

	# Is the cursor visible?
	#
	# Only affects the desktop implementations.
	var show_cursor: Bool = true is writable

	# Number of bits used for the red value in the color buffer
	fun red_bits: Int do return 8

	# Number of bits used for the green value in the color buffer
	fun green_bits: Int do return 8

	# Number of bits used for the blue value in the color buffer
	fun blue_bits: Int do return 8

	# Prepare this display
	#
	# The implementation varies per platform.
	fun setup is abstract

	# Close this display and free underlying resources
	#
	# The implementation varies per platform.
	fun close do end

	# Flip the display buffers
	#
	# The implementation varies per platform.
	fun flip do end

	# Loop on available events and feed them back to the app
	#
	# The implementation varies per platform.
	fun feed_events do end

	# Extensions to OpenGL ES 2.0 supported by the current configuration
	var gl_extensions: Array[String] is lazy do return glGetString(gl_EXTENSIONS).split(' ')
end
lib/gamnit/display.nit:28,1--79,3

gamnit :: egl $ GamnitDisplay
redef class GamnitDisplay

	# The EGL display
	var egl_display: EGLDisplay is noautoinit

	# The EGL context
	var egl_context: EGLContext is noautoinit

	# The EGL surface for the window
	var window_surface: EGLSurface is noautoinit

	# The selected EGL configuration
	var egl_config: EGLConfig is noautoinit

	# Setup the EGL display for the given `native_display`
	protected fun setup_egl_display(native_display: Pointer)
	do
		var egl_display = new EGLDisplay(native_display)
		assert egl_display.is_valid else print "new EGL display is not valid"

		egl_display.initialize
		assert egl_display.is_valid else print "EGL initialize error: {egl_display.error}"

		self.egl_display = egl_display
	end

	# Select an EGL config
	protected fun select_egl_config(red, green, blue, alpha, depth, stencil: Int)
	do
		var config_chooser = new EGLConfigChooser
		config_chooser.renderable_type_egl
		config_chooser.surface_type_egl
		config_chooser.red_size = red
		config_chooser.green_size = green
		config_chooser.blue_size = blue
		if alpha > 0 then config_chooser.alpha_size = alpha
		if depth > 0 then config_chooser.depth_size = depth
		if stencil > 0 then config_chooser.stencil_size = stencil

		config_chooser.sample_buffers = 1
		config_chooser.samples = 4

		config_chooser.close

		var configs = config_chooser.choose(egl_display)
		assert configs != null else print "Choosing EGL config failed: {egl_display.error}"
		assert not configs.is_empty else print "Found no EGL config"

		if debug_gamnit then
			print "EGL available configurations:"
			for config in configs do
				var attribs = config.attribs(egl_display)
				print "* Conformant to: {attribs.conformant}"
				print "  Caveats: {attribs.caveat}"
				print "  Size of RGBA: {attribs.red_size} {attribs.green_size} {attribs.blue_size} {attribs.alpha_size}"
				print "  Buffer, depth, stencil: {attribs.buffer_size} {attribs.depth_size} {attribs.stencil_size}"
				print "  Sample buffers, samples: {attribs.sample_buffers} {attribs.samples}"
			end
		end

		# We use the first one, it is recommended
		self.egl_config = configs.first
	end

	# Setup the EGL context for the given `native_window`
	protected fun setup_egl_context(native_window: Pointer)
	do
		var window_surface = egl_display.create_window_surface(egl_config, native_window, [0])
		assert window_surface.is_ok else print "Creating EGL window surface failed: {egl_display.error}"
		self.window_surface = window_surface

		egl_context = egl_display.create_context(egl_config)
		assert egl_context.is_ok else print "Creating EGL context failed: {egl_display.error}"

		var make_current_res = egl_display.make_current(window_surface, window_surface, egl_context)
		assert make_current_res else print "Creating EGL make current failed: {egl_display.error}"

		# TODO make the API selection configurable per platform
		assert egl_bind_opengl_es_api else print "EGL bind API failed: {egl_display.error}"
	end

	# Check if the current configuration of `native_window` is still valid
	#
	# There is two return values:
	# * Returns `true` if the Gamnit services should be recreated.
	# * Sets `native_window_is_invalid` if the system provided window handle is invalid.
	#   We should wait until we are provided a valid window handle.
	fun check_egl_context(native_window: Pointer): Bool
	do
		native_window_is_invalid = false

		if not egl_context.is_ok then
			# Needs recreating
			egl_context = egl_display.create_context(egl_config)
			assert egl_context.is_ok else print "Creating EGL context failed: {egl_display.error}"
		end

		var success = egl_display.make_current(window_surface, window_surface, egl_context)
		if not success then
			var error = egl_display.error
			print "check_egl_context make_current: {error}"


			if error.is_bad_native_window then
				# native_window is invalid
				native_window_is_invalid = true
				return true

			else if not error.is_success then
				# The context is now invalid, rebuild it
				setup_egl_context native_window
				return true
			end
		end
		return false
	end

	# Return value from `check_egl_context`, the current native window is invalid
	#
	# We should wait until we are provided a valid window handle.
	var native_window_is_invalid = false

	redef fun width do return window_surface.attribs(egl_display).width

	redef fun height do return window_surface.attribs(egl_display).height

	# Close the EGL context
	fun close_egl
	do
		egl_display.make_current(new EGLSurface.none, new EGLSurface.none, new EGLContext.none)
		egl_display.destroy_context(egl_context)
		egl_display.destroy_surface(window_surface)
	end

	redef fun flip
	do
		assert glGetError == gl_NO_ERROR

		assert egl_display.is_valid

		egl_display.swap_buffers(window_surface)
	end
end
lib/gamnit/egl.nit:22,1--164,3

gamnit :: display_ios $ GamnitDisplay
redef class GamnitDisplay

	redef var width = 200
	redef var height = 300

	# Underlying GLKit game controller and view
	var glk_view: NitGLKView is noautoinit

	redef fun setup
	do
		var view = new GamnitGLKView
		view.multiple_touch_enabled = true
		self.glk_view = view
		self.width = view.drawable_width
		self.height = view.drawable_height
	end
end
lib/gamnit/display_ios.nit:28,1--44,3

gamnit :: display_linux $ GamnitDisplay
redef class GamnitDisplay

	# Actual width or desired width of the window, can be set before calling `setup`
	fun width=(value: Int) do requested_width = value
	private var requested_width = 1920

	# Actual height or desired height of the window, can be set before calling `setup`
	fun height=(value: Int) do requested_height = value
	private var requested_height = 1080

	redef fun show_cursor do return sdl.show_cursor

	redef fun show_cursor=(val) do sdl.show_cursor = val

	redef fun lock_cursor=(val) do sdl.relative_mouse_mode = val

	redef fun lock_cursor do return sdl.relative_mouse_mode

	# Setup SDL, wm, EGL in order
	redef fun setup
	do
		if debug_gamnit then print "Setting up SDL"
		self.sdl_window = setup_sdl(requested_width, requested_height)

		if debug_gamnit then print "Setting up window manager"
		setup_egl_display sdl_window.wm_info.display_handle

		if debug_gamnit then print "Setting up EGL context"
		select_egl_config(red_bits, green_bits, blue_bits, 8, 8, 0)
		setup_egl_context sdl_window.wm_info.window_handle
	end

	# Close EGL and SDL in reverse order of `setup` (nothing to do for X11)
	redef fun close
	do
		close_egl
		close_sdl
	end

	# ---
	# SDL

	# The SDL display managing the window and events
	var sdl_window: SDLWindow is noautoinit

	# Title of the window, must be set before creating the window (or redef)
	var window_title = "gamnit game" is lazy, writable

	# Setup the SDL display and lib
	fun setup_sdl(window_width, window_height: Int): SDLWindow
	do
		assert sdl.initialize((new SDLInitFlags).video.audio) else
			print_error "Failed to initialize SDL2: {sdl.error}"
		end

		var img_flags = (new SDLImgInitFlags).png.jpg
		assert sdl.img.initialize(img_flags) == img_flags else
			print_error "Failed to initialize SDL2 IMG: {sdl.error}"
		end

		var sdl_window = new SDLWindow(window_title.to_cstring, window_width, window_height, sdl_window_flags)
		assert not sdl_window.address_is_null else
			print_error "Failed to create SDL2 window: {sdl.error}"
		end

		# Audio support
		var inited = mix.initialize(mix_init_flags)
		if inited != mix_init_flags then
			print_error "Failed to load SDL2 mixer format supports: {mix.error}"
		end

		var open = mix.open_audio(44100, mix.default_format, 2, 1024)
		if not open then
			print_error "Failed to initialize SDL2 mixer: {mix.error}"
		end

		return sdl_window
	end

	# SDL2 window initialization flags
	#
	# The default value supports OpenGL and window resizing.
	var sdl_window_flags: SDLWindowFlags = (new SDLWindowFlags).opengl.resizable is lazy, writable

	# SDL2 mixer initialization flags
	#
	# Defaults to FLAC, MP3 and OGG.
	var mix_init_flags: MixInitFlags = mix.flac | mix.mp3 | mix.ogg is lazy, writable

	# Close the SDL display
	fun close_sdl
	do
		sdl_window.destroy
		mix.close_audio
		mix.quit
		sdl.finalize
	end
end
lib/gamnit/display_linux.nit:25,1--122,3

gamnit :: display_android $ GamnitDisplay
redef class GamnitDisplay

	redef fun setup
	do
		var native_display = egl_default_display
		var native_window = app.native_app_glue.window

		setup_egl_display native_display

		# We need 8 bits per color for selection by color
		select_egl_config(red_bits, green_bits, blue_bits, 0, 8, 0)

		var format = egl_config.attribs(egl_display).native_visual_id
		assert not native_window.address_is_null
		native_window.set_buffers_geometry(0, 0, format)

		setup_egl_context native_window
	end

	redef fun close do close_egl
end
lib/gamnit/display_android.nit:32,1--52,3

gamnit :: stereoscopic_view $ GamnitDisplay
redef class GamnitDisplay

	# With stereoscopic view, the aspect ratio (in each eye) is half of the screen
	redef fun aspect_ratio do return super / 2.0
end
lib/gamnit/depth/stereoscopic_view.nit:57,1--61,3

gamnit :: gamnit_linux $ GamnitDisplay
redef class GamnitDisplay
	redef var aspect_ratio = super is lazy
end
lib/gamnit/gamnit_linux.nit:59,1--61,3

gamnit :: gamnit_android $ GamnitDisplay
redef class GamnitDisplay

	redef var width = 1080
	redef var height = 720

	# Update `width` and `height`
	private fun update_size
	do
		var context = app.native_activity
		self.width = context.window_width
		self.height = context.window_height
	end
end
lib/gamnit/gamnit_android.nit:278,1--290,3