generated from treeform/nimtemplate
-
Notifications
You must be signed in to change notification settings - Fork 7
/
masking.nim
48 lines (37 loc) · 1.13 KB
/
masking.nim
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
import boxy, opengl, windy
let window = newWindow("Windy + Boxy", ivec2(1280, 800))
makeContextCurrent(window)
loadExtensions()
let bxy = newBoxy()
# Load the images.
bxy.addImage("mask", readImage("examples/data/mask.png"))
bxy.addImage("greece", readImage("examples/data/greece.png"))
var frame: int
# Called when it is time to draw a new frame.
window.onFrame = proc() =
# Clear the screen and begin a new frame.
bxy.beginFrame(window.size)
# Draw the bg.
bxy.drawRect(rect(vec2(0, 0), window.size.vec2), color(0, 0, 0, 1))
# Draw some background image.
bxy.saveTransform()
bxy.translate(window.size.vec2 / 2)
bxy.scale(1.2 + 0.2 * sin(frame.float32/100))
bxy.drawImage("greece", center = vec2(0, 0), angle = 0)
bxy.restoreTransform()
# Draw the mask.
bxy.pushLayer()
bxy.drawImage(
"mask",
center = window.size.vec2 / 2,
angle = 0,
tint = color(1, 0, 0, 1)
)
bxy.popLayer(blendMode = MaskBlend)
# End this frame, flushing the draw commands.
bxy.endFrame()
# Swap buffers displaying the new Boxy frame.
window.swapBuffers()
inc frame
while not window.closeRequested:
pollEvents()