Brian Paul | 976c26c | 2001-08-20 16:07:10 +0000 | [diff] [blame] | 1 | |
| 2 | /* Copyright (c) Mark J. Kilgard, 1994. */ |
| 3 | |
| 4 | /* |
| 5 | * (c) Copyright 1993, Silicon Graphics, Inc. |
| 6 | * ALL RIGHTS RESERVED |
| 7 | * Permission to use, copy, modify, and distribute this software for |
| 8 | * any purpose and without fee is hereby granted, provided that the above |
| 9 | * copyright notice appear in all copies and that both the copyright notice |
| 10 | * and this permission notice appear in supporting documentation, and that |
| 11 | * the name of Silicon Graphics, Inc. not be used in advertising |
| 12 | * or publicity pertaining to distribution of the software without specific, |
| 13 | * written prior permission. |
| 14 | * |
| 15 | * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" |
| 16 | * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, |
| 17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON |
| 19 | * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, |
| 20 | * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY |
| 21 | * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, |
| 22 | * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF |
| 23 | * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN |
| 24 | * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON |
| 25 | * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE |
| 26 | * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. |
| 27 | * |
| 28 | * US Government Users Restricted Rights |
| 29 | * Use, duplication, or disclosure by the Government is subject to |
| 30 | * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph |
| 31 | * (c)(1)(ii) of the Rights in Technical Data and Computer Software |
| 32 | * clause at DFARS 252.227-7013 and/or in similar or successor |
| 33 | * clauses in the FAR or the DOD or NASA FAR Supplement. |
| 34 | * Unpublished-- rights reserved under the copyright laws of the |
| 35 | * United States. Contractor/manufacturer is Silicon Graphics, |
| 36 | * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. |
| 37 | * |
| 38 | * OpenGL(TM) is a trademark of Silicon Graphics, Inc. |
| 39 | */ |
| 40 | |
| 41 | /* Original name: accanti.c |
| 42 | * |
| 43 | * Conversion to UGL/Mesa by Stephane Raimbault |
| 44 | */ |
| 45 | |
| 46 | #include <stdio.h> |
| 47 | #include <math.h> |
| 48 | |
| 49 | #include <ugl/ugl.h> |
| 50 | #include <ugl/uglevent.h> |
| 51 | #include <ugl/uglinput.h> |
| 52 | |
| 53 | #include <GL/uglmesa.h> |
| 54 | #include <GL/uglglutshapes.h> |
| 55 | |
| 56 | #include "../book/jitter.h" |
| 57 | |
| 58 | UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId; |
| 59 | UGL_LOCAL UGL_EVENT_Q_ID qId; |
| 60 | UGL_LOCAL UGL_MESA_CONTEXT umc; |
| 61 | |
| 62 | /* Initialize lighting and other values. |
| 63 | */ |
| 64 | UGL_LOCAL void initGL(GLsizei w, GLsizei h) |
| 65 | { |
| 66 | GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; |
| 67 | GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; |
| 68 | GLfloat light_position[] = { 0.0, 0.0, 10.0, 1.0 }; |
| 69 | GLfloat lm_ambient[] = { 0.2, 0.2, 0.2, 1.0 }; |
| 70 | |
| 71 | glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); |
| 72 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); |
| 73 | glMaterialf(GL_FRONT, GL_SHININESS, 50.0); |
| 74 | glLightfv(GL_LIGHT0, GL_POSITION, light_position); |
| 75 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lm_ambient); |
| 76 | |
| 77 | glEnable(GL_LIGHTING); |
| 78 | glEnable(GL_LIGHT0); |
| 79 | glDepthFunc(GL_LESS); |
| 80 | glEnable(GL_DEPTH_TEST); |
| 81 | glShadeModel (GL_FLAT); |
| 82 | |
| 83 | glClearColor(0.0, 0.0, 0.0, 0.0); |
| 84 | glClearAccum(0.0, 0.0, 0.0, 0.0); |
| 85 | |
| 86 | glMatrixMode(GL_PROJECTION); |
| 87 | glLoadIdentity(); |
| 88 | if (w <= h) |
| 89 | glOrtho (-2.25, 2.25, -2.25*h/w, 2.25*h/w, -10.0, 10.0); |
| 90 | else |
| 91 | glOrtho (-2.25*w/h, 2.25*w/h, -2.25, 2.25, -10.0, 10.0); |
| 92 | glMatrixMode(GL_MODELVIEW); |
| 93 | } |
| 94 | |
| 95 | UGL_LOCAL void displayObjects(void) |
| 96 | { |
| 97 | GLfloat torus_diffuse[] = { 0.7, 0.7, 0.0, 1.0 }; |
| 98 | GLfloat cube_diffuse[] = { 0.0, 0.7, 0.7, 1.0 }; |
| 99 | GLfloat sphere_diffuse[] = { 0.7, 0.0, 0.7, 1.0 }; |
| 100 | GLfloat octa_diffuse[] = { 0.7, 0.4, 0.4, 1.0 }; |
| 101 | |
| 102 | glPushMatrix (); |
| 103 | glRotatef (30.0, 1.0, 0.0, 0.0); |
| 104 | |
| 105 | glPushMatrix (); |
| 106 | glTranslatef (-0.80, 0.35, 0.0); |
| 107 | glRotatef (100.0, 1.0, 0.0, 0.0); |
| 108 | glMaterialfv(GL_FRONT, GL_DIFFUSE, torus_diffuse); |
| 109 | glutSolidTorus (0.275, 0.85, 16, 16); |
| 110 | glPopMatrix (); |
| 111 | |
| 112 | glPushMatrix (); |
| 113 | glTranslatef (-0.75, -0.50, 0.0); |
| 114 | glRotatef (45.0, 0.0, 0.0, 1.0); |
| 115 | glRotatef (45.0, 1.0, 0.0, 0.0); |
| 116 | glMaterialfv(GL_FRONT, GL_DIFFUSE, cube_diffuse); |
| 117 | glutSolidCube (1.5); |
| 118 | glPopMatrix (); |
| 119 | |
| 120 | glPushMatrix (); |
| 121 | glTranslatef (0.75, 0.60, 0.0); |
| 122 | glRotatef (30.0, 1.0, 0.0, 0.0); |
| 123 | glMaterialfv(GL_FRONT, GL_DIFFUSE, sphere_diffuse); |
| 124 | glutSolidSphere (1.0, 16, 16); |
| 125 | glPopMatrix (); |
| 126 | |
| 127 | glPushMatrix (); |
| 128 | glTranslatef (0.70, -0.90, 0.25); |
| 129 | glMaterialfv(GL_FRONT, GL_DIFFUSE, octa_diffuse); |
| 130 | glutSolidOctahedron (); |
| 131 | glPopMatrix (); |
| 132 | |
| 133 | glPopMatrix (); |
| 134 | } |
| 135 | |
| 136 | #define ACSIZE 8 |
| 137 | |
| 138 | UGL_LOCAL void drawGL(void) |
| 139 | { |
| 140 | GLint viewport[4]; |
| 141 | int jitter; |
| 142 | |
| 143 | glGetIntegerv (GL_VIEWPORT, viewport); |
| 144 | |
| 145 | glClear(GL_ACCUM_BUFFER_BIT); |
| 146 | for (jitter = 0; jitter < ACSIZE; jitter++) |
| 147 | { |
| 148 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 149 | glPushMatrix (); |
| 150 | /* Note that 4.5 is the distance in world space between |
| 151 | * left and right and bottom and top. |
| 152 | * This formula converts fractional pixel movement to |
| 153 | * world coordinates. |
| 154 | */ |
| 155 | glTranslatef (j8[jitter].x*4.5/viewport[2], |
| 156 | j8[jitter].y*4.5/viewport[3], 0.0); |
| 157 | displayObjects (); |
| 158 | glPopMatrix (); |
| 159 | glAccum(GL_ACCUM, 1.0/ACSIZE); |
| 160 | } |
| 161 | glAccum (GL_RETURN, 1.0); |
| 162 | glFlush(); |
| 163 | |
| 164 | uglMesaSwapBuffers(); |
| 165 | } |
| 166 | |
| 167 | UGL_LOCAL int getEvent(void) |
| 168 | { |
| 169 | UGL_EVENT event; |
| 170 | UGL_STATUS status; |
| 171 | int retVal = 0; |
| 172 | |
| 173 | status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); |
| 174 | |
| 175 | while (status != UGL_STATUS_Q_EMPTY) |
| 176 | { |
| 177 | UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event; |
| 178 | |
| 179 | if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) |
| 180 | retVal = 1; |
| 181 | |
| 182 | status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT); |
| 183 | } |
| 184 | |
| 185 | return(retVal); |
| 186 | } |
| 187 | |
Brian Paul | 3069330 | 2001-09-10 19:21:13 +0000 | [diff] [blame] | 188 | void windMLAccum (UGL_BOOL windMLMode); |
Brian Paul | 976c26c | 2001-08-20 16:07:10 +0000 | [diff] [blame] | 189 | |
| 190 | void uglaccum (void) |
| 191 | { |
| 192 | taskSpawn("tAccum", 210, VX_FP_TASK, 100000, |
Brian Paul | 3069330 | 2001-09-10 19:21:13 +0000 | [diff] [blame] | 193 | (FUNCPTR)windMLAccum,UGL_FALSE,1,2,3,4,5,6,7,8,9); |
Brian Paul | 976c26c | 2001-08-20 16:07:10 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Brian Paul | 3069330 | 2001-09-10 19:21:13 +0000 | [diff] [blame] | 196 | void windMLAccum (UGL_BOOL windMLMode) |
Brian Paul | 976c26c | 2001-08-20 16:07:10 +0000 | [diff] [blame] | 197 | { |
| 198 | UGL_INPUT_DEVICE_ID keyboardDevId; |
| 199 | GLsizei width, height; |
| 200 | |
| 201 | uglInitialize(); |
| 202 | |
| 203 | uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId); |
| 204 | |
| 205 | uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId); |
| 206 | |
| 207 | qId = uglEventQCreate (eventServiceId, 100); |
Brian Paul | 3069330 | 2001-09-10 19:21:13 +0000 | [diff] [blame] | 208 | |
| 209 | if (windMLMode) |
| 210 | umc = uglMesaCreateNewContextExt(UGL_MESA_DOUBLE |
| 211 | | UGL_MESA_WINDML_EXCLUSIVE, |
| 212 | 16, |
| 213 | 0, |
| 214 | 8,8,8,0, |
| 215 | NULL); |
| 216 | else |
| 217 | umc = uglMesaCreateNewContextExt(UGL_MESA_DOUBLE, |
| 218 | 16, |
| 219 | 0, |
| 220 | 8,8,8,0, |
| 221 | NULL); |
Brian Paul | 976c26c | 2001-08-20 16:07:10 +0000 | [diff] [blame] | 222 | |
Brian Paul | 976c26c | 2001-08-20 16:07:10 +0000 | [diff] [blame] | 223 | if (umc == NULL) |
| 224 | { |
| 225 | uglDeinitialize(); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | /* Fullscreen */ |
| 230 | |
| 231 | uglMesaMakeCurrentContext(umc, 0, 0, |
| 232 | UGL_MESA_FULLSCREEN_WIDTH, |
| 233 | UGL_MESA_FULLSCREEN_HEIGHT); |
| 234 | |
| 235 | uglMesaGetIntegerv(UGL_MESA_WIDTH, &width); |
| 236 | uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height); |
| 237 | |
| 238 | initGL(width, height); |
| 239 | |
Brian Paul | 3069330 | 2001-09-10 19:21:13 +0000 | [diff] [blame] | 240 | drawGL(); |
| 241 | |
| 242 | while (!getEvent()); |
Brian Paul | 976c26c | 2001-08-20 16:07:10 +0000 | [diff] [blame] | 243 | |
| 244 | uglEventQDestroy (eventServiceId, qId); |
| 245 | |
| 246 | uglMesaDestroyContext(); |
| 247 | uglDeinitialize(); |
| 248 | |
| 249 | return; |
| 250 | } |