-
Notifications
You must be signed in to change notification settings - Fork 0
/
rendercam.render_script
82 lines (65 loc) · 2.84 KB
/
rendercam.render_script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
local rendercam = require "rendercam.rendercam"
local vp = rendercam.viewport
local IDENTITY_MATRIX = vmath.matrix4()
local CLEAR_COLOR = hash("clear_color")
local WINDOW_RESIZED = hash("window_resized")
local UPDATE_WINDOW = hash("update window")
local function update_window(self)
rendercam.update_window(render.get_window_width(), render.get_window_height())
self.gui_proj = vmath.matrix4_orthographic(0, rendercam.window.x, 0, rendercam.window.y, -1, 1)
end
function init(self)
self.tile_pred = render.predicate({"tile"})
self.gui_pred = render.predicate({"gui"})
self.text_pred = render.predicate({"text"})
self.model_pred = render.predicate({"model"})
self.particle_pred = render.predicate({"particle"})
self.clear_color = vmath.vector4(0)
rendercam.configWin.x = render.get_width(); rendercam.configWin.y = render.get_height()
rendercam.update_window_size(render.get_window_width(), render.get_window_height())
update_window(self)
end
function update(self)
render.set_depth_mask(true)
render.set_stencil_mask(0xff)
render.clear({[render.BUFFER_COLOR_BIT] = self.clear_color, [render.BUFFER_DEPTH_BIT] = 1, [render.BUFFER_STENCIL_BIT] = 0})
render.set_viewport(vp.x, vp.y, vp.width, vp.height)
render.set_view(rendercam.calculate_view())
render.set_projection(rendercam.calculate_proj())
-- Sprite and particle rendering
render.set_depth_mask(false)
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_STENCIL_TEST)
render.enable_state(render.STATE_BLEND)
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
render.disable_state(render.STATE_CULL_FACE)
render.draw(self.tile_pred)
render.draw(self.particle_pred)
-- Model rendering
render.set_blend_func(render.BLEND_SRC_ALPHA, render.BLEND_ONE_MINUS_SRC_ALPHA)
render.enable_state(render.STATE_CULL_FACE)
render.enable_state(render.STATE_DEPTH_TEST)
render.set_depth_mask(true)
render.draw(self.model_pred)
-- Debug rendering - physics debug, draw_line
render.disable_state(render.STATE_DEPTH_TEST)
render.disable_state(render.STATE_CULL_FACE)
render.draw_debug3d()
-- GUI Rendering
render.set_viewport(0, 0, rendercam.window.x, rendercam.window.y)
render.set_view(IDENTITY_MATRIX)
render.set_projection(self.gui_proj) -- gui_proj only calculated on update_window
render.enable_state(render.STATE_STENCIL_TEST)
render.draw(self.gui_pred)
render.draw(self.text_pred) -- Includes debug text from "draw_text" messages.
render.disable_state(render.STATE_STENCIL_TEST)
end
function on_message(self, message_id, message)
if message_id == CLEAR_COLOR then
self.clear_color = message.color
elseif message_id == WINDOW_RESIZED then -- sent by engine
update_window(self)
elseif message_id == UPDATE_WINDOW then -- sent by rendercam when a camera is activated ("window_resized" engine message requires data)
update_window(self)
end
end