1 // These are just the bits of GLU we use so we can ditch the external
2 // dependency (since it turns out to be complicated, as it depends on libGL,
3 // which we load dynamically, etc). This is from SGI's open source version.
6 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
7 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice including the dates of first publication and
17 * either this permission notice or a reference to
18 * http://oss.sgi.com/projects/FreeB/
19 * shall be included in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
26 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 * Except as contained in this notice, the name of Silicon Graphics, Inc.
30 * shall not be used in advertising or otherwise to promote the sale, use or
31 * other dealings in this Software without prior written authorization from
32 * Silicon Graphics, Inc.
41 ** Make m an identity matrix
43 static void __gluMakeIdentityd(GLdouble m[16])
45 m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0;
46 m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
47 m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
48 m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
51 static void __gluMakeIdentityf(GLfloat m[16])
53 m[0+4*0] = 1; m[0+4*1] = 0; m[0+4*2] = 0; m[0+4*3] = 0;
54 m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
55 m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
56 m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
60 gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
62 glOrtho(left, right, bottom, top, -1, 1);
65 #define __glPi 3.14159265358979323846
68 gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
71 double sine, cotangent, deltaZ;
72 double radians = fovy / 2 * __glPi / 180;
74 deltaZ = zFar - zNear;
76 if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) {
79 cotangent = cos(radians) / sine;
81 __gluMakeIdentityd(&m[0][0]);
82 m[0][0] = cotangent / aspect;
84 m[2][2] = -(zFar + zNear) / deltaZ;
86 m[3][2] = -2 * zNear * zFar / deltaZ;
88 glMultMatrixd(&m[0][0]);