generated from treeform/nimtemplate
-
Notifications
You must be signed in to change notification settings - Fork 8
/
basic_glut.nim
47 lines (35 loc) · 1.23 KB
/
basic_glut.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
import boxy, opengl, opengl/glut
let windowSize = ivec2(1280, 800)
proc display() {.cdecl.} # Forward declaration
glutInit()
glutInitDisplayMode(GLUT_DOUBLE)
glutInitWindowSize(windowSize.x, windowSize.y)
discard glutCreateWindow("GLUT + Boxy")
glutDisplayFunc(display)
loadExtensions()
let bxy = newBoxy()
# Load the images.
bxy.addImage("bg", readImage("examples/data/bg.png"))
bxy.addImage("ring1", readImage("examples/data/ring1.png"))
bxy.addImage("ring2", readImage("examples/data/ring2.png"))
bxy.addImage("ring3", readImage("examples/data/ring3.png"))
var frame: int
# Called when it is time to draw a new frame.
proc display() {.cdecl.} =
# Clear the screen and begin a new frame.
bxy.beginFrame(windowSize)
# Draw the bg.
bxy.drawImage("bg", rect = rect(vec2(0, 0), windowSize.vec2))
# Draw the rings.
let center = windowSize.vec2 / 2
bxy.drawImage("ring1", center, angle = frame.float / 100)
bxy.drawImage("ring2", center, angle = -frame.float / 190)
bxy.drawImage("ring3", center, angle = frame.float / 170)
# End this frame, flushing the draw commands.
bxy.endFrame()
# Swap buffers displaying the new Boxy frame.
glutSwapBuffers()
inc frame
# Ask glut to draw next frame
glutPostRedisplay()
glutMainLoop()