Skip to content

Commit

Permalink
Check window width and height in render script
Browse files Browse the repository at this point in the history
Fixes #68
  • Loading branch information
britzl committed Feb 21, 2024
1 parent ae92852 commit ea4465d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
1 change: 0 additions & 1 deletion game.project
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[project]
title = Orthographic
version = 0.9
write_log = 1
dependencies#0 = https://github.com/britzl/deftest/archive/2.7.0.zip
dependencies#1 = https://github.com/britzl/gooey/archive/refs/tags/10.4.0.zip
dependencies#2 = https://github.com/subsoap/defos/archive/refs/tags/v2.7.1.zip
Expand Down
32 changes: 18 additions & 14 deletions orthographic/render/orthographic.render_script
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,24 @@ function update(self)
render.draw_debug3d()
end
end

-- draw gui in screen space using an orthographic projection
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_CULL_FACE)
render.enable_state(render.STATE_STENCIL_TEST)
render.set_viewport(0, 0, render.get_window_width(), render.get_window_height())
view = IDENTITY
render.set_view(view)
proj = vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1)
render.set_projection(proj)
frustum = proj * view
render.draw(self.gui_pred, {frustum = frustum})
render.draw(self.text_pred, {frustum = frustum})
render.disable_state(render.STATE_STENCIL_TEST)

local window_width = render.get_window_width()
local window_height = render.get_window_height()
if window_width > 0 and window_height > 0 then
-- draw gui in screen space using an orthographic projection
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_CULL_FACE)
render.enable_state(render.STATE_STENCIL_TEST)
render.set_viewport(0, 0, window_width, window_height)
view = IDENTITY
render.set_view(view)
proj = vmath.matrix4_orthographic(0, window_width, 0, window_height, -1, 1)
render.set_projection(proj)
frustum = proj * view
render.draw(self.gui_pred, {frustum = frustum})
render.draw(self.text_pred, {frustum = frustum})
render.disable_state(render.STATE_STENCIL_TEST)
end
end

function on_message(self, message_id, message)
Expand Down

0 comments on commit ea4465d

Please sign in to comment.