1 ;;; Gacela, a GNU Common Lisp extension for fast games development
2 ;;; Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
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.
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.
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/>.
20 (defmacro mapcconst (type c-type name)
21 (let ((c-header (concatenate 'string c-type " gacela_" name " (void)"))
22 (c-body (concatenate 'string "return " name ";"))
23 (c-name (concatenate 'string "gacela_" name))
24 (lisp-name (intern (string-upcase name))))
26 (defcfun ,c-header 0 ,c-body)
27 (defentry ,lisp-name () (,type ,c-name))
28 (eval-when (load) (defconstant ,lisp-name (,lisp-name))))))
30 (clines "#include <GL/gl.h>")
31 (clines "#include <GL/glu.h>")
34 (mapcconst int "int" "GL_UNSIGNED_BYTE")
37 (mapcconst int "int" "GL_POINTS")
38 (mapcconst int "int" "GL_LINES")
39 (mapcconst int "int" "GL_LINE_LOOP")
40 (mapcconst int "int" "GL_LINE_STRIP")
41 (mapcconst int "int" "GL_TRIANGLES")
42 (mapcconst int "int" "GL_TRIANGLE_STRIP")
43 (mapcconst int "int" "GL_TRIANGLE_FAN")
44 (mapcconst int "int" "GL_QUADS")
45 (mapcconst int "int" "GL_QUAD_STRIP")
46 (mapcconst int "int" "GL_POLYGON")
49 (mapcconst int "int" "GL_MODELVIEW")
50 (mapcconst int "int" "GL_PROJECTION")
53 (mapcconst int "int" "GL_LEQUAL")
54 (mapcconst int "int" "GL_DEPTH_TEST")
57 (mapcconst int "int" "GL_LIGHTING")
58 (mapcconst int "int" "GL_LIGHT1")
59 (mapcconst int "int" "GL_AMBIENT")
60 (mapcconst int "int" "GL_DIFFUSE")
61 (mapcconst int "int" "GL_POSITION")
62 (mapcconst int "int" "GL_SMOOTH")
65 (mapcconst int "int" "GL_BLEND")
66 (mapcconst int "int" "GL_ONE")
67 (mapcconst int "int" "GL_SRC_ALPHA")
70 (mapcconst int "int" "GL_LINEAR")
72 ;;; Buffers, Pixel Drawing/Reading
73 (mapcconst int "int" "GL_RGB")
74 (mapcconst int "int" "GL_RGBA")
77 (mapcconst int "int" "GL_PERSPECTIVE_CORRECTION_HINT")
78 (mapcconst int "int" "GL_NICEST")
81 (mapcconst int "int" "GL_TEXTURE_2D")
82 (mapcconst int "int" "GL_TEXTURE_MAG_FILTER")
83 (mapcconst int "int" "GL_TEXTURE_MIN_FILTER")
84 (mapcconst int "int" "GL_LINEAR_MIPMAP_NEAREST")
85 (mapcconst int "int" "GL_NEAREST")
87 ;;; glPush/PopAttrib bits
88 (mapcconst int "int" "GL_DEPTH_BUFFER_BIT")
89 (mapcconst int "int" "GL_COLOR_BUFFER_BIT")
92 (mapcconst int "int" "GL_BGR")
93 (mapcconst int "int" "GL_BGRA")
96 (defcfun "void gacela_glBegin (int mode)" 0
99 (defcfun "void gacela_glClear (int mask)" 0
102 (defcfun "void gacela_glClearColor (float red, float green, float blue, float alpha)" 0
103 "glClearColor (red, green, blue, alpha);")
105 (defcfun "void gacela_glClearDepth (double depth)" 0
106 "glClearDepth (depth);")
108 (defcfun "void gacela_glColor3f (float red, float green, float blue)" 0
109 "glColor3f (red, green, blue);")
111 (defcfun "void gacela_glColor4f (float red, float green, float blue, float alpha)" 0
112 "glColor4f (red, green, blue, alpha);")
114 (defcfun "void gacela_glDepthFunc (int func)" 0
115 "glDepthFunc (func);")
117 (defcfun "void gacela_glEnable (int cap)" 0
120 (defcfun "void gacela_glDisable (int cap)" 0
123 (defcfun "void gacela_glEnd (void)" 0
126 (defcfun "void gacela_glHint (int target, int mode)" 0
127 "glHint (target, mode);")
129 (defcfun "void gacela_glLoadIdentity (void)" 0
130 "glLoadIdentity ();")
132 (defcfun "void gacela_glMatrixMode (int mode)" 0
133 "glMatrixMode (mode);")
135 (defcfun "void gacela_glRotatef (float angle, float x, float y, float z)" 0
136 "glRotatef (angle, x, y, z);")
138 (defcfun "void gacela_glShadeModel (int mode)" 0
139 "glShadeModel (mode);")
141 (defcfun "void gacela_glTranslatef (float x, float y, float z)" 0
142 "glTranslatef (x, y, z);")
144 (defcfun "void gacela_glVertex2f (float x, float y)" 0
145 "glVertex2f (x, y);")
147 (defcfun "void gacela_glVertex3f (float x, float y, float z)" 0
148 "glVertex3f (x, y, z);")
150 (defcfun "void gacela_glViewport (int x, int y, int width, int height)" 0
151 "glViewport (x, y, width, height);")
153 (defcfun "static object gacela_glGenTextures (int n)" 0
158 "glGenTextures (n, &text[0]);"
159 "for (i = n - 1; i >= 0; i--) {"
161 ((cons (int t) textures) textures)
165 (defcfun "void gacela_glDeleteTextures (int n, object textures)" 0
168 "for (i = 0; i < n; i++) {"
169 ((nth (int i) textures) t)
172 "glDeleteTextures (n, &text[0]);")
174 (defcfun "void gacela_glBindTexture (int target, int texture)" 0
175 "glBindTexture (target, texture);")
177 (defcfun "void gacela_glTexImage2D (int target, int level, int internalFormat, int width, int height, int border, int format, int type, int pixels)" 0
178 "glTexImage2D (target, level, internalFormat, width, height, border, format, type, pixels);")
180 (defcfun "void gacela_glTexParameteri (int target, int pname, int param)" 0
181 "glTexParameteri (target, pname, param);")
183 (defcfun "void gacela_glTexCoord2f (float s, float t)" 0
184 "glTexCoord2f (s, t);")
186 (defcfun "void gacela_glLightfv (int light, int pname, float param1, float param2, float param3, float param4)" 0
188 "params[0] = param1;"
189 "params[1] = param2;"
190 "params[2] = param3;"
191 "params[3] = param4;"
192 "glLightfv (light, pname, params);")
194 (defcfun "void gacela_glNormal3f (float nx, float ny, float nz)" 0
195 "glNormal3f (nx, ny, nz);")
197 (defcfun "void gacela_glBlendFunc (int sfactor, int dfactor)" 0
198 "glBlendFunc (sfactor, dfactor);")
200 (defcfun "void gacela_glOrtho (float left, float right, float bottom, float top, float near_val, float far_val)" 0
201 "glOrtho (left, right, bottom, top, near_val, far_val);")
203 (defcfun "void gacela_gluPerspective (double fovy, double aspect, double zNear, double zFar)" 0
204 "gluPerspective (fovy, aspect, zNear, zFar);")
206 (defcfun "int gacela_gluBuild2DMipmaps (int target, int internalFormat, int width, int height, int format, int type, int data)" 0
207 "return gluBuild2DMipmaps (target, internalFormat, width, height, format, type, data);")
209 (defentry glBegin (int) (void "gacela_glBegin"))
210 (defentry glClear (int) (void "gacela_glClear"))
211 (defentry glClearColor (float float float float) (void "gacela_glClearColor"))
212 (defentry glClearDepth (double) (void "gacela_glClearDepth"))
213 (defentry glColor3f (float float float) (void "gacela_glColor3f"))
214 (defentry glColor4f (float float float float) (void "gacela_glColor4f"))
215 (defentry glDepthFunc (int) (void "gacela_glDepthFunc"))
216 (defentry glEnable (int) (void "gacela_glEnable"))
217 (defentry glDisable (int) (void "gacela_glDisable"))
218 (defentry glEnd () (void "gacela_glEnd"))
219 (defentry glHint (int int) (void "gacela_glHint"))
220 (defentry glLoadIdentity () (void "gacela_glLoadIdentity"))
221 (defentry glMatrixMode (int) (void "gacela_glMatrixMode"))
222 (defentry glRotatef (float float float float) (void "gacela_glRotatef"))
223 (defentry glShadeModel (int) (void "gacela_glShadeModel"))
224 (defentry glTranslatef (float float float) (void "gacela_glTranslatef"))
225 (defentry glVertex2f (float float) (void "gacela_glVertex2f"))
226 (defentry glVertex3f (float float float) (void "gacela_glVertex3f"))
227 (defentry glViewport (int int int int) (void "gacela_glViewport"))
228 (defentry glGenTextures (int) (object "gacela_glGenTextures"))
229 (defentry glDeleteTextures (int object) (void "gacela_glDeleteTextures"))
230 (defentry glBindTexture (int int) (void "gacela_glBindTexture"))
231 (defentry glTexImage2D (int int int int int int int int int) (void "gacela_glTexImage2D"))
232 (defentry glTexParameteri (int int int) (void "gacela_glTexParameteri"))
233 (defentry glTexCoord2f (float float) (void "gacela_glTexCoord2f"))
234 (defentry glLightfv (int int float float float float) (void "gacela_glLightfv"))
235 (defentry glNormal3f (float float float) (void "gacela_glNormal3f"))
236 (defentry glBlendFunc (int int) (void "gacela_glBlendFunc"))
237 (defentry glOrtho (float float float float float float) (void "gacela_glOrtho"))
239 (defentry gluPerspective (double double double double) (void "gacela_gluPerspective"))
240 (defentry gluBuild2DMipmaps (int int int int int int int) (int "gacela_gluBuild2DMipmaps"))