]> git.jsancho.org Git - gacela.git/blob - gacela_GL.lisp
e2032f817609355a9020ac74dbbd9d2dc4353adf
[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 (in-package :gacela)
19
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))))
25     `(progn
26        (defcfun ,c-header 0 ,c-body)
27        (defentry ,lisp-name () (,type ,c-name))
28        (eval-when (load) (defconstant ,lisp-name (,lisp-name))))))
29
30 (clines "#include <GL/gl.h>")
31 (clines "#include <GL/glu.h>")
32
33 ;;; Data types
34 (mapcconst int "int" "GL_UNSIGNED_BYTE")
35
36 ;;; Primitives
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")
47
48 ;;; Matrix Mode
49 (mapcconst int "int" "GL_MODELVIEW")
50 (mapcconst int "int" "GL_PROJECTION")
51
52 ;;; Depth buffer
53 (mapcconst int "int" "GL_LEQUAL")
54 (mapcconst int "int" "GL_DEPTH_TEST")
55
56 ;;; Lighting
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")
63
64 ;;; Blending
65 (mapcconst int "int" "GL_BLEND")
66 (mapcconst int "int" "GL_ONE")
67 (mapcconst int "int" "GL_SRC_ALPHA")
68
69 ;;; Fog
70 (mapcconst int "int" "GL_LINEAR")
71
72 ;;; Buffers, Pixel Drawing/Reading
73 (mapcconst int "int" "GL_RGB")
74 (mapcconst int "int" "GL_RGBA")
75
76 ;;; Hints
77 (mapcconst int "int" "GL_PERSPECTIVE_CORRECTION_HINT")
78 (mapcconst int "int" "GL_NICEST")
79
80 ;;; Texture mapping
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")
86
87 ;;; glPush/PopAttrib bits
88 (mapcconst int "int" "GL_DEPTH_BUFFER_BIT")
89 (mapcconst int "int" "GL_COLOR_BUFFER_BIT")
90
91 ;;; OpenGL 1.2
92 (mapcconst int "int" "GL_BGR")
93 (mapcconst int "int" "GL_BGRA")
94
95 ;;; OpenGL Functions
96 (defcfun "void gacela_glBegin (int mode)" 0
97   "glBegin (mode);")
98
99 (defcfun "void gacela_glClear (int mask)" 0
100   "glClear (mask);")
101
102 (defcfun "void gacela_glClearColor (float red, float green, float blue, float alpha)" 0
103   "glClearColor (red, green, blue, alpha);")
104
105 (defcfun "void gacela_glClearDepth (double depth)" 0
106   "glClearDepth (depth);")
107
108 (defcfun "void gacela_glColor3f (float red, float green, float blue)" 0
109   "glColor3f (red, green, blue);")
110
111 (defcfun "void gacela_glColor4f (float red, float green, float blue, float alpha)" 0
112   "glColor4f (red, green, blue, alpha);")
113
114 (defcfun "void gacela_glDepthFunc (int func)" 0
115   "glDepthFunc (func);")
116
117 (defcfun "void gacela_glEnable (int cap)" 0
118   "glEnable (cap);")
119
120 (defcfun "void gacela_glDisable (int cap)" 0
121   "glDisable (cap);")
122
123 (defcfun "void gacela_glEnd (void)" 0
124   "glEnd ();")
125
126 (defcfun "void gacela_glHint (int target, int mode)" 0
127   "glHint (target, mode);")
128
129 (defcfun "void gacela_glLoadIdentity (void)" 0
130   "glLoadIdentity ();")
131
132 (defcfun "void gacela_glMatrixMode (int mode)" 0
133   "glMatrixMode (mode);")
134
135 (defcfun "void gacela_glRotatef (float angle, float x, float y, float z)" 0
136   "glRotatef (angle, x, y, z);")
137
138 (defcfun "void gacela_glShadeModel (int mode)" 0
139   "glShadeModel (mode);")
140
141 (defcfun "void gacela_glTranslatef (float x, float y, float z)" 0
142   "glTranslatef (x, y, z);")
143
144 (defcfun "void gacela_glVertex2f (float x, float y)" 0
145   "glVertex2f (x, y);")
146
147 (defcfun "void gacela_glVertex3f (float x, float y, float z)" 0
148   "glVertex3f (x, y, z);")
149
150 (defcfun "void gacela_glViewport (int x, int y, int width, int height)" 0
151   "glViewport (x, y, width, height);")
152
153 (defcfun "static object gacela_glGenTextures (int n)" 0
154   "object textures;"
155   "GLuint text[n];"
156   "int i, t;"
157   ('nil textures)
158   "glGenTextures (n, &text[0]);"
159   "for (i = n - 1; i >= 0; i--) {"
160   "t = text[i];"
161   ((cons (int t) textures) textures)
162   "}"
163   "return textures;")
164
165 (defcfun "void gacela_glDeleteTextures (int n, object textures)" 0
166   "GLuint text[n];"
167   "int i, t;"
168   "for (i = 0; i < n; i++) {"
169   ((nth (int i) textures) t)
170   "text[i] = t;"
171   "}"
172   "glDeleteTextures (n, &text[0]);")
173
174 (defcfun "void gacela_glBindTexture (int target, int texture)" 0
175   "glBindTexture (target, texture);")
176
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);")
179
180 (defcfun "void gacela_glTexParameteri (int target, int pname, int param)" 0
181   "glTexParameteri (target, pname, param);")
182
183 (defcfun "void gacela_glTexCoord2f (float s, float t)" 0
184   "glTexCoord2f (s, t);")
185
186 (defcfun "void gacela_glLightfv (int light, int pname, float param1, float param2, float param3, float param4)" 0
187   "GLfloat params[4];"
188   "params[0] = param1;"
189   "params[1] = param2;"
190   "params[2] = param3;"
191   "params[3] = param4;"
192   "glLightfv (light, pname, params);")
193
194 (defcfun "void gacela_glNormal3f (float nx, float ny, float nz)" 0
195   "glNormal3f (nx, ny, nz);")
196
197 (defcfun "void gacela_glBlendFunc (int sfactor, int dfactor)" 0
198   "glBlendFunc (sfactor, dfactor);")
199
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);")
202
203 (defcfun "void gacela_gluPerspective (double fovy, double aspect, double zNear, double zFar)" 0
204   "gluPerspective (fovy, aspect, zNear, zFar);")
205
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);")
208
209 (defcfun "void gacela_gluLookAt (double eyeX, double eyeY, double eyeZ, double centerX, double centerY, double centerZ, double upX, double upY, double upZ)" 0
210   "gluLookAt (eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);")
211
212 (defentry glBegin (int) (void "gacela_glBegin"))
213 (defentry glClear (int) (void "gacela_glClear"))
214 (defentry glClearColor (float float float float) (void "gacela_glClearColor"))
215 (defentry glClearDepth (double) (void "gacela_glClearDepth"))
216 (defentry glColor3f (float float float) (void "gacela_glColor3f"))
217 (defentry glColor4f (float float float float) (void "gacela_glColor4f"))
218 (defentry glDepthFunc (int) (void "gacela_glDepthFunc"))
219 (defentry glEnable (int) (void "gacela_glEnable"))
220 (defentry glDisable (int) (void "gacela_glDisable"))
221 (defentry glEnd () (void "gacela_glEnd"))
222 (defentry glHint (int int) (void "gacela_glHint"))
223 (defentry glLoadIdentity () (void "gacela_glLoadIdentity"))
224 (defentry glMatrixMode (int) (void "gacela_glMatrixMode"))
225 (defentry glRotatef (float float float float) (void "gacela_glRotatef"))
226 (defentry glShadeModel (int) (void "gacela_glShadeModel"))
227 (defentry glTranslatef (float float float) (void "gacela_glTranslatef"))
228 (defentry glVertex2f (float float) (void "gacela_glVertex2f"))
229 (defentry glVertex3f (float float float) (void "gacela_glVertex3f"))
230 (defentry glViewport (int int int int) (void "gacela_glViewport"))
231 (defentry glGenTextures (int) (object "gacela_glGenTextures"))
232 (defentry glDeleteTextures (int object) (void "gacela_glDeleteTextures"))
233 (defentry glBindTexture (int int) (void "gacela_glBindTexture"))
234 (defentry glTexImage2D (int int int int int int int int int) (void "gacela_glTexImage2D"))
235 (defentry glTexParameteri (int int int) (void "gacela_glTexParameteri"))
236 (defentry glTexCoord2f (float float) (void "gacela_glTexCoord2f"))
237 (defentry glLightfv (int int float float float float) (void "gacela_glLightfv"))
238 (defentry glNormal3f (float float float) (void "gacela_glNormal3f"))
239 (defentry glBlendFunc (int int) (void "gacela_glBlendFunc"))
240 (defentry glOrtho (float float float float float float) (void "gacela_glOrtho"))
241
242 (defentry gluPerspective (double double double double) (void "gacela_gluPerspective"))
243 (defentry gluBuild2DMipmaps (int int int int int int int) (int "gacela_gluBuild2DMipmaps"))
244 (defentry gluLookAt (float float float float float float float float float) (void "gacela_gluLookAt"))