-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-gl-texbuf.k
93 lines (85 loc) · 3 KB
/
test-gl-texbuf.k
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
83
84
85
86
87
88
89
90
91
92
93
(require "libglfw.k")
(require "libglu.k")
(require "libgl.k")
(require "gl-texbuf.k")
(define *texbuf*)
(define-function init ()
(glClearColor 0.2 0.2 0.2 1.0)
(glEnable GL_TEXTURE_2D)
(glClearDepth 1.0)
(glDepthFunc GL_LESS)
(glEnable GL_DEPTH_TEST)
(glShadeModel GL_SMOOTH)
(set *texbuf* (texbuf 400 400 32 32))
)
(define-function solidCube (s)
(let ((ns (- s)))
(glBegin GL_QUADS)
(glColor3f 0.0 1.0 0.0) (glVertex3f s s ns) (glVertex3f ns s ns) (glVertex3f ns s s) (glVertex3f s s s)
(glColor3f 1.0 0.5 0.0) (glVertex3f s ns s) (glVertex3f ns ns s) (glVertex3f ns ns ns) (glVertex3f s ns ns)
(glColor3f 0.5 0.0 0.0) (glVertex3f s s s) (glVertex3f ns s s) (glVertex3f ns ns s) (glVertex3f s ns s)
(glColor3f 1.0 1.0 0.0) (glVertex3f s ns ns) (glVertex3f ns ns ns) (glVertex3f ns s ns) (glVertex3f s s ns)
(glColor3f 0.0 0.0 1.0) (glVertex3f ns s s) (glVertex3f ns s ns) (glVertex3f ns ns ns) (glVertex3f ns ns s)
(glColor3f 1.0 0.0 1.0) (glVertex3f s s ns) (glVertex3f s s s) (glVertex3f s ns s) (glVertex3f s ns ns)
(glEnd)))
(define ltheta 0.0)
(define rtheta 0.0)
(define counter 0)
(define-function display ()
(glClear (| GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT))
(glLoadIdentity)
(when (= 128 (incr counter))
(exit 0)
(set counter 0)
(fill *texbuf* 0xff000000)
)
(let* ((x (+ 200 (double->long (* 100.0 (sin rtheta)))))
(y (+ 200 (double->long (* 100.0 (cos rtheta))))))
(fill-rect *texbuf* x y (+ x 32) (+ y 32) 0xff000000))
(incr rtheta 0.1)
(let* ((x (+ 200 (double->long (* 100.0 (sin rtheta)))))
(y (+ 200 (double->long (* 100.0 (cos rtheta))))))
(fill-rect *texbuf* x y (+ x 32) (+ y 32) 0xff0000ff))
(draw-line *texbuf*
200 (+ 200 (double->long (* 180.0 (sin ltheta))))
(+ 200 (double->long (* 180.0 (cos ltheta)))) 200
0xff00ff00)
(flush *texbuf*)
(gl-render *texbuf*)
(incr ltheta 1)
)
(define-function reshape (width height)
(glViewport 0 0 width height)
(glMatrixMode GL_PROJECTION)
(glLoadIdentity)
(if 1
(let ((w (long->double width))
(h (long->double height)))
(glOrtho 0.0 w 0.0 h -1.0 1.0))
(gluPerspective 60.0 (/ (long->double width) (long->double height)) 1.0 100.0))
(glMatrixMode GL_MODELVIEW))
(define-function *main* ()
(init-libglfw)
(init-libglu)
(init-libgl)
(glfwInit)
(let ((w 800) (h 600))
(glfwOpenWindow w h 8 8 8 8 32 0 GLFW_WINDOW)
(glfwSetWindowTitle "Maru :: Framebuffer")
(init)
(reshape w h)
(let ((running 1))
(while running
(display)
(glfwSwapBuffers)
;;(glfwSleep 0.02);;(glfwWaitEvents)
(let ((winw (data sizeof-int))
(winh (data sizeof-int)))
(glfwGetWindowSize winw winh)
(or (and (= w (long-at winw 0)) (= h (long-at winh 0)))
(reshape (set w (long-at winw 0)) (set h (long-at winh 0)))))
(set running (and (= 0 (glfwGetKey GLFW_KEY_ESC))
(= 1 (glfwGetWindowParam GLFW_OPENED))))))
(glfwTerminate)
(exit 0)))
(or *arguments* (*main*))