10 #include <X11/keysym.h>
12 #include <X11/Xutil.h>
20 static int attributes[] = {GLX_RGBA, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8, GLX_DEPTH_SIZE, 1, 0};
22 #define SWAPBUFFERS glXSwapBuffers(dpy, glwin)
39 GLvoid
resize(GLsizei, GLsizei);
42 void polarView( GLdouble, GLdouble, GLdouble, GLdouble);
46 if ((e->type == MapNotify) && (e->xmap.window == (Window)arg)) {
57 XSetWindowAttributes swa;
60 GLboolean needRedraw = GL_FALSE, recalcModelView = GL_TRUE;
65 fprintf(stderr,
"could not open display\n");
69 if(!glXQueryExtension(
dpy, &dummy, &dummy)){
70 fprintf(stderr,
"could not open display");
77 fprintf(stderr,
"could not get visual\n");
82 cx = glXCreateContext(
dpy, vi, None, GL_TRUE);
84 fprintf(stderr,
"could not create rendering context\n");
89 #ifndef OFFLINE_RENDERING
91 vi->visual, AllocNone);
94 swa.event_mask = ExposureMask | KeyPressMask | StructureNotifyMask;
96 HEIGHT, 0, vi->depth, InputOutput, vi->visual,
97 CWBorderPixel | CWColormap | CWEventMask, &swa);
105 #ifndef OFFLINE_RENDERING
119 switch (event.type) {
137 case ConfigureNotify:
138 resize(event.xconfigure.width, event.xconfigure.height);
148 GLvoid
resize( GLsizei width, GLsizei height )
152 glViewport( 0, 0, width, height );
154 aspect = (GLfloat) width / height;
156 glMatrixMode( GL_PROJECTION );
158 gluPerspective( 45.0, aspect, 3.0, 7.0 );
159 glMatrixMode( GL_MODELVIEW );
164 GLUquadricObj *quadObj;
166 glNewList(
GLOBE, GL_COMPILE);
167 quadObj = gluNewQuadric ();
168 gluQuadricDrawStyle (quadObj, GLU_LINE);
169 gluSphere (quadObj, 1.5, 16, 16);
172 glNewList(
CONE, GL_COMPILE);
173 quadObj = gluNewQuadric ();
174 gluQuadricDrawStyle (quadObj, GLU_FILL);
175 gluQuadricNormals (quadObj, GLU_SMOOTH);
176 gluCylinder(quadObj, 0.3, 0.0, 0.6, 15, 10);
181 glRotatef ((GLfloat)90.0, (GLfloat)1.0, (GLfloat)0.0, (GLfloat)0.0);
182 glTranslatef ((GLfloat)0.0, (GLfloat)0.0, (GLfloat)-1.0);
183 quadObj = gluNewQuadric ();
184 gluQuadricDrawStyle (quadObj, GLU_FILL);
185 gluQuadricNormals (quadObj, GLU_SMOOTH);
186 gluCylinder (quadObj, 0.3, 0.3, 0.6, 12, 2);
193 GLfloat maxObjectSize, aspect;
194 GLdouble near_plane, far_plane;
199 glEnable(GL_DEPTH_TEST);
201 glMatrixMode( GL_PROJECTION );
202 aspect = (GLfloat) width / height;
203 gluPerspective( 45.0, aspect, 3.0, 7.0 );
204 glMatrixMode( GL_MODELVIEW );
208 maxObjectSize = 3.0F;
209 radius = near_plane + maxObjectSize/2.0;
222 glTranslated(0.0, 0.0, -
radius);
223 glRotated(-twist, 0.0, 0.0, 1.0);
224 glRotated(-
latitude, 1.0, 0.0, 0.0);
231 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
249 glTranslatef(0.8F, -0.65F, 0.0F);
250 glRotatef(30.0F, 1.0F, 0.5F, 1.0F);
256 #ifdef OFFLINE_RENDERING
260 glReadBuffer(GL_FRONT);
261 glPixelStorei(GL_PACK_ALIGNMENT, 1);
262 glReadPixels(0, 0,
WIDTH,
HEIGHT, GL_RGB, GL_UNSIGNED_BYTE, imgbuf);
265 sprintf(filename,
"test%08d.ppm", i++);
268 FILE *fp = fopen(filename,
"w+");