]> git.jsancho.org Git - gacela.git/blob - gacela_GL.lisp
(no commit message)
[gacela.git] / gacela_GL.lisp
1 ;;; Gacela, a GNU Common Lisp extension for fast games development
2 ;;; Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
3 ;;;
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation, either version 3 of the License, or
7 ;;; (at your option) any later version.
8 ;;;
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ;;; GNU General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17
18 (eval-when (compile load eval)
19            (when (not (find-package 'gacela)) (make-package 'gacela :nicknames '(gg) :use '(lisp)))
20            (in-package 'gacela :nicknames '(gg) :use '(lisp)))
21
22
23 (defmacro mapcconst (type c-type name)
24   (let ((c-header (concatenate 'string c-type " gacela_" name " (void)"))
25         (c-body (concatenate 'string "return " name ";"))
26         (c-name (concatenate 'string "gacela_" name))
27         (lisp-name (intern (string-upcase name))))
28     `(progn
29        (defcfun ,c-header 0 ,c-body)
30        (defentry ,lisp-name () (,type ,c-name))
31        (eval-when (load) (defconstant ,lisp-name (,lisp-name))))))
32
33 (clines "#include <GL/gl.h>")
34 (clines "#include <GL/glu.h>")
35
36 ;;; Data types
37 (mapcconst int "int" "GL_UNSIGNED_BYTE")
38
39 ;;; Primitives
40 (mapcconst int "int" "GL_POINTS")
41 (mapcconst int "int" "GL_LINES")
42 (mapcconst int "int" "GL_LINE_LOOP")
43 (mapcconst int "int" "GL_LINE_STRIP")
44 (mapcconst int "int" "GL_TRIANGLES")
45 (mapcconst int "int" "GL_TRIANGLE_STRIP")
46 (mapcconst int "int" "GL_TRIANGLE_FAN")
47 (mapcconst int "int" "GL_QUADS")
48 (mapcconst int "int" "GL_QUAD_STRIP")
49 (mapcconst int "int" "GL_POLYGON")
50
51 ;;; Matrix Mode
52 (mapcconst int "int" "GL_MODELVIEW")
53 (mapcconst int "int" "GL_PROJECTION")
54
55 ;;; Depth buffer
56 (mapcconst int "int" "GL_LEQUAL")
57 (mapcconst int "int" "GL_DEPTH_TEST")
58
59 ;;; Lighting
60 (mapcconst int "int" "GL_LIGHTING")
61 (mapcconst int "int" "GL_LIGHT1")
62 (mapcconst int "int" "GL_AMBIENT")
63 (mapcconst int "int" "GL_DIFFUSE")
64 (mapcconst int "int" "GL_POSITION")
65 (mapcconst int "int" "GL_SMOOTH")
66
67 ;;; Blending
68 (mapcconst int "int" "GL_BLEND")
69 (mapcconst int "int" "GL_ONE")
70 (mapcconst int "int" "GL_SRC_ALPHA")
71
72 ;;; Fog
73 (mapcconst int "int" "GL_LINEAR")
74
75 ;;; Buffers, Pixel Drawing/Reading
76 (mapcconst int "int" "GL_RGB")
77 (mapcconst int "int" "GL_RGBA")
78
79 ;;; Hints
80 (mapcconst int "int" "GL_PERSPECTIVE_CORRECTION_HINT")
81 (mapcconst int "int" "GL_NICEST")
82
83 ;;; Texture mapping
84 (mapcconst int "int" "GL_TEXTURE_2D")
85 (mapcconst int "int" "GL_TEXTURE_MAG_FILTER")
86 (mapcconst int "int" "GL_TEXTURE_MIN_FILTER")
87 (mapcconst int "int" "GL_LINEAR_MIPMAP_NEAREST")
88 (mapcconst int "int" "GL_NEAREST")
89
90 ;;; glPush/PopAttrib bits
91 (mapcconst int "int" "GL_DEPTH_BUFFER_BIT")
92 (mapcconst int "int" "GL_COLOR_BUFFER_BIT")
93
94 ;;; OpenGL 1.2
95 (mapcconst int "int" "GL_BGR")
96 (mapcconst int "int" "GL_BGRA")
97
98 ;;; OpenGL Functions
99 (defcfun "void gacela_glBegin (int mode)" 0
100   "glBegin (mode);")
101
102 (defcfun "void gacela_glClear (int mask)" 0
103   "glClear (mask);")
104
105 (defcfun "void gacela_glClearColor (float red, float green, float blue, float alpha)" 0
106   "glClearColor (red, green, blue, alpha);")
107
108 (defcfun "void gacela_glClearDepth (double depth)" 0
109   "glClearDepth (depth);")
110
111 (defcfun "void gacela_glColor3f (float red, float green, float blue)" 0
112   "glColor3f (red, green, blue);")
113
114 (defcfun "void gacela_glColor4f (float red, float green, float blue, float alpha)" 0
115   "glColor4f (red, green, blue, alpha);")
116
117 (defcfun "void gacela_glDepthFunc (int func)" 0
118   "glDepthFunc (func);")
119
120 (defcfun "void gacela_glEnable (int cap)" 0
121   "glEnable (cap);")
122
123 (defcfun "void gacela_glDisable (int cap)" 0
124   "glDisable (cap);")
125
126 (defcfun "void gacela_glEnd (void)" 0
127   "glEnd ();")
128
129 (defcfun "void gacela_glHint (int target, int mode)" 0
130   "glHint (target, mode);")
131
132 (defcfun "void gacela_glLoadIdentity (void)" 0
133   "glLoadIdentity ();")
134
135 (defcfun "void gacela_glMatrixMode (int mode)" 0
136   "glMatrixMode (mode);")
137
138 (defcfun "void gacela_glRotatef (float angle, float x, float y, float z)" 0
139   "glRotatef (angle, x, y, z);")
140
141 (defcfun "void gacela_glShadeModel (int mode)" 0
142   "glShadeModel (mode);")
143
144 (defcfun "void gacela_glTranslatef (float x, float y, float z)" 0
145   "glTranslatef (x, y, z);")
146
147 (defcfun "void gacela_glVertex2f (float x, float y)" 0
148   "glVertex2f (x, y);")
149
150 (defcfun "void gacela_glVertex3f (float x, float y, float z)" 0
151   "glVertex3f (x, y, z);")
152
153 (defcfun "void gacela_glViewport (int x, int y, int width, int height)" 0
154   "glViewport (x, y, width, height);")
155
156 (defcfun "static object gacela_glGenTextures (int n)" 0
157   "object textures;"
158   "GLuint text[n];"
159   "int i, t;"
160   ('nil textures)
161   "glGenTextures (n, &text[0]);"
162   "for (i = n - 1; i >= 0; i--) {"
163   "t = text[i];"
164   ((cons (int t) textures) textures)
165   "}"
166   "return textures;")
167
168 (defcfun "void gacela_glDeleteTextures (int n, object textures)" 0
169   "GLuint text[n];"
170   "int i, t;"
171   "for (i = 0; i < n; i++) {"
172   ((nth (int i) textures) t)
173   "text[i] = t;"
174   "}"
175   "glDeleteTextures (n, &text[0]);")
176
177 (defcfun "void gacela_glBindTexture (int target, int texture)" 0
178   "glBindTexture (target, texture);")
179
180 (defcfun "void gacela_glTexImage2D (int target, int level, int internalFormat, int width, int height, int border, int format, int type, int pixels)" 0
181   "glTexImage2D (target, level, internalFormat, width, height, border, format, type, pixels);")
182
183 (defcfun "void gacela_glTexParameteri (int target, int pname, int param)" 0
184   "glTexParameteri (target, pname, param);")
185
186 (defcfun "void gacela_glTexCoord2f (float s, float t)" 0
187   "glTexCoord2f (s, t);")
188
189 (defcfun "void gacela_glLightfv (int light, int pname, float param1, float param2, float param3, float param4)" 0
190   "GLfloat params[4];"
191   "params[0] = param1;"
192   "params[1] = param2;"
193   "params[2] = param3;"
194   "params[3] = param4;"
195   "glLightfv (light, pname, params);")
196
197 (defcfun "void gacela_glNormal3f (float nx, float ny, float nz)" 0
198   "glNormal3f (nx, ny, nz);")
199
200 (defcfun "void gacela_glBlendFunc (int sfactor, int dfactor)" 0
201   "glBlendFunc (sfactor, dfactor);")
202
203 (defcfun "void gacela_glOrtho (float left, float right, float bottom, float top, float near_val, float far_val)" 0
204   "glOrtho (left, right, bottom, top, near_val, far_val);")
205
206 (defcfun "void gacela_glPushMatrix (void)" 0
207   "glPushMatrix ();")
208
209 (defcfun "void gacela_glPopMatrix (void)" 0
210   "glPopMatrix ();")
211
212 (defcfun "void gacela_gluPerspective (double fovy, double aspect, double zNear, double zFar)" 0
213   "gluPerspective (fovy, aspect, zNear, zFar);")
214
215 (defcfun "int gacela_gluBuild2DMipmaps (int target, int internalFormat, int width, int height, int format, int type, int data)" 0
216   "return gluBuild2DMipmaps (target, internalFormat, width, height, format, type, data);")
217
218 (defcfun "void gacela_gluLookAt (double eyeX, double eyeY, double eyeZ, double centerX, double centerY, double centerZ, double upX, double upY, double upZ)" 0
219   "gluLookAt (eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);")
220
221 (defentry glBegin (int) (void "gacela_glBegin"))
222 (defentry glClear (int) (void "gacela_glClear"))
223 (defentry glClearColor (float float float float) (void "gacela_glClearColor"))
224 (defentry glClearDepth (double) (void "gacela_glClearDepth"))
225 (defentry glColor3f (float float float) (void "gacela_glColor3f"))
226 (defentry glColor4f (float float float float) (void "gacela_glColor4f"))
227 (defentry glDepthFunc (int) (void "gacela_glDepthFunc"))
228 (defentry glEnable (int) (void "gacela_glEnable"))
229 (defentry glDisable (int) (void "gacela_glDisable"))
230 (defentry glEnd () (void "gacela_glEnd"))
231 (defentry glHint (int int) (void "gacela_glHint"))
232 (defentry glLoadIdentity () (void "gacela_glLoadIdentity"))
233 (defentry glMatrixMode (int) (void "gacela_glMatrixMode"))
234 (defentry glRotatef (float float float float) (void "gacela_glRotatef"))
235 (defentry glShadeModel (int) (void "gacela_glShadeModel"))
236 (defentry glTranslatef (float float float) (void "gacela_glTranslatef"))
237 (defentry glVertex2f (float float) (void "gacela_glVertex2f"))
238 (defentry glVertex3f (float float float) (void "gacela_glVertex3f"))
239 (defentry glViewport (int int int int) (void "gacela_glViewport"))
240 (defentry glGenTextures (int) (object "gacela_glGenTextures"))
241 (defentry glDeleteTextures (int object) (void "gacela_glDeleteTextures"))
242 (defentry glBindTexture (int int) (void "gacela_glBindTexture"))
243 (defentry glTexImage2D (int int int int int int int int int) (void "gacela_glTexImage2D"))
244 (defentry glTexParameteri (int int int) (void "gacela_glTexParameteri"))
245 (defentry glTexCoord2f (float float) (void "gacela_glTexCoord2f"))
246 (defentry glLightfv (int int float float float float) (void "gacela_glLightfv"))
247 (defentry glNormal3f (float float float) (void "gacela_glNormal3f"))
248 (defentry glBlendFunc (int int) (void "gacela_glBlendFunc"))
249 (defentry glOrtho (float float float float float float) (void "gacela_glOrtho"))
250 (defentry glPushMatrix () (void "gacela_glPushMatrix"))
251 (defentry glPopMatrix () (void "gacela_glPopMatrix"))
252
253 (defentry gluPerspective (double double double double) (void "gacela_gluPerspective"))
254 (defentry gluBuild2DMipmaps (int int int int int int int) (int "gacela_gluBuild2DMipmaps"))
255 (defentry gluLookAt (double double double double double double double double double) (void "gacela_gluLookAt"))