# Clipping wall the farthest of the camera, defaults to -100.0
var far: Float = -100.0 is writable
- # Width in world units, defaults to the width in pixels of the screen
- var width: Float = display.width.to_f is lazy
+ # Width in world units, calculated from `height` and the screen aspect ratio
+ fun width: Float do return height * display.aspect_ratio
# Height in world units, defaults to 1080.0
#
fun reset_height(height: nullable Float)
do
if height == null then height = display.height.to_f
-
self.height = height
- self.width = height * display.aspect_ratio
end
# Convert the position `x, y` on screen, to UI coordinates
mvp_matrix_cache = null
end
- redef fun width=(value)
- do
- super
- mvp_matrix_cache = null
- end
-
redef fun height=(value)
do
super
# Draw all elements of `actors` and then call `frame_core_flat`
protected fun frame_core_depth(display: GamnitDisplay)
do
+ glViewport(0, 0, display.width, display.height)
frame_core_dynamic_resolution_before display
# Update cameras on both our programs
fun height: Int is abstract
# Aspect ratio of the screen, `width / height`
- var aspect_ratio: Float is lazy do return width.to_f / height.to_f
+ 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
print_error "Failed to initialize SDL2 IMG: {sdl.error}"
end
- var sdl_window = new SDLWindow(window_title.to_cstring, window_width, window_height, (new SDLWindowFlags).opengl)
+ 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
return sdl_window
end
- # Initialization flags passed to SDL2 mixer
+ # 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 all available formats.
var mix_init_flags: MixInitFlags = mix.flac | mix.mod | mix.mp3 | mix.ogg is lazy, writable
import performance_analysis
import gamnit
-import gamnit::cameras_cache
intrude import gamnit::cameras
+intrude import gamnit::cameras_cache
import gamnit::dynamic_resolution
import gamnit::limit_fps
import gamnit::camera_control
do
texture.load
- var splash = new Sprite(texture, ui_camera.center)
+ var splash = new Sprite(texture, ui_camera.center.offset(0.0, 0.0, 0.0))
ui_sprites.add splash
var display = display
if display != null then display.close
end
+ redef fun on_resize(display)
+ do
+ super
+
+ world_camera.mvp_matrix_cache = null
+ ui_camera.mvp_matrix_cache = null
+
+ # Update all sprites in the UI
+ for sprite in ui_sprites do sprite.needs_update
+ end
+
redef fun frame_core(display)
do
# Prepare to draw, clear buffers
# The instances passed as `event` may be freed (or overwritten),
# right after this method returns. They should not be preserved.
fun accept_event(event: InputEvent): Bool do return false
+
+ # The window has been resized by the user or system
+ #
+ # The framework handles resizing the viewport automatically.
+ fun on_resize(display: GamnitDisplay) do end
end
import sdl2::events
intrude import gamnit
+intrude import display_linux
redef class App
private var sdl_event_buffer = new SDLEventBuffer.malloc
# Convert to an SDL event with data
var sdl_event = sdl_event_buffer.to_event
+ if sdl_event isa SDLWindowEvent and sdl_event.is_resized then
+ display.width = sdl_event.data1
+ display.height = sdl_event.data2
+ on_resize display
+ end
+
# Convert to `mnit::inputs` conforming objects
var gamnit_event = sdl_event.to_gamnit_event(sdl_event_buffer)
accept_event gamnit_event