]> git.jsancho.org Git - gacela.git/blob - gacela_GL.lisp
84e38d63cb6fb269e9548afaf7b41f002ff40e97
[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_glDepthFunc (int func)" 0
102   "glDepthFunc (func);")
103
104 (defcfun "void gacela_glEnable (int cap)" 0
105   "glEnable (cap);")
106
107 (defcfun "void gacela_glDisable (int cap)" 0
108   "glDisable (cap);")
109
110 (defcfun "void gacela_glEnd (void)" 0
111   "glEnd ();")
112
113 (defcfun "void gacela_glHint (int target, int mode)" 0
114   "glHint (target, mode);")
115
116 (defcfun "void gacela_glLoadIdentity (void)" 0
117   "glLoadIdentity ();")
118
119 (defcfun "void gacela_glMatrixMode (int mode)" 0
120   "glMatrixMode (mode);")
121
122 (defcfun "void gacela_glRotatef (float angle, float x, float y, float z)" 0
123   "glRotatef (angle, x, y, z);")
124
125 (defcfun "void gacela_glShadeModel (int mode)" 0
126   "glShadeModel (mode);")
127
128 (defcfun "void gacela_glTranslatef (float x, float y, float z)" 0
129   "glTranslatef (x, y, z);")
130
131 (defcfun "void gacela_glVertex2f (float x, float y)" 0
132   "glVertex2f (x, y);")
133
134 (defcfun "void gacela_glVertex3f (float x, float y, float z)" 0
135   "glVertex3f (x, y, z);")
136
137 (defcfun "void gacela_glViewport (int x, int y, int width, int height)" 0
138   "glViewport (x, y, width, height);")
139
140 (defcfun "static object gacela_glGenTextures (int n)" 0
141   "object textures;"
142   "GLuint text[n];"
143   "int i, t;"
144   ('nil textures)
145   "glGenTextures (n, &text[0]);"
146   "for (i = n - 1; i >= 0; i--) {"
147   "t = text[i];"
148   ((cons (int t) textures) textures)
149   "}"
150   "return textures;")
151
152 (defcfun "void gacela_glBindTexture (int target, int texture)" 0
153   "glBindTexture (target, texture);")
154
155 (defcfun "void gacela_glTexImage2D (int target, int level, int internalFormat, int width, int height, int border, int format, int type, int pixels)" 0
156   "glTexImage2D (target, level, internalFormat, width, height, border, format, type, pixels);")
157
158 (defcfun "void gacela_glTexParameteri (int target, int pname, int param)" 0
159   "glTexParameteri (target, pname, param);")
160
161 (defcfun "void gacela_glTexCoord2f (float s, float t)" 0
162   "glTexCoord2f (s, t);")
163
164 (defcfun "void gacela_glLightfv (int light, int pname, float param1, float param2, float param3, float param4)" 0
165   "GLfloat params[4];"
166   "params[0] = param1;"
167   "params[1] = param2;"
168   "params[2] = param3;"
169   "params[3] = param4;"
170   "glLightfv (light, pname, params);")
171
172 (defcfun "void gacela_glNormal3f (float nx, float ny, float nz)" 0
173   "glNormal3f (nx, ny, nz);")
174
175 (defcfun "void gacela_glBlendFunc (int sfactor, int dfactor)" 0
176   "glBlendFunc (sfactor, dfactor);")
177
178 (defcfun "void gacela_glOrtho (float left, float right, float bottom, float top, float near_val, float far_val)" 0
179   "glOrtho (left, right, bottom, top, near_val, far_val);")
180
181 (defcfun "void gacela_gluPerspective (double fovy, double aspect, double zNear, double zFar)" 0
182   "gluPerspective (fovy, aspect, zNear, zFar);")
183
184 (defcfun "int gacela_gluBuild2DMipmaps (int target, int internalFormat, int width, int height, int format, int type, int data)" 0
185   "return gluBuild2DMipmaps (target, internalFormat, width, height, format, type, data);")
186
187 (defentry glBegin (int) (void "gacela_glBegin"))
188 (defentry glClear (int) (void "gacela_glClear"))
189 (defentry glClearColor (float float float float) (void "gacela_glClearColor"))
190 (defentry glClearDepth (double) (void "gacela_glClearDepth"))
191 (defentry glColor3f (float float float) (void "gacela_glColor3f"))
192 (defentry glDepthFunc (int) (void "gacela_glDepthFunc"))
193 (defentry glEnable (int) (void "gacela_glEnable"))
194 (defentry glDisable (int) (void "gacela_glDisable"))
195 (defentry glEnd () (void "gacela_glEnd"))
196 (defentry glHint (int int) (void "gacela_glHint"))
197 (defentry glLoadIdentity () (void "gacela_glLoadIdentity"))
198 (defentry glMatrixMode (int) (void "gacela_glMatrixMode"))
199 (defentry glRotatef (float float float float) (void "gacela_glRotatef"))
200 (defentry glShadeModel (int) (void "gacela_glShadeModel"))
201 (defentry glTranslatef (float float float) (void "gacela_glTranslatef"))
202 (defentry glVertex2f (float float) (void "gacela_glVertex2f"))
203 (defentry glVertex3f (float float float) (void "gacela_glVertex3f"))
204 (defentry glViewport (int int int int) (void "gacela_glViewport"))
205 (defentry glGenTextures (int) (object "gacela_glGenTextures"))
206 (defentry glBindTexture (int int) (void "gacela_glBindTexture"))
207 (defentry glTexImage2D (int int int int int int int int int) (void "gacela_glTexImage2D"))
208 (defentry glTexParameteri (int int int) (void "gacela_glTexParameteri"))
209 (defentry glTexCoord2f (float float) (void "gacela_glTexCoord2f"))
210 (defentry glLightfv (int int float float float float) (void "gacela_glLightfv"))
211 (defentry glNormal3f (float float float) (void "gacela_glNormal3f"))
212 (defentry glBlendFunc (int int) (void "gacela_glBlendFunc"))
213 (defentry glOrtho (float float float float float float) (void "gacela_glOrtho"))
214
215 (defentry gluPerspective (double double double double) (void "gacela_gluPerspective"))
216 (defentry gluBuild2DMipmaps (int int int int int int int) (int "gacela_gluBuild2DMipmaps"))