简体   繁体   中英

OpenGL translation

I'm having some problems translating an object I'm drawing. This is the entirety of my display function. I can't seem to find anything I'm doing wrong.

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 720, 480, 0, -1.0, 1.0);
glTranslatef(-0.5f,0.0f,0.0f);

//drawing object here

glPopMatrix();
glutSwapBuffers();

You need to start modifying the modelview matrix stack after you've done glOrtho :

// ...
glOrtho(0, 720, 480, 0, -1.0, 1.0);

glMatrixMode(GL_MODELVIEW);
glTranslatef(-0.5f,0.0f,0.0f);
// ...

But now your glPushMatrix and glPopMatrix are modifying different stacks, so the glPopMatrix will result in an error. You shouldn't need them for such a simple example anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM