Hello, I’m trying to transform quads : first one should rotate, second one should move. I am completely stuck with this one: either both quads are rotating and moving at once, either transformation terminates.
my code:
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
int x;
int y;
void basicInt(void)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClearColor(0,0,0,0);
gluOrtho2D(0,950,0,600);
}
void drawQ(int x, int y)
{
glColor3f(1,1,0);
glBegin(GL_QUADS);
glVertex2d( x, y );
glColor3f(1,1,1);
glVertex2d( x, y+75 );
glVertex2d( x+50, y+75 );
glVertex2d(x+50, y );
glEnd( );
}
void refresh(int count)
{
glutPostRedisplay();
}
void myView(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glRotated(1,0,0,1);
drawQ(400, 200); //first quad should rotate
glPopMatrix();
glPushMatrix();
glTranslated(1,1,0);
drawQ(600, 200); //second quad should change its position
glPopMatrix();
glutSwapBuffers();
glutTimerFunc(33,refresh,1);
}
int main(int argc,char* argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(950,600);
glutInitWindowPosition(100,100);
glutCreateWindow("Test");
basicInt();
glutDisplayFunc(myView);
glutMainLoop();
}
I assume something is not right with glPushMatrix/glPopMatrix
please help!