How can I make this thing not move when I redisplay it?

Started by
2 comments, last by thyrgle 13 years, 1 month ago
I need to redisplay my OpenGL draw function which is as follows:

void drawMolecule() {
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
glOrtho (0, 400, 400, 0, 0, 1);
glMatrixMode (GL_MODELVIEW);

glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
for (int i = 0; i < 100; i++)
{
getColor(grid);
getTransform(grid);
glBegin(GL_QUADS);
glVertex2i(0, 0);
glVertex2i(20, 0);
glVertex2i(20, 20);
glVertex2i(0, 20);
glEnd();
}
glutSwapBuffers();
}


But, when I do so, everything gets shifted down when I call glutPostRedisplay in another function... How can I stop it from shifting down? I am calling the translations in the getTransform function which is defined as follows:


void getTransform(point x) {
glTranslatef(21, 0, 0.0);
if (counter % 10 == 0 && counter >= 10) {
glTranslatef(0, 21, 0);
glTranslatef(-210, 0, 0);
}
counter++;
}


Any help would be appreciated.
Advertisement
Add another glLoadIdentity after glMatrixMode (GL_MODELVIEW)
@Erik:

I have tried what you suggest. But, I am still getting a translation.

Before redisplay:
[attachment=1628:Screen shot 2011-03-12 at 9.29.35 PM.png]

After redisplay:
[attachment=1629:Screen shot 2011-03-12 at 9.29.47 PM.png]
Figured it out, did not reset counter variable...

This topic is closed to new replies.

Advertisement