Doxygen Source Code Documentation
SUMA_glxdino.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <GL/gl.h>
#include <GL/glx.h>
#include <GL/glu.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xmu/StdCmap.h>
#include <X11/keysym.h>
Go to the source code of this file.
Defines | |
#define | CAST_GLU_FUNCPTR (_GLUfuncptr) |
Enumerations | |
enum | displayLists { RESERVED, BODY_SIDE, BODY_EDGE, BODY_WHOLE, ARM_SIDE, ARM_EDGE, ARM_WHOLE, LEG_SIDE, LEG_EDGE, LEG_WHOLE, EYE_SIDE, EYE_EDGE, EYE_WHOLE, DINOSAUR } |
Functions | |
void | extrudeSolidFromPolygon (GLfloat data[][2], unsigned int dataSize, GLdouble thickness, GLuint side, GLuint edge, GLuint whole) |
void | redraw (void) |
void | makeDinosaur (void) |
void | contextInit (void) |
void | fatalError (char *message) |
Colormap | getShareableColormap (XVisualInfo *vi) |
int | main (int argc, char **argv) |
Variables | |
Display * | dpy |
Window | win |
GLfloat | angle = -150 |
Bool | doubleBuffer = True |
Bool | iconic = False |
Bool | keepAspect = False |
int | W = 300 |
int | H = 300 |
XSizeHints | sizeHints = {0} |
GLdouble | bodyWidth = 2.0 |
int | configuration [] |
GLfloat | body [][2] |
GLfloat | arm [][2] |
GLfloat | leg [][2] |
GLfloat | eye [][2] |
GLfloat | skinColor [] = {0.1, 1.0, 0.1, 1.0} |
GLfloat | eyeColor [] = {1.0, 0.2, 0.2, 1.0} |
GLfloat | lightZeroPosition [] = {10.0, 4.0, 10.0, 1.0} |
GLfloat | lightZeroColor [] = {0.8, 1.0, 0.8, 1.0} |
GLfloat | lightOnePosition [] = {-1.0, -2.0, 1.0, 0.0} |
GLfloat | lightOneColor [] = {0.6, 0.3, 0.2, 1.0} |
Define Documentation
|
Definition at line 136 of file SUMA_glxdino.c. Referenced by extrudeSolidFromPolygon(). |
Enumeration Type Documentation
|
Definition at line 37 of file SUMA_glxdino.c.
|
Function Documentation
|
Definition at line 209 of file SUMA_glxdino.c. References angle, bodyWidth, lightOneColor, lightOnePosition, lightZeroColor, and lightZeroPosition. Referenced by main().
00210 { 00211 glEnable(GL_CULL_FACE); /* Up to 50% better perfomance than no 00212 back-face culling. */ 00213 glEnable(GL_DEPTH_TEST); /* Enable depth buffering. */ 00214 00215 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); 00216 glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition); 00217 glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor); 00218 glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1); 00219 glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05); 00220 glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition); 00221 glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor); 00222 00223 /* Enable both lights. */ 00224 glEnable(GL_LIGHT0); 00225 glEnable(GL_LIGHT1); 00226 glEnable(GL_LIGHTING); 00227 00228 /* Set up projection transform. */ 00229 glMatrixMode(GL_PROJECTION); 00230 gluPerspective( 00231 40.0, /* Field of view in degree */ 00232 1.0, /* Aspect ratio */ 00233 1.0, /* Z near */ 00234 40.0); /* Z far */ 00235 00236 /* Now, change to modelview. */ 00237 glMatrixMode(GL_MODELVIEW); 00238 gluLookAt( 00239 0.0, 0.0, 30.0, /* Eye is at (0,0,30) */ 00240 0.0, 0.0, 0.0, /* Center is at (0,0,0) */ 00241 0.0, 1.0, 0.); /* Up is in positive Y direction */ 00242 glPushMatrix(); /* Dummy push so we can pop on model 00243 recalc. */ 00244 } |
|
Definition at line 142 of file SUMA_glxdino.c. References CAST_GLU_FUNCPTR, and i. Referenced by makeDinosaur().
00144 { 00145 static GLUtriangulatorObj *tobj = NULL; 00146 GLdouble vertex[3], dx, dy, len; 00147 int i; 00148 int count = dataSize / (2 * sizeof(GLfloat)); 00149 00150 if (tobj == NULL) { 00151 tobj = gluNewTess(); /* create and initialize a GLU 00152 polygon tessellation object */ 00153 /* cast 3rd args as _GLUfuncptr for some machines 02 Aug 2004 [rickr] */ 00154 gluTessCallback(tobj, GLU_BEGIN, CAST_GLU_FUNCPTR glBegin); 00155 gluTessCallback(tobj, GLU_VERTEX, CAST_GLU_FUNCPTR glVertex2fv);/* tricky */ 00156 gluTessCallback(tobj, GLU_END, CAST_GLU_FUNCPTR glEnd); 00157 } 00158 glNewList(side, GL_COMPILE); 00159 glShadeModel(GL_SMOOTH); /* smooth minimizes seeing 00160 tessellation */ 00161 gluBeginPolygon(tobj); 00162 for (i = 0; i < count; i++) { 00163 vertex[0] = data[i][0]; 00164 vertex[1] = data[i][1]; 00165 vertex[2] = 0; 00166 gluTessVertex(tobj, vertex, &data[i]); 00167 } 00168 gluEndPolygon(tobj); 00169 glEndList(); 00170 glNewList(edge, GL_COMPILE); 00171 glShadeModel(GL_FLAT); /* flat shade keeps angular hands 00172 from being "smoothed" */ 00173 glBegin(GL_QUAD_STRIP); 00174 for (i = 0; i <= count; i++) { 00175 /* mod function handles closing the edge */ 00176 glVertex3f(data[i % count][0], data[i % count][1], 0.0); 00177 glVertex3f(data[i % count][0], data[i % count][1], thickness); 00178 /* Calculate a unit normal by dividing by Euclidean 00179 distance. We could be lazy and use glEnable(GL_NORMALIZE) 00180 so we could pass in arbitrary normals for a very slight 00181 performance hit. */ 00182 dx = data[(i + 1) % count][1] - data[i % count][1]; 00183 dy = data[i % count][0] - data[(i + 1) % count][0]; 00184 len = sqrt(dx * dx + dy * dy); 00185 glNormal3f(dx / len, dy / len, 0.0); 00186 } 00187 glEnd(); 00188 glEndList(); 00189 glNewList(whole, GL_COMPILE); 00190 glFrontFace(GL_CW); 00191 glCallList(edge); 00192 glNormal3f(0.0, 0.0, -1.0); /* constant normal for side */ 00193 glCallList(side); 00194 glPushMatrix(); 00195 glTranslatef(0.0, 0.0, thickness); 00196 glFrontFace(GL_CCW); 00197 glNormal3f(0.0, 0.0, 1.0); /* reverse normal for other side */ 00198 glCallList(side); 00199 glPopMatrix(); 00200 glEndList(); 00201 } |
|
Definition at line 49 of file SUMA_glxdino.c.
00050 {
00051 fprintf(stderr, "glxdino: %s\n", message);
00052 exit(1);
00053 }
|
|
Definition at line 56 of file SUMA_glxdino.c. References cmap, dpy, fatalError(), and i. Referenced by main().
00057 { 00058 Status status; 00059 XStandardColormap *standardCmaps; 00060 Colormap cmap; 00061 int i, numCmaps; 00062 00063 /* be lazy; using DirectColor too involved for this example */ 00064 if (vi->class != TrueColor) 00065 fatalError("No support for non-TrueColor visual."); 00066 /* if no standard colormap but TrueColor, just make an 00067 unshared one */ 00068 status = XmuLookupStandardColormap(dpy, vi->screen, vi->visualid, 00069 vi->depth, XA_RGB_DEFAULT_MAP, /* replace */ False, /* retain */ True); 00070 if (status == 1) { 00071 status = XGetRGBColormaps(dpy, RootWindow(dpy, vi->screen), 00072 &standardCmaps, &numCmaps, XA_RGB_DEFAULT_MAP); 00073 if (status == 1) 00074 for (i = 0; i < numCmaps; i++) 00075 if (standardCmaps[i].visualid == vi->visualid) { 00076 cmap = standardCmaps[i].colormap; 00077 XFree(standardCmaps); 00078 return cmap; 00079 } 00080 } 00081 cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), 00082 vi->visual, AllocNone); 00083 return cmap; 00084 } |
|
Definition at line 247 of file SUMA_glxdino.c. References angle, argc, bodyWidth, Bool, cmap, configuration, contextInit(), display, doubleBuffer, dpy, event, fatalError(), flags, getShareableColormap(), H, i, iconic, keepAspect, makeDinosaur(), redraw(), sizeHints, W, and win.
00248 { 00249 XVisualInfo *vi; 00250 Colormap cmap; 00251 XSetWindowAttributes swa; 00252 XWMHints *wmHints; 00253 Atom wmDeleteWindow; 00254 GLXContext cx; 00255 XEvent event; 00256 KeySym ks; 00257 Bool needRedraw = False, recalcModelView = True; 00258 char *display = NULL, *geometry = NULL; 00259 int flags, x, y, width, height, lastX = 0, i; 00260 00261 for (i = 1; i < argc; i++) { 00262 if (!strcmp(argv[i], "-geometry")) { 00263 if (++i >= argc) 00264 fatalError("follow -geometry option with geometry parameter"); 00265 geometry = argv[i]; 00266 } else if (!strcmp(argv[i], "-display")) { 00267 if (++i >= argc) 00268 fatalError("follow -display option with display parameter"); 00269 display = argv[i]; 00270 } else if (!strcmp(argv[i], "-iconic")) 00271 iconic = True; 00272 else if (!strcmp(argv[i], "-keepaspect")) 00273 keepAspect = True; 00274 else if (!strcmp(argv[i], "-single")) 00275 doubleBuffer = False; 00276 else 00277 fatalError("bad option"); 00278 } 00279 00280 dpy = XOpenDisplay(display); 00281 if (dpy == NULL) 00282 fatalError("could not open display"); 00283 00284 if (!glXQueryExtension(dpy, NULL, NULL)) 00285 fatalError("X server has no OpenGL GLX extension"); 00286 00287 /* Find an OpenGL-capable RGB visual with depth buffer. */ 00288 if (!doubleBuffer) 00289 goto SingleBufferOverride; 00290 vi = glXChooseVisual(dpy, DefaultScreen(dpy), configuration); 00291 if (vi == NULL) { 00292 SingleBufferOverride: 00293 vi = glXChooseVisual(dpy, DefaultScreen(dpy), &configuration[1]); 00294 if (vi == NULL) 00295 fatalError("no appropriate RGB visual with depth buffer"); 00296 doubleBuffer = False; 00297 } 00298 cmap = getShareableColormap(vi); 00299 00300 /* Create an OpenGL rendering context. */ 00301 cx = glXCreateContext(dpy, vi, 00302 /* No sharing of display lists */ NULL, 00303 /* Direct rendering if possible */ True); 00304 if (cx == NULL) 00305 fatalError("could not create rendering context"); 00306 00307 flags = XParseGeometry(geometry, &x, &y, 00308 (unsigned int *) &width, (unsigned int *) &height); 00309 if (WidthValue & flags) { 00310 sizeHints.flags |= USSize; 00311 sizeHints.width = width; 00312 W = width; 00313 } 00314 if (HeightValue & flags) { 00315 sizeHints.flags |= USSize; 00316 sizeHints.height = height; 00317 H = height; 00318 } 00319 if (XValue & flags) { 00320 if (XNegative & flags) 00321 x = DisplayWidth(dpy, DefaultScreen(dpy)) + x - sizeHints.width; 00322 sizeHints.flags |= USPosition; 00323 sizeHints.x = x; 00324 } 00325 if (YValue & flags) { 00326 if (YNegative & flags) 00327 y = DisplayHeight(dpy, DefaultScreen(dpy)) + y - sizeHints.height; 00328 sizeHints.flags |= USPosition; 00329 sizeHints.y = y; 00330 } 00331 if (keepAspect) { 00332 sizeHints.flags |= PAspect; 00333 sizeHints.min_aspect.x = sizeHints.max_aspect.x = W; 00334 sizeHints.min_aspect.y = sizeHints.max_aspect.y = H; 00335 } 00336 swa.colormap = cmap; 00337 swa.border_pixel = 0; 00338 swa.event_mask = ExposureMask | StructureNotifyMask | 00339 ButtonPressMask | Button1MotionMask | KeyPressMask; 00340 win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 00341 sizeHints.x, sizeHints.y, W, H, 00342 0, vi->depth, InputOutput, vi->visual, 00343 CWBorderPixel | CWColormap | CWEventMask, &swa); 00344 XSetStandardProperties(dpy, win, "OpenGLosaurus", "glxdino", 00345 None, argv, argc, &sizeHints); 00346 wmHints = XAllocWMHints(); 00347 wmHints->initial_state = iconic ? IconicState : NormalState; 00348 wmHints->flags = StateHint; 00349 XSetWMHints(dpy, win, wmHints); 00350 wmDeleteWindow = XInternAtom(dpy, "WM_DELETE_WINDOW", False); 00351 XSetWMProtocols(dpy, win, &wmDeleteWindow, 1); 00352 glXMakeCurrent(dpy, win, cx); 00353 makeDinosaur(); 00354 contextInit(); 00355 XMapWindow(dpy, win); 00356 for (;;) { 00357 do { 00358 XNextEvent(dpy, &event); 00359 switch (event.type) { 00360 case ConfigureNotify: 00361 glViewport(0, 0, 00362 event.xconfigure.width, event.xconfigure.height); 00363 /* fall through... */ 00364 case Expose: 00365 needRedraw = True; 00366 break; 00367 case MotionNotify: 00368 recalcModelView = True; 00369 angle -= (lastX - event.xmotion.x); 00370 case ButtonPress: 00371 lastX = event.xbutton.x; 00372 break; 00373 case KeyPress: 00374 ks = XLookupKeysym((XKeyEvent *) & event, 0); 00375 if (ks == XK_Escape) 00376 exit(0); 00377 break; 00378 case ClientMessage: 00379 if (event.xclient.data.l[0] == wmDeleteWindow) 00380 exit(0); 00381 break; 00382 } 00383 } while (XPending(dpy)); /* Loop to compress events. */ 00384 if (recalcModelView) { 00385 glPopMatrix(); /* Pop old rotated matrix (or dummy 00386 matrix if first time). */ 00387 glPushMatrix(); 00388 glRotatef(angle, 0.0, 1.0, 0.0); 00389 glTranslatef(-8, -8, -bodyWidth / 2); 00390 recalcModelView = False; 00391 needRedraw = True; 00392 } 00393 if (needRedraw) { 00394 redraw(); 00395 needRedraw = False; 00396 } 00397 } 00398 } |
|
Definition at line 103 of file SUMA_glxdino.c. References arm, ARM_EDGE, ARM_SIDE, ARM_WHOLE, body, BODY_EDGE, BODY_SIDE, BODY_WHOLE, bodyWidth, DINOSAUR, extrudeSolidFromPolygon(), eye, EYE_EDGE, EYE_SIDE, EYE_WHOLE, eyeColor, leg, LEG_EDGE, LEG_SIDE, LEG_WHOLE, and skinColor. Referenced by main().
00104 { 00105 GLfloat bodyWidth = 3.0; 00106 00107 extrudeSolidFromPolygon(body, sizeof(body), bodyWidth, 00108 BODY_SIDE, BODY_EDGE, BODY_WHOLE); 00109 extrudeSolidFromPolygon(arm, sizeof(arm), bodyWidth / 4, 00110 ARM_SIDE, ARM_EDGE, ARM_WHOLE); 00111 extrudeSolidFromPolygon(leg, sizeof(leg), bodyWidth / 2, 00112 LEG_SIDE, LEG_EDGE, LEG_WHOLE); 00113 extrudeSolidFromPolygon(eye, sizeof(eye), bodyWidth + 0.2, 00114 EYE_SIDE, EYE_EDGE, EYE_WHOLE); 00115 glNewList(DINOSAUR, GL_COMPILE); 00116 glMaterialfv(GL_FRONT, GL_DIFFUSE, skinColor); 00117 glCallList(BODY_WHOLE); 00118 glPushMatrix(); 00119 glTranslatef(0.0, 0.0, bodyWidth); 00120 glCallList(ARM_WHOLE); 00121 glCallList(LEG_WHOLE); 00122 glTranslatef(0.0, 0.0, -bodyWidth - bodyWidth / 4); 00123 glCallList(ARM_WHOLE); 00124 glTranslatef(0.0, 0.0, -bodyWidth / 4); 00125 glCallList(LEG_WHOLE); 00126 glTranslatef(0.0, 0.0, bodyWidth / 2 - 0.1); 00127 glMaterialfv(GL_FRONT, GL_DIFFUSE, eyeColor); 00128 glCallList(EYE_WHOLE); 00129 glPopMatrix(); 00130 glEndList(); 00131 } |
|
Definition at line 401 of file SUMA_glxdino.c. References DINOSAUR, dpy, and win. Referenced by main().
|
Variable Documentation
|
Definition at line 29 of file SUMA_glxdino.c. Referenced by main(). |
|
Initial value: { {8, 10}, {9, 9}, {10, 9}, {13, 8}, {14, 9}, {16, 9}, {15, 9.5}, {16, 10}, {15, 10}, {15.5, 11}, {14.5, 10}, {14, 11}, {14, 10}, {13, 9}, {11, 11}, {9, 11} } Definition at line 92 of file SUMA_glxdino.c. Referenced by makeDinosaur(). |
|
Initial value: { {0, 3}, {1, 1}, {5, 1}, {8, 4}, {10, 4}, {11, 5}, {11, 11.5}, {13, 12}, {13, 13}, {10, 13.5}, {13, 14}, {13, 15}, {11, 16}, {8, 16}, {7, 15}, {7, 13}, {8, 12}, {7, 11}, {6, 6}, {4, 3}, {3, 2}, {1, 2} } Definition at line 88 of file SUMA_glxdino.c. Referenced by makeDinosaur(). |
|
Definition at line 33 of file SUMA_glxdino.c. Referenced by main(), and makeDinosaur(). |
|
Initial value: {GLX_DOUBLEBUFFER, GLX_RGBA, GLX_DEPTH_SIZE, 12, GLX_RED_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_GREEN_SIZE, 1, None} Definition at line 34 of file SUMA_glxdino.c. Referenced by main(), and SUMA_RenderToPixMap(). |
|
Definition at line 30 of file SUMA_glxdino.c. Referenced by main(). |
|
|
Initial value: { {8.75, 15}, {9, 14.7}, {9.6, 14.7}, {10.1, 15}, {9.6, 15.25}, {9, 15.25} } Definition at line 97 of file SUMA_glxdino.c. Referenced by makeDinosaur(). |
|
Definition at line 100 of file SUMA_glxdino.c. Referenced by makeDinosaur(). |
|
Definition at line 31 of file SUMA_glxdino.c. Referenced by main(). |
|
Definition at line 30 of file SUMA_glxdino.c. Referenced by main(). |
|
Definition at line 30 of file SUMA_glxdino.c. Referenced by main(). |
|
Initial value: { {8, 6}, {8, 4}, {9, 3}, {9, 2}, {8, 1}, {8, 0.5}, {9, 0}, {12, 0}, {10, 1}, {10, 2}, {12, 4}, {11, 6}, {10, 7}, {9, 7} } Definition at line 95 of file SUMA_glxdino.c. Referenced by makeDinosaur(). |
|
Definition at line 206 of file SUMA_glxdino.c. Referenced by contextInit(). |
|
Definition at line 205 of file SUMA_glxdino.c. Referenced by contextInit(). |
|
Definition at line 204 of file SUMA_glxdino.c. Referenced by contextInit(). |
|
Definition at line 203 of file SUMA_glxdino.c. Referenced by contextInit(). |
|
Definition at line 32 of file SUMA_glxdino.c. Referenced by main(). |
|
Definition at line 99 of file SUMA_glxdino.c. Referenced by makeDinosaur(). |
|
Definition at line 31 of file SUMA_glxdino.c. Referenced by main(). |
|