3 * Mesa 3-D graphics library
5 * Copyright (C) 1995-2001 Brian Paul
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 * Miscellaneous utility functions
41 #define M_PI 3.1415926536
45 #ifndef GLU_INCOMPATIBLE_GL_VERSION
46 #define GLU_INCOMPATIBLE_GL_VERSION 100903
51 gluLookAt(GLdouble eyex
, GLdouble eyey
, GLdouble eyez
,
52 GLdouble centerx
, GLdouble centery
, GLdouble centerz
,
53 GLdouble upx
, GLdouble upy
, GLdouble upz
)
56 GLfloat x
[3], y
[3], z
[3];
59 /* Make rotation matrix */
62 z
[0] = eyex
- centerx
;
63 z
[1] = eyey
- centery
;
64 z
[2] = eyez
- centerz
;
65 mag
= sqrt(z
[0] * z
[0] + z
[1] * z
[1] + z
[2] * z
[2]);
66 if (mag
) { /* mpichler, 19950515 */
77 /* X vector = Y cross Z */
78 x
[0] = y
[1] * z
[2] - y
[2] * z
[1];
79 x
[1] = -y
[0] * z
[2] + y
[2] * z
[0];
80 x
[2] = y
[0] * z
[1] - y
[1] * z
[0];
82 /* Recompute Y = Z cross X */
83 y
[0] = z
[1] * x
[2] - z
[2] * x
[1];
84 y
[1] = -z
[0] * x
[2] + z
[2] * x
[0];
85 y
[2] = z
[0] * x
[1] - z
[1] * x
[0];
87 /* mpichler, 19950515 */
88 /* cross product gives area of parallelogram, which is < 1.0 for
89 * non-perpendicular unit-length vectors; so normalize x, y here
92 mag
= sqrt(x
[0] * x
[0] + x
[1] * x
[1] + x
[2] * x
[2]);
99 mag
= sqrt(y
[0] * y
[0] + y
[1] * y
[1] + y
[2] * y
[2]);
106 #define M(row,col) m[col*4+row]
126 /* Translate Eye to Origin */
127 glTranslatef(-eyex
, -eyey
, -eyez
);
134 gluOrtho2D(GLdouble left
, GLdouble right
, GLdouble bottom
, GLdouble top
)
136 glOrtho(left
, right
, bottom
, top
, -1.0, 1.0);
142 frustum(GLfloat left
, GLfloat right
,
143 GLfloat bottom
, GLfloat top
,
144 GLfloat nearval
, GLfloat farval
)
146 GLfloat x
, y
, a
, b
, c
, d
;
149 x
= (2.0 * nearval
) / (right
- left
);
150 y
= (2.0 * nearval
) / (top
- bottom
);
151 a
= (right
+ left
) / (right
- left
);
152 b
= (top
+ bottom
) / (top
- bottom
);
153 c
= -(farval
+ nearval
) / ( farval
- nearval
);
154 d
= -(2.0 * farval
* nearval
) / (farval
- nearval
);
156 #define M(row,col) m[col*4+row]
157 M(0,0) = x
; M(0,1) = 0.0F
; M(0,2) = a
; M(0,3) = 0.0F
;
158 M(1,0) = 0.0F
; M(1,1) = y
; M(1,2) = b
; M(1,3) = 0.0F
;
159 M(2,0) = 0.0F
; M(2,1) = 0.0F
; M(2,2) = c
; M(2,3) = d
;
160 M(3,0) = 0.0F
; M(3,1) = 0.0F
; M(3,2) = -1.0F
; M(3,3) = 0.0F
;
168 gluPerspective(GLdouble fovy
, GLdouble aspect
, GLdouble zNear
, GLdouble zFar
)
170 GLfloat xmin
, xmax
, ymin
, ymax
;
172 ymax
= zNear
* tan(fovy
* M_PI
/ 360.0);
174 xmin
= ymin
* aspect
;
175 xmax
= ymax
* aspect
;
177 /* don't call glFrustum() because of error semantics (covglu) */
178 frustum(xmin
, xmax
, ymin
, ymax
, zNear
, zFar
);
184 gluPickMatrix(GLdouble x
, GLdouble y
,
185 GLdouble width
, GLdouble height
, GLint viewport
[4])
191 sx
= viewport
[2] / width
;
192 sy
= viewport
[3] / height
;
193 tx
= (viewport
[2] + 2.0 * (viewport
[0] - x
)) / width
;
194 ty
= (viewport
[3] + 2.0 * (viewport
[1] - y
)) / height
;
196 #define M(row,col) m[col*4+row]
220 const GLubyte
*GLAPIENTRY
221 gluErrorString(GLenum errorCode
)
223 static char *tess_error
[] = {
224 "missing gluBeginPolygon",
225 "missing gluBeginContour",
226 "missing gluEndPolygon",
227 "missing gluEndContour",
228 "misoriented or self-intersecting loops",
229 "coincident vertices",
231 "FIST recovery process fatal error"
233 static char *nurbs_error
[] = {
234 "spline order un-supported",
236 "valid knot range is empty",
237 "decreasing knot sequence knot",
238 "knot multiplicity greater than order of spline",
239 "endcurve() must follow bgncurve()",
240 "bgncurve() must precede endcurve()",
241 "missing or extra geometric data",
242 "can't draw pwlcurves",
243 "missing bgncurve()",
244 "missing bgnsurface()",
245 "endtrim() must precede endsurface()",
246 "bgnsurface() must precede endsurface()",
247 "curve of improper type passed as trim curve",
248 "bgnsurface() must precede bgntrim()",
249 "endtrim() must follow bgntrim()",
250 "bgntrim() must precede endtrim()",
251 "invalid or missing trim curve",
252 "bgntrim() must precede pwlcurve()",
253 "pwlcurve referenced twice",
254 "pwlcurve and nurbscurve mixed",
255 "improper usage of trim data type",
256 "nurbscurve referenced twice",
257 "nurbscurve and pwlcurve mixed",
258 "nurbssurface referenced twice",
260 "endsurface() must follow bgnsurface()",
261 "misoriented trim curves",
262 "intersecting trim curves",
264 "unconnected trim curves",
265 "unknown knot error",
266 "negative vertex count encountered",
267 "negative byte-stride encountered",
268 "unknown type descriptor",
269 "null control array or knot vector",
270 "duplicate point on pwlcurve"
274 if (errorCode
== GL_NO_ERROR
) {
275 return (GLubyte
*) "no error";
277 else if (errorCode
== GL_INVALID_VALUE
) {
278 return (GLubyte
*) "invalid value";
280 else if (errorCode
== GL_INVALID_ENUM
) {
281 return (GLubyte
*) "invalid enum";
283 else if (errorCode
== GL_INVALID_OPERATION
) {
284 return (GLubyte
*) "invalid operation";
286 else if (errorCode
== GL_STACK_OVERFLOW
) {
287 return (GLubyte
*) "stack overflow";
289 else if (errorCode
== GL_STACK_UNDERFLOW
) {
290 return (GLubyte
*) "stack underflow";
292 else if (errorCode
== GL_OUT_OF_MEMORY
) {
293 return (GLubyte
*) "out of memory";
296 else if (errorCode
== GLU_NO_ERROR
) {
297 return (GLubyte
*) "no error";
299 else if (errorCode
== GLU_INVALID_ENUM
) {
300 return (GLubyte
*) "invalid enum";
302 else if (errorCode
== GLU_INVALID_VALUE
) {
303 return (GLubyte
*) "invalid value";
305 else if (errorCode
== GLU_OUT_OF_MEMORY
) {
306 return (GLubyte
*) "out of memory";
308 else if (errorCode
== GLU_INCOMPATIBLE_GL_VERSION
) {
309 return (GLubyte
*) "incompatible GL version";
311 else if (errorCode
>= GLU_TESS_ERROR1
&& errorCode
<= GLU_TESS_ERROR8
) {
312 return (GLubyte
*) tess_error
[errorCode
- GLU_TESS_ERROR1
];
314 else if (errorCode
>= GLU_NURBS_ERROR1
&& errorCode
<= GLU_NURBS_ERROR37
) {
315 return (GLubyte
*) nurbs_error
[errorCode
- GLU_NURBS_ERROR1
];
328 const GLubyte
*GLAPIENTRY
329 gluGetString(GLenum name
)
331 static char *extensions
= "GL_EXT_abgr";
332 static char *version
= "1.1 Mesa 3.5";
336 return (GLubyte
*) extensions
;
338 return (GLubyte
*) version
;
346 #if 0 /* gluGetProcAddressEXT not finalized yet! */
350 void GLAPIENTRY(*gluGetProcAddressEXT(const GLubyte
* procName
)) (...)
352 void (GLAPIENTRY
* gluGetProcAddressEXT(const GLubyte
* procName
)) ()
360 static struct proc procTable
[] = {
361 {"gluGetProcAddressEXT", (void *) gluGetProcAddressEXT
}, /* me! */
363 /* new 1.1 functions */
364 {"gluGetString", (void *) gluGetString
},
366 /* new 1.2 functions */
367 {"gluTessBeginPolygon", (void *) gluTessBeginPolygon
},
368 {"gluTessBeginContour", (void *) gluTessBeginContour
},
369 {"gluTessEndContour", (void *) gluTessEndContour
},
370 {"gluTessEndPolygon", (void *) gluTessEndPolygon
},
371 {"gluGetTessProperty", (void *) gluGetTessProperty
},
373 /* new 1.3 functions */
379 for (i
= 0; procTable
[i
].address
; i
++) {
380 if (strcmp((const char *) procName
, procTable
[i
].name
) == 0)
381 return (void (GLAPIENTRY
*) ()) procTable
[i
].address
;
394 #ifdef GLU_VERSION_1_3
396 gluCheckExtension(const GLubyte
*extName
, const GLubyte
* extString
)
401 const int len
= strlen((const char *) extName
);
402 const char *start
= (const char *) extString
;
405 const char *c
= strstr(start
, (const char *) extName
);
409 if ((c
== start
|| c
[-1] == ' ') && (c
[len
] == ' ' || c
[len
] == 0))