I’m having a problem moving an specific object in OpenGL using C.
Object CODE
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1, 0.73, 0.06);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glRotatef(0,PacX,PacY,0);
glBegin(GL_QUADS);
glVertex2f(ax, ay);
glVertex2f(bx, by);
glVertex2f(cx, cy);
glVertex2f(dx, dy);
glEnd();
glPopMatrix();
glFlush();
This will draw a square, but in the window i have other objects, so when i try to move only the square with glTranslatef() it moves all the objects, is there a way or variable where i can store a pointer or an ID to the square so i can move only the square ?
You need to save and restore the transformation matrix for each object, so that each object gets its own matrix.
See the
glPushMatrix()function.