1 /* Gacela, a GNU Guile 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/>.
21 #include "gacela_GL.h"
24 gacela_glBegin (SCM mode)
26 glBegin (scm_to_int (mode));
27 return SCM_UNSPECIFIED;
31 gacela_glClear (SCM mask)
33 glClear (scm_to_int (mask));
34 return SCM_UNSPECIFIED;
38 gacela_glClearColor (SCM red, SCM green, SCM blue, SCM alpha)
40 glClearColor (scm_to_double (red), scm_to_double (green), scm_to_double (blue), scm_to_double (alpha));
41 return SCM_UNSPECIFIED;
45 gacela_glClearDepth (SCM depth)
47 glClearDepth (scm_to_double (depth));
48 return SCM_UNSPECIFIED;
52 gacela_glColor3f (SCM red, SCM green, SCM blue)
54 glColor3f (scm_to_double (red), scm_to_double (green), scm_to_double (blue));
55 return SCM_UNSPECIFIED;
59 gacela_glColor4f (SCM red, SCM green, SCM blue, SCM alpha)
61 glColor4f (scm_to_double (red), scm_to_double (green), scm_to_double (blue), scm_to_double (alpha));
62 return SCM_UNSPECIFIED;
66 gacela_glDepthFunc (SCM func)
68 glDepthFunc (scm_to_int (func));
69 return SCM_UNSPECIFIED;
73 gacela_glEnable (SCM cap)
75 glEnable (scm_to_int (cap));
76 return SCM_UNSPECIFIED;
80 gacela_glDisable (SCM cap)
82 glDisable (scm_to_int (cap));
83 return SCM_UNSPECIFIED;
90 return SCM_UNSPECIFIED;
94 gacela_glHint (SCM target, SCM mode)
96 glHint (scm_to_int (target), scm_to_int (mode));
97 return SCM_UNSPECIFIED;
101 gacela_glLoadIdentity (void)
104 return SCM_UNSPECIFIED;
108 gacela_glMatrixMode (SCM mode)
110 glMatrixMode (scm_to_int (mode));
111 return SCM_UNSPECIFIED;
115 gacela_glRotatef (SCM angle, SCM x, SCM y, SCM z)
117 glRotatef (scm_to_double (angle), scm_to_double (x), scm_to_double (y), scm_to_double (z));
118 return SCM_UNSPECIFIED;
122 gacela_glShadeModel (SCM mode)
124 glShadeModel (scm_to_int (mode));
125 return SCM_UNSPECIFIED;
129 gacela_glTranslatef (SCM x, SCM y, SCM z)
131 glTranslatef (scm_to_double (x), scm_to_double (y), scm_to_double (z));
132 return SCM_UNSPECIFIED;
136 gacela_glVertex2f (SCM x, SCM y)
138 glVertex2f (scm_to_double (x), scm_to_double (y));
139 return SCM_UNSPECIFIED;
143 gacela_glVertex3f (SCM x, SCM y, SCM z)
145 glVertex3f (scm_to_double (x), scm_to_double (y), scm_to_double (z));
146 return SCM_UNSPECIFIED;
150 gacela_glViewport (SCM x, SCM y, SCM width, SCM height)
152 glViewport (scm_to_int (x), scm_to_int (y), scm_to_int (width), scm_to_int (height));
153 return SCM_UNSPECIFIED;
157 gacela_glGenTextures (SCM n)
160 int nint = scm_to_int (n);
164 textures = scm_list_n (SCM_UNDEFINED);
165 glGenTextures (nint, &text[0]);
167 for (i = nint - 1; i >= 0; i--) {
168 textures = scm_cons (scm_from_int (text[i]), textures);
175 gacela_glDeleteTextures (SCM n, SCM textures)
177 int nint = scm_to_int (n);
181 for (i = 0; i < nint; i++) {
182 text[i] = scm_to_int (scm_list_ref (textures, scm_from_int (i)));
185 glDeleteTextures (nint, &text[0]);
186 return SCM_UNSPECIFIED;
190 gacela_glBindTexture (SCM target, SCM texture)
192 glBindTexture (scm_to_int (target), scm_to_int (texture));
193 return SCM_UNSPECIFIED;
197 gacela_glTexImage2D (SCM target, SCM level, SCM internalFormat, SCM width, SCM height, SCM border, SCM format, SCM type, SCM pixels)
199 glTexImage2D (scm_to_int (target), scm_to_int (level), scm_to_int (internalFormat), scm_to_int (width), \
200 scm_to_int (height), scm_to_int (border), scm_to_int (format), scm_to_int (type), \
201 (GLvoid *)scm_to_int (pixels));
202 return SCM_UNSPECIFIED;
206 gacela_glTexParameteri (SCM target, SCM pname, SCM param)
208 glTexParameteri (scm_to_int (target), scm_to_int (pname), scm_to_int (param));
209 return SCM_UNSPECIFIED;
213 gacela_glTexCoord2f (SCM s, SCM t)
215 glTexCoord2f (scm_to_double (s), scm_to_double (t));
216 return SCM_UNSPECIFIED;
220 gacela_glLightfv (SCM light, SCM pname, SCM params)
222 int n = scm_to_int (scm_length (params));
223 GLfloat gl_params[n];
226 for (i = 0; i < n; i++) {
227 gl_params[i] = scm_to_double (scm_list_ref (params, scm_from_int (i)));
230 glLightfv (scm_to_int (light), scm_to_int (pname), gl_params);
231 return SCM_UNSPECIFIED;
235 gacela_glNormal3f (SCM nx, SCM ny, SCM nz)
237 glNormal3f (scm_to_double (nx), scm_to_double (ny), scm_to_double (nz));
238 return SCM_UNSPECIFIED;
242 gacela_glBlendFunc (SCM sfactor, SCM dfactor)
244 glBlendFunc (scm_to_int (sfactor), scm_to_int (dfactor));
245 return SCM_UNSPECIFIED;
249 gacela_glOrtho (SCM left, SCM right, SCM bottom, SCM top, SCM near_val, SCM far_val)
251 glOrtho (scm_to_double (left), scm_to_double (right), scm_to_double (bottom), scm_to_double (top), \
252 scm_to_double (near_val), scm_to_double (far_val));
253 return SCM_UNSPECIFIED;
257 gacela_glPushMatrix (void)
260 return SCM_UNSPECIFIED;
264 gacela_glPopMatrix (void)
267 return SCM_UNSPECIFIED;
271 gacela_gluPerspective (SCM fovy, SCM aspect, SCM zNear, SCM zFar)
273 gluPerspective (scm_to_double (fovy), scm_to_double (aspect), scm_to_double (zNear), scm_to_double (zFar));
274 return SCM_UNSPECIFIED;
278 gacela_gluBuild2DMipmaps (SCM target, SCM internalFormat, SCM width, SCM height, SCM format, SCM type, SCM data)
280 return scm_from_int (gluBuild2DMipmaps (scm_to_int (target), scm_to_int (internalFormat), scm_to_int (width), \
281 scm_to_int (height), scm_to_int (format), scm_to_int (type), \
282 (void *)scm_to_int (data)));
286 gacela_gluLookAt (SCM eyeX, SCM eyeY, SCM eyeZ, SCM centerX, SCM centerY, SCM centerZ, SCM upX, SCM upY, SCM upZ)
288 gluLookAt (scm_to_double (eyeX), scm_to_double (eyeY), scm_to_double (eyeZ), \
289 scm_to_double (centerX), scm_to_double (centerY), scm_to_double (centerZ), \
290 scm_to_double (upX), scm_to_double (upY), scm_to_double (upZ));
291 return SCM_UNSPECIFIED;
296 GL_register_functions (void* data)
299 scm_c_define ("GL_UNSIGNED_BYTE", scm_from_int (GL_UNSIGNED_BYTE));
302 scm_c_define ("GL_POINTS", scm_from_int (GL_POINTS));
303 scm_c_define ("GL_LINES", scm_from_int (GL_LINES));
304 scm_c_define ("GL_LINE_LOOP", scm_from_int (GL_LINE_LOOP));
305 scm_c_define ("GL_LINE_STRIP", scm_from_int (GL_LINE_STRIP));
306 scm_c_define ("GL_TRIANGLES", scm_from_int (GL_TRIANGLES));
307 scm_c_define ("GL_TRIANGLE_STRIP", scm_from_int (GL_TRIANGLE_STRIP));
308 scm_c_define ("GL_TRIANGLE_FAN", scm_from_int (GL_TRIANGLE_FAN));
309 scm_c_define ("GL_QUADS", scm_from_int (GL_QUADS));
310 scm_c_define ("GL_QUAD_STRIP", scm_from_int (GL_QUAD_STRIP));
311 scm_c_define ("GL_POLYGON", scm_from_int (GL_POLYGON));
314 scm_c_define ("GL_MODELVIEW", scm_from_int (GL_MODELVIEW));
315 scm_c_define ("GL_PROJECTION", scm_from_int (GL_PROJECTION));
318 scm_c_define ("GL_LEQUAL", scm_from_int (GL_LEQUAL));
319 scm_c_define ("GL_DEPTH_TEST", scm_from_int (GL_DEPTH_TEST));
322 scm_c_define ("GL_LIGHTING", scm_from_int (GL_LIGHTING));
323 scm_c_define ("GL_LIGHT1", scm_from_int (GL_LIGHT1));
324 scm_c_define ("GL_AMBIENT", scm_from_int (GL_AMBIENT));
325 scm_c_define ("GL_DIFFUSE", scm_from_int (GL_DIFFUSE));
326 scm_c_define ("GL_POSITION", scm_from_int (GL_POSITION));
327 scm_c_define ("GL_SMOOTH", scm_from_int (GL_SMOOTH));
330 scm_c_define ("GL_BLEND", scm_from_int (GL_BLEND));
331 scm_c_define ("GL_ONE", scm_from_int (GL_ONE));
332 scm_c_define ("GL_SRC_ALPHA", scm_from_int (GL_SRC_ALPHA));
335 scm_c_define ("GL_LINEAR", scm_from_int (GL_LINEAR));
337 // Buffers, Pixel Drawing/Reading
338 scm_c_define ("GL_RGB", scm_from_int (GL_RGB));
339 scm_c_define ("GL_RGBA", scm_from_int (GL_RGBA));
342 scm_c_define ("GL_PERSPECTIVE_CORRECTION_HINT", scm_from_int (GL_PERSPECTIVE_CORRECTION_HINT));
343 scm_c_define ("GL_NICEST", scm_from_int (GL_NICEST));
346 scm_c_define ("GL_TEXTURE_2D", scm_from_int (GL_TEXTURE_2D));
347 scm_c_define ("GL_TEXTURE_MAG_FILTER", scm_from_int (GL_TEXTURE_MAG_FILTER));
348 scm_c_define ("GL_TEXTURE_MIN_FILTER", scm_from_int (GL_TEXTURE_MIN_FILTER));
349 scm_c_define ("GL_LINEAR_MIPMAP_NEAREST", scm_from_int (GL_LINEAR_MIPMAP_NEAREST));
350 scm_c_define ("GL_NEAREST", scm_from_int (GL_NEAREST));
352 // glPush/PopAttrib bits
353 scm_c_define ("GL_DEPTH_BUFFER_BIT", scm_from_int (GL_DEPTH_BUFFER_BIT));
354 scm_c_define ("GL_COLOR_BUFFER_BIT", scm_from_int (GL_COLOR_BUFFER_BIT));
357 scm_c_define ("GL_BGR", scm_from_int (GL_BGR));
358 scm_c_define ("GL_BGRA", scm_from_int (GL_BGRA));
361 scm_c_define_gsubr ("glBegin", 1, 0, 0, gacela_glBegin);
362 scm_c_define_gsubr ("glClear", 1, 0, 0, gacela_glClear);
363 scm_c_define_gsubr ("glClearColor", 4, 0, 0, gacela_glClearColor);
364 scm_c_define_gsubr ("glClearDepth", 1, 0, 0, gacela_glClearDepth);
365 scm_c_define_gsubr ("glColor3f", 3, 0, 0, gacela_glColor3f);
366 scm_c_define_gsubr ("glColor4f", 4, 0, 0, gacela_glColor4f);
367 scm_c_define_gsubr ("glDepthFunc", 1, 0, 0, gacela_glDepthFunc);
368 scm_c_define_gsubr ("glEnable", 1, 0, 0, gacela_glEnable);
369 scm_c_define_gsubr ("glDisable", 1, 0, 0, gacela_glDisable);
370 scm_c_define_gsubr ("glEnd", 0, 0, 0, gacela_glEnd);
371 scm_c_define_gsubr ("glHint", 2, 0, 0, gacela_glHint);
372 scm_c_define_gsubr ("glLoadIdentity", 0, 0, 0, gacela_glLoadIdentity);
373 scm_c_define_gsubr ("glMatrixMode", 1, 0, 0, gacela_glMatrixMode);
374 scm_c_define_gsubr ("glRotatef", 4, 0, 0, gacela_glRotatef);
375 scm_c_define_gsubr ("glShadeModel", 1, 0, 0, gacela_glShadeModel);
376 scm_c_define_gsubr ("glTranslatef", 3, 0, 0, gacela_glTranslatef);
377 scm_c_define_gsubr ("glVertex2f", 2, 0, 0, gacela_glVertex2f);
378 scm_c_define_gsubr ("glVertex3f", 3, 0, 0, gacela_glVertex3f);
379 scm_c_define_gsubr ("glViewport", 4, 0, 0, gacela_glViewport);
380 scm_c_define_gsubr ("glGenTextures", 1, 0, 0, gacela_glGenTextures);
381 scm_c_define_gsubr ("glDeleteTextures", 2, 0, 0, gacela_glDeleteTextures);
382 scm_c_define_gsubr ("glBindTexture", 2, 0, 0, gacela_glBindTexture);
383 scm_c_define_gsubr ("glTexImage2D", 9, 0, 0, gacela_glTexImage2D);
384 scm_c_define_gsubr ("glTexParameteri", 3, 0, 0, gacela_glTexParameteri);
385 scm_c_define_gsubr ("glTexCoord2f", 2, 0, 0, gacela_glTexCoord2f);
386 scm_c_define_gsubr ("glLightfv", 3, 0, 0, gacela_glLightfv);
387 scm_c_define_gsubr ("glNormal3f", 3, 0, 0, gacela_glNormal3f);
388 scm_c_define_gsubr ("glBlendFunc", 2, 0, 0, gacela_glBlendFunc);
389 scm_c_define_gsubr ("glOrtho", 6, 0, 0, gacela_glOrtho);
390 scm_c_define_gsubr ("glPushMatrix", 0, 0, 0, gacela_glPushMatrix);
391 scm_c_define_gsubr ("glPopMatrix", 0, 0, 0, gacela_glPopMatrix);
393 scm_c_define_gsubr ("gluPerspective", 4, 0, 0, gacela_gluPerspective);
394 scm_c_define_gsubr ("gluBuild2DMipmaps", 7, 0, 0, gacela_gluBuild2DMipmaps);
395 scm_c_define_gsubr ("gluLookAt", 9, 0, 0, gacela_gluLookAt);