]> git.jsancho.org Git - gacela.git/blob - gacela_GL.lisp
8b532f33e7f3a21022e8cfe76081d074f9e20eda
[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 (clines "#include <GL/gl.h>")
21 (clines "#include <GL/glu.h>")
22
23 ;;; Data types
24 (mapcconst int "int" "GL_UNSIGNED_BYTE")
25
26 ;;; Primitives
27 (mapcconst int "int" "GL_POINTS")
28 (mapcconst int "int" "GL_LINES")
29 (mapcconst int "int" "GL_LINE_LOOP")
30 (mapcconst int "int" "GL_LINE_STRIP")
31 (mapcconst int "int" "GL_TRIANGLES")
32 (mapcconst int "int" "GL_TRIANGLE_STRIP")
33 (mapcconst int "int" "GL_TRIANGLE_FAN")
34 (mapcconst int "int" "GL_QUADS")
35 (mapcconst int "int" "GL_QUAD_STRIP")
36 (mapcconst int "int" "GL_POLYGON")
37
38 ;;; Matrix Mode
39 (mapcconst int "int" "GL_MODELVIEW")
40 (mapcconst int "int" "GL_PROJECTION")
41
42 ;;; Depth buffer
43 (mapcconst int "int" "GL_LEQUAL")
44 (mapcconst int "int" "GL_DEPTH_TEST")
45
46 ;;; Lighting
47 (mapcconst int "int" "GL_LIGHTING")
48 (mapcconst int "int" "GL_LIGHT1")
49 (mapcconst int "int" "GL_AMBIENT")
50 (mapcconst int "int" "GL_DIFFUSE")
51 (mapcconst int "int" "GL_POSITION")
52 (mapcconst int "int" "GL_SMOOTH")
53
54 ;;; Blending
55 (mapcconst int "int" "GL_BLEND")
56 (mapcconst int "int" "GL_ONE")
57 (mapcconst int "int" "GL_SRC_ALPHA")
58
59 ;;; Fog
60 (mapcconst int "int" "GL_LINEAR")
61
62 ;;; Buffers, Pixel Drawing/Reading
63 (mapcconst int "int" "GL_RGB")
64 (mapcconst int "int" "GL_RGBA")
65
66 ;;; Hints
67 (mapcconst int "int" "GL_PERSPECTIVE_CORRECTION_HINT")
68 (mapcconst int "int" "GL_NICEST")
69
70 ;;; Texture mapping
71 (mapcconst int "int" "GL_TEXTURE_2D")
72 (mapcconst int "int" "GL_TEXTURE_MAG_FILTER")
73 (mapcconst int "int" "GL_TEXTURE_MIN_FILTER")
74 (mapcconst int "int" "GL_LINEAR_MIPMAP_NEAREST")
75 (mapcconst int "int" "GL_NEAREST")
76
77 ;;; glPush/PopAttrib bits
78 (mapcconst int "int" "GL_DEPTH_BUFFER_BIT")
79 (mapcconst int "int" "GL_COLOR_BUFFER_BIT")
80
81 ;;; OpenGL 1.2
82 (mapcconst int "int" "GL_BGR")
83 (mapcconst int "int" "GL_BGRA")
84
85 ;;; OpenGL Functions
86 (defcfun "void gacela_glBegin (int mode)" 0
87   "glBegin (mode);")
88
89 (defcfun "void gacela_glClear (int mask)" 0
90   "glClear (mask);")
91
92 (defcfun "void gacela_glClearColor (float red, float green, float blue, float alpha)" 0
93   "glClearColor (red, green, blue, alpha);")
94
95 (defcfun "void gacela_glClearDepth (double depth)" 0
96   "glClearDepth (depth);")
97
98 (defcfun "void gacela_glColor3f (float red, float green, float blue)" 0
99   "glColor3f (red, green, blue);")
100
101 (defcfun "void gacela_glColor4f (float red, float green, float blue, float alpha)" 0
102   "glColor4f (red, green, blue, alpha);")
103
104 (defcfun "void gacela_glDepthFunc (int func)" 0
105   "glDepthFunc (func);")
106
107 (defcfun "void gacela_glEnable (int cap)" 0
108   "glEnable (cap);")
109
110 (defcfun "void gacela_glDisable (int cap)" 0
111   "glDisable (cap);")
112
113 (defcfun "void gacela_glEnd (void)" 0
114   "glEnd ();")
115
116 (defcfun "void gacela_glHint (int target, int mode)" 0
117   "glHint (target, mode);")
118
119 (defcfun "void gacela_glLoadIdentity (void)" 0
120   "glLoadIdentity ();")
121
122 (defcfun "void gacela_glMatrixMode (int mode)" 0
123   "glMatrixMode (mode);")
124
125 (defcfun "void gacela_glRotatef (float angle, float x, float y, float z)" 0
126   "glRotatef (angle, x, y, z);")
127
128 (defcfun "void gacela_glShadeModel (int mode)" 0
129   "glShadeModel (mode);")
130
131 (defcfun "void gacela_glTranslatef (float x, float y, float z)" 0
132   "glTranslatef (x, y, z);")
133
134 (defcfun "void gacela_glVertex2f (float x, float y)" 0
135   "glVertex2f (x, y);")
136
137 (defcfun "void gacela_glVertex3f (float x, float y, float z)" 0
138   "glVertex3f (x, y, z);")
139
140 (defcfun "void gacela_glViewport (int x, int y, int width, int height)" 0
141   "glViewport (x, y, width, height);")
142
143 (defcfun "static object gacela_glGenTextures (int n)" 0
144   "object textures;"
145   "GLuint text[n];"
146   "int i, t;"
147   ('nil textures)
148   "glGenTextures (n, &text[0]);"
149   "for (i = n - 1; i >= 0; i--) {"
150   "t = text[i];"
151   ((cons (int t) textures) textures)
152   "}"
153   "return textures;")
154
155 (defcfun "void gacela_glDeleteTextures (int n, object textures)" 0
156   "GLuint text[n];"
157   "int i, t;"
158   "for (i = 0; i < n; i++) {"
159   ((nth (int i) textures) t)
160   "text[i] = t;"
161   "}"
162   "glDeleteTextures (n, &text[0]);")
163
164 (defcfun "void gacela_glBindTexture (int target, int texture)" 0
165   "glBindTexture (target, texture);")
166
167 (defcfun "void gacela_glTexImage2D (int target, int level, int internalFormat, int width, int height, int border, int format, int type, int pixels)" 0
168   "glTexImage2D (target, level, internalFormat, width, height, border, format, type, pixels);")
169
170 (defcfun "void gacela_glTexParameteri (int target, int pname, int param)" 0
171   "glTexParameteri (target, pname, param);")
172
173 (defcfun "void gacela_glTexCoord2f (float s, float t)" 0
174   "glTexCoord2f (s, t);")
175
176 (defcfun "void gacela_glLightfv (int light, int pname, float param1, float param2, float param3, float param4)" 0
177   "GLfloat params[4];"
178   "params[0] = param1;"
179   "params[1] = param2;"
180   "params[2] = param3;"
181   "params[3] = param4;"
182   "glLightfv (light, pname, params);")
183
184 (defcfun "void gacela_glNormal3f (float nx, float ny, float nz)" 0
185   "glNormal3f (nx, ny, nz);")
186
187 (defcfun "void gacela_glBlendFunc (int sfactor, int dfactor)" 0
188   "glBlendFunc (sfactor, dfactor);")
189
190 (defcfun "void gacela_glOrtho (float left, float right, float bottom, float top, float near_val, float far_val)" 0
191   "glOrtho (left, right, bottom, top, near_val, far_val);")
192
193 (defcfun "void gacela_gluPerspective (double fovy, double aspect, double zNear, double zFar)" 0
194   "gluPerspective (fovy, aspect, zNear, zFar);")
195
196 (defcfun "int gacela_gluBuild2DMipmaps (int target, int internalFormat, int width, int height, int format, int type, int data)" 0
197   "return gluBuild2DMipmaps (target, internalFormat, width, height, format, type, data);")
198
199 (defentry glBegin (int) (void "gacela_glBegin"))
200 (defentry glClear (int) (void "gacela_glClear"))
201 (defentry glClearColor (float float float float) (void "gacela_glClearColor"))
202 (defentry glClearDepth (double) (void "gacela_glClearDepth"))
203 (defentry glColor3f (float float float) (void "gacela_glColor3f"))
204 (defentry glColor4f (float float float float) (void "gacela_glColor4f"))
205 (defentry glDepthFunc (int) (void "gacela_glDepthFunc"))
206 (defentry glEnable (int) (void "gacela_glEnable"))
207 (defentry glDisable (int) (void "gacela_glDisable"))
208 (defentry glEnd () (void "gacela_glEnd"))
209 (defentry glHint (int int) (void "gacela_glHint"))
210 (defentry glLoadIdentity () (void "gacela_glLoadIdentity"))
211 (defentry glMatrixMode (int) (void "gacela_glMatrixMode"))
212 (defentry glRotatef (float float float float) (void "gacela_glRotatef"))
213 (defentry glShadeModel (int) (void "gacela_glShadeModel"))
214 (defentry glTranslatef (float float float) (void "gacela_glTranslatef"))
215 (defentry glVertex2f (float float) (void "gacela_glVertex2f"))
216 (defentry glVertex3f (float float float) (void "gacela_glVertex3f"))
217 (defentry glViewport (int int int int) (void "gacela_glViewport"))
218 (defentry glGenTextures (int) (object "gacela_glGenTextures"))
219 (defentry glDeleteTextures (int object) (void "gacela_glDeleteTextures"))
220 (defentry glBindTexture (int int) (void "gacela_glBindTexture"))
221 (defentry glTexImage2D (int int int int int int int int int) (void "gacela_glTexImage2D"))
222 (defentry glTexParameteri (int int int) (void "gacela_glTexParameteri"))
223 (defentry glTexCoord2f (float float) (void "gacela_glTexCoord2f"))
224 (defentry glLightfv (int int float float float float) (void "gacela_glLightfv"))
225 (defentry glNormal3f (float float float) (void "gacela_glNormal3f"))
226 (defentry glBlendFunc (int int) (void "gacela_glBlendFunc"))
227 (defentry glOrtho (float float float float float float) (void "gacela_glOrtho"))
228
229 (defentry gluPerspective (double double double double) (void "gacela_gluPerspective"))
230 (defentry gluBuild2DMipmaps (int int int int int int int) (int "gacela_gluBuild2DMipmaps"))