-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender_clip.nelua
46 lines (34 loc) · 1.19 KB
/
render_clip.nelua
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
--[[
Copyright (c) 2021-present André Luiz Alvares
Nene is licensed under the Zlib license.
Please refer to the LICENSE file for details
SPDX-License-Identifier: Zlib
]]
-- This example shows how to using render clipping using a rectangle.
local Nene = require 'nene.core'
local Color = require 'nene.color'
local Rect = require 'nene.math.rect'
local function rects()
local ok = Nene.init('nene render rect clip', 256, 256)
assert(ok, 'error: nene initialization failed')
-- create two rects
local rect_clip: Rect = { size = { 48, 48 } }
repeat
Nene.update()
-- copy mouse position to rect_clip position
local nene = Nene.instance()
rect_clip.pos = Nene.screen_point_to_world_pos(nene.mouse_pos):to_vec2i()
Nene.render_clear(Color.bg)
-- draw grid
for i = -16, 16 do
Nene.render_draw_line({ 16 * i, -256 }, { 16 * i, 256 }, Color.black, true)
Nene.render_draw_line({ -256, 16 * i }, { 256, 16 * i }, Color.black, true)
end
-- set render clipping
Nene.set_render_clip(rect_clip, false)
Nene.render_draw_rect(rect_clip, true, Color.red, true)
Nene.render_present()
until Nene.should_quit()
Nene.terminate()
end
rects()