Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.
Close
From: Peter J. Bismuti <pjb9508@va...>  20050113 20:14:49

In the Redbook example "double", how can I change the perspective? It doesn't seem to find the command glFrustrum. I tried gluPerspective and got a blank screen. I replaced the rectangle with a more general shape, giving it a z value of 0. glBegin(GL_POLYGON); for (i=0; i<numVerts; i++) { angle = ((float)i0.5)*2.0*3.14159/(float)numVerts; glVertex3f(sqrt(2.0)*25.0*cos(angle), sqrt(2.0)*25.0*sin(angle),0.0); } void reshape(int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(50.0, 50.0, 50.0, 50.0, 1.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } 
From: Peter J. Bismuti <pjb9508@va...>  20050113 20:54:50

I'm a little unclear how this creates animation (double.c from Redbook). I must not understand how the matrix stack is being used. It looks like you push something on, create a new top entry and then pop it off such that it is lost. Where does it pop to? void display(void) { glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glRotatef(spin, 0.0, 0.0, 1.0); glColor3f(1.0, 1.0, 1.0); glRectf(25.0, 25.0, 25.0, 25.0); glPopMatrix(); glutSwapBuffers(); } 
From: Daniel Sperka <djsperka@uc...>  20050114 00:21:15

The current "top" matrix on the stack is used to process any vertices that are sent through (as with glRectf). The rest of the stack can be ignored for the purposes of your example. IIRC the red book has a "robot" example which does a good job of illustrating the use of the stack. If you can recall any linear algebra, then you will find openGL rather intuitive after looking at it a while. When you push a matrix stack, you push the current matrix down and a new matrix becomes the top matrix. I would think that this new matrix defaults to the identity, but most examples always issue these commands together: glPushMatrix() glLoadIdentity() When you "pop" a stack, the top matrix is simply discarded and the stack below it becomes the "top" matrix. In your example, there is no glLoadIdentity  this may be a problem or not. Anyways, glRotatef generates a rotation matrix and multiplies it by what is currently on the top of the stack. I think of this as a r.h. operation: (StackTop) x (rotation) = new StackTop The resulting matrix becomes the matrix at the top of the stack. Subsequent vertices from the glRectf are all rotated by 'spin'. If your example is advancing the value of 'spin' somewhere else (the idle callback?), then the effect is that your rectangle spins. If your example is NOT advancing the value of 'spin', then your rect probably just sits there, rotated at 'spin' forever. Dan 
From: Brian Paul <brian.paul@tu...>  20050114 14:45:01

Peter J. Bismuti wrote: > In the Redbook example "double", how can I change the perspective? It > doesn't seem to find the command glFrustrum. I tried gluPerspective and > got a blank screen. > > I replaced the rectangle with a more general shape, giving it a z value > of 0. > > > glBegin(GL_POLYGON); > for (i=0; i<numVerts; i++) > { > angle = ((float)i0.5)*2.0*3.14159/(float)numVerts; > glVertex3f(sqrt(2.0)*25.0*cos(angle), > sqrt(2.0)*25.0*sin(angle),0.0); > } I don't see a glEnd() call. > void reshape(int w, int h) > { > glViewport (0, 0, (GLsizei) w, (GLsizei) h); > glMatrixMode(GL_PROJECTION); > glLoadIdentity(); > glOrtho(50.0, 50.0, 50.0, 50.0, 1.0, 1.0); > glMatrixMode(GL_MODELVIEW); > glLoadIdentity(); > } Something like this should work. Many of the Mesa demos have code like this: void reshape(int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(1, 1, 1, 1, 2, 20); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, 10); } Brian 