]> 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 (in-package :gacela)
19
20 (clines "#include <GL/gl.h>")
21 (clines "#include <GL/glu.h>")
22
23 ;;; Data types
24 (defconstant GL_UNSIGNED_BYTE                 #x1401)
25
26 ;;; Primitives
27 (defconstant GL_POINTS                        #x0000)
28 (defconstant GL_LINES                         #x0001)
29 (defconstant GL_LINE_LOOP                     #x0002)
30 (defconstant GL_LINE_STRIP                    #x0003)
31 (defconstant GL_TRIANGLES                     #x0004)
32 (defconstant GL_TRIANGLE_STRIP                #x0005)
33 (defconstant GL_TRIANGLE_FAN                  #x0006)
34 (defconstant GL_QUADS                         #x0007)
35 (defconstant GL_QUAD_STRIP                    #x0008)
36 (defconstant GL_POLYGON                       #x0009)
37
38 ;;; Matrix Mode
39 (defconstant GL_MODELVIEW                     #x1700)
40 (defconstant GL_PROJECTION                    #x1701)
41
42 ;;; Depth buffer
43 (defconstant GL_LEQUAL                        #x0203)
44 (defconstant GL_DEPTH_TEST                    #x0B71)
45
46 ;;; Lighting
47 (defconstant GL_LIGHTING                      #x0B50)
48 (defconstant GL_LIGHT1                        #x4001)
49 (defconstant GL_AMBIENT                       #x1200)
50 (defconstant GL_DIFFUSE                       #x1201)
51 (defconstant GL_POSITION                      #x1203)
52 (defconstant GL_SMOOTH                        #x1D01)
53
54 ;;; Blending
55 (defconstant GL_BLEND                         #x0BE2)
56 (defconstant GL_ONE                           #x1)
57 (defconstant GL_SRC_ALPHA                     #x0302)
58
59 ;;; Fog
60 (defconstant GL_LINEAR                        #x2601)
61
62 ;;; Buffers, Pixel Drawing/Reading
63 (defconstant GL_RGB                           #x1907)
64 (defconstant GL_RGBA                          #x1908)
65
66 ;;; Hints
67 (defconstant GL_PERSPECTIVE_CORRECTION_HINT   #x0C50)
68 (defconstant GL_NICEST                        #x1102)
69
70 ;;; Texture mapping
71 (defconstant GL_TEXTURE_2D                    #x0DE1)
72 (defconstant GL_TEXTURE_MAG_FILTER            #x2800)
73 (defconstant GL_TEXTURE_MIN_FILTER            #x2801)
74 (defconstant GL_LINEAR_MIPMAP_NEAREST         #x2701)
75 (defconstant GL_NEAREST                       #x2600)
76
77 ;;; glPush/PopAttrib bits
78 (defconstant GL_DEPTH_BUFFER_BIT              #x00000100)
79 (defconstant GL_COLOR_BUFFER_BIT              #x00004000)
80
81 ;;; OpenGL 1.2
82 (defconstant GL_BGR                           #x80E0)
83 (defconstant GL_BGRA                          #x80E1)
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_glBindTexture (int target, int texture)" 0
156   "glBindTexture (target, texture);")
157
158 (defcfun "void gacela_glTexImage2D (int target, int level, int internalFormat, int width, int height, int border, int format, int type, int pixels)" 0
159   "glTexImage2D (target, level, internalFormat, width, height, border, format, type, pixels);")
160
161 (defcfun "void gacela_glTexParameteri (int target, int pname, int param)" 0
162   "glTexParameteri (target, pname, param);")
163
164 (defcfun "void gacela_glTexCoord2f (float s, float t)" 0
165   "glTexCoord2f (s, t);")
166
167 (defcfun "void gacela_glLightfv (int light, int pname, float param1, float param2, float param3, float param4)" 0
168   "GLfloat params[4];"
169   "params[0] = param1;"
170   "params[1] = param2;"
171   "params[2] = param3;"
172   "params[3] = param4;"
173   "glLightfv (light, pname, params);")
174
175 (defcfun "void gacela_glNormal3f (float nx, float ny, float nz)" 0
176   "glNormal3f (nx, ny, nz);")
177
178 (defcfun "void gacela_glBlendFunc (int sfactor, int dfactor)" 0
179   "glBlendFunc (sfactor, dfactor);")
180
181 (defcfun "void gacela_glOrtho (float left, float right, float bottom, float top, float near_val, float far_val)" 0
182   "glOrtho (left, right, bottom, top, near_val, far_val);")
183
184 (defcfun "void gacela_gluPerspective (double fovy, double aspect, double zNear, double zFar)" 0
185   "gluPerspective (fovy, aspect, zNear, zFar);")
186
187 (defcfun "int gacela_gluBuild2DMipmaps (int target, int internalFormat, int width, int height, int format, int type, int data)" 0
188   "return gluBuild2DMipmaps (target, internalFormat, width, height, format, type, data);")
189
190 (defentry glBegin (int) (void "gacela_glBegin"))
191 (defentry glClear (int) (void "gacela_glClear"))
192 (defentry glClearColor (float float float float) (void "gacela_glClearColor"))
193 (defentry glClearDepth (double) (void "gacela_glClearDepth"))
194 (defentry glColor3f (float float float) (void "gacela_glColor3f"))
195 (defentry glColor4f (float float float float) (void "gacela_glColor4f"))
196 (defentry glDepthFunc (int) (void "gacela_glDepthFunc"))
197 (defentry glEnable (int) (void "gacela_glEnable"))
198 (defentry glDisable (int) (void "gacela_glDisable"))
199 (defentry glEnd () (void "gacela_glEnd"))
200 (defentry glHint (int int) (void "gacela_glHint"))
201 (defentry glLoadIdentity () (void "gacela_glLoadIdentity"))
202 (defentry glMatrixMode (int) (void "gacela_glMatrixMode"))
203 (defentry glRotatef (float float float float) (void "gacela_glRotatef"))
204 (defentry glShadeModel (int) (void "gacela_glShadeModel"))
205 (defentry glTranslatef (float float float) (void "gacela_glTranslatef"))
206 (defentry glVertex2f (float float) (void "gacela_glVertex2f"))
207 (defentry glVertex3f (float float float) (void "gacela_glVertex3f"))
208 (defentry glViewport (int int int int) (void "gacela_glViewport"))
209 (defentry glGenTextures (int) (object "gacela_glGenTextures"))
210 (defentry glBindTexture (int int) (void "gacela_glBindTexture"))
211 (defentry glTexImage2D (int int int int int int int int int) (void "gacela_glTexImage2D"))
212 (defentry glTexParameteri (int int int) (void "gacela_glTexParameteri"))
213 (defentry glTexCoord2f (float float) (void "gacela_glTexCoord2f"))
214 (defentry glLightfv (int int float float float float) (void "gacela_glLightfv"))
215 (defentry glNormal3f (float float float) (void "gacela_glNormal3f"))
216 (defentry glBlendFunc (int int) (void "gacela_glBlendFunc"))
217 (defentry glOrtho (float float float float float float) (void "gacela_glOrtho"))
218
219 (defentry gluPerspective (double double double double) (void "gacela_gluPerspective"))
220 (defentry gluBuild2DMipmaps (int int int int int int int) (int "gacela_gluBuild2DMipmaps"))