I am learning openGL and I am writing an application that draws a 2D triangle and rotates it around its z-axis depending on its position. Its middle (t1.tx, t1.ty) is constantly being changed when the triangle is dragged with the mouse. The problem is that when I drag the triangle to another location, instead of staying where its at and rotating, it rotates in a circle path around its center point. Can someone look over this code and see what I am doing wrong.. I want it to rotate in its position.
void drawTriangle() {
glBegin(GL_POLYGON);
glColor3f((float)200/255, (float)200/255, (float)200/255);
glVertex2f(t1.tx, t1.ty + .2); // top point of triangle
glVertex2f(t1.tx - .2, t1.ty - .2); // left point
glVertex2f(t1.tx + .2, t1.ty - .2); // right point
glEnd();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glTranslatef(t1.tx, t1.ty, 0); // move matrix to triangle's current center point
glRotatef(theta, 0, 0, 1.0); // rotate on z-axis
drawTriangle();
glPopMatrix();
glutPostRedisplay();
glutSwapBuffers();
}