/
gltest.rkt
51 lines (39 loc) · 1.52 KB
/
gltest.rkt
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
;; Extremely simply OpenGL demo.
;; Draw a white rectangle on the screen.
;; Also query some information on the OpenGL implementation.
#lang racket/gui
(require (planet "rgl.rkt" ("stephanh" "RacketGL.plt" 1 4)))
(require ffi/vector)
(require "viewer.rkt")
(define (print-info)
; print available extensions
(for ((ext (in-set (gl-extensions))))
(printf "Extension: ~a~%" ext))
; print version, as a nice parseable Racket list
(printf "~s~%" (gl-version))
; demo to check for a certain extension
(if (gl-has-extension? 'GL_EXT_texture_object)
(printf "Yep, we have GL_EXT_texture_object~%")
(printf "Sorry no GL_EXT_texture_object~%"))
; demo to query some array-based state
(let ((v (glGetIntegerv GL_VERTEX_ARRAY)))
(printf "glGet on GL_VERTEX_ARRAY = ~s~%" (s32vector-ref v 0))))
(define (draw)
; the coordinates
(define vertex-array
(f64vector -0.5 -0.5
0.5 -0.5
0.5 0.5
-0.5 0.5))
; Let's be "modern" and use the array functions (introduced in OpenGL 1.1).
; Note that you need to ask GL everything 3 times:
; 1. Here is an array I'd like you to draw...
(let-values (((type cptr) (gl-vector->type/cpointer vertex-array)))
(glVertexPointer 2 type 0 cptr))
; 2. Yes, I really want you to use it, I was not simply fooling around.
(glEnableClientState GL_VERTEX_ARRAY)
; 3. Allright, now draw the silly thing already!
(glDrawArrays GL_QUADS 0 4)
; Clean up state.
(glDisableClientState GL_VERTEX_ARRAY))
(view draw print-info)