Archived

This topic is now archived and is closed to further replies.

th032

Can you tell me why this doesn't work???

Recommended Posts

th032    122
I try to draw buttons on the window in Ortho projection, and then draw an object on the window in Perspective projection But after popping both matrices(which I pushed), only the buttons are drawn and the object isn''t. =============================================================== glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); /* Set camera */ gluLookAt(0.0, 0.0, d, 0.0, 0.0, q, 0.0, 1.0, 0.0); glTranslatef(0.0f,0.0f, q); glPushMatrix(); /* Push Modelview Matrix */ glMatrixMode(GL_PROJECTION); glPushMatrix(); /* Push Projection Matrix */ glLoadIdentity(); gluOrtho2D(0, winWidth, 0, winHeight); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* Draw buttons */ for (ctr = 0; ctr < numButtons; ctr++) glButton(&button[ctr]); glPopMatrix(); /* Pop Projection Matrix */ glPopMatrix(); /* Pop Modelview Matrix */ glMatrixMode(GL_MODELVIEW); glObject(); /* Draw object */ AMD Tbird 1GHz 266FSB, ASUS A7V133, Crucial 256MB PC133 SDRAM, PlexWriter 12X/10X/32X CD-RW, Voodoo3 2000 PCI, Creative SoundBlaster Live!, Maxtor 7200rpm 13.3GB, IBM 5200rpm 3.2GB, Samsung 955DF 19" Monitor, LinkSys USB100TX Ethernet Network Adapter, Rogers@Home, Win2000/Linux Mandrake 8.0

Share this post


Link to post
Share on other sites
GKW    200
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

/* Draw buttons */
for (ctr = 0; ctr < numButtons; ctr++) glButton(&button[ctr]);
glPopMatrix(); /* Pop Projection Matrix */
glPopMatrix(); /* Pop Modelview Matrix */

glMatrixMode(GL_MODELVIEW);
glObject(); /* Draw object */


You are actually popping the modelview matrix twice with the two pop calls. You need to put a glMatrixMode(GL_PROJECTION) call in between them. Shoudl oook like the following:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

/* Draw buttons */
for (ctr = 0; ctr < numButtons; ctr++) glButton(&button[ctr]);

glMatrixMode( GL_PROJECTION );
glPopMatrix(); /* Pop Projection Matrix */

glMatrixMode(GL_MODELVIEW);
glPopMatrix(); /* Pop Modelview Matrix */
glObject(); /* Draw object */


The fanatic is incorruptible: if he kills for an idea, he can just as well get himself killed for one; in either case, tyrant or martyr, he is a monster.
--EM Cioran

Opere Citato

Share this post


Link to post
Share on other sites
Eber Kain    130
read this

"You can control which matrix is on top with the commands that perform stack operations: glPushMatrix(),
which copies the current matrix and adds the copy to the top of the stack, and glPopMatrix(), which
discards the top matrix on the stack"

''on the stack'' as in each matrix mode has a different stack.

Share this post


Link to post
Share on other sites
th032    122
Thanks, it works now
....Tom

AMD Tbird 1GHz 266FSB, ASUS A7V133, Crucial 256MB PC133 SDRAM, PlexWriter 12X/10X/32X CD-RW, Voodoo3 2000 PCI, Creative SoundBlaster Live!, Maxtor 7200rpm 13.3GB, IBM 5200rpm 3.2GB, Samsung 955DF 19" Monitor, LinkSys USB100TX Ethernet Network Adapter,
Rogers@Home, Win2000/Linux Mandrake 8.0

Share this post


Link to post
Share on other sites