i am trying to rotate a quad at z-axis but the problem is , it is not rotating but translating towards some other direction rather than rotating at a particular point.I believe my display function is correct, and the problem exist in init() function and is related to modelView or projection matrix, i downt know the purpose of them and what will be the sequence, here is my code
#include<GL\freeglut.h>
#include<Windows.h>
#include <math.h>
#include"F:\BSCS VI\cg\cg\SOIL.h"
double moveX = 0.0;
double x = 0, b = 0;
int degree = 0;
void display() {
glEnable(GL_TEXTURE_2D);
glClear(GL_COLOR_BUFFER_BIT);
//////////////quad to be rotated
glPushMatrix();
glRotatef(degree, 0.0f, 0.0f, 1.0f);
glColor3f(0, 0, 0);
glBegin(GL_QUADS);
glVertex2d(30, 300);
glVertex2d(100, 300);
glVertex2d(100, 320);
glVertex2d(30, 320);
glEnd();
glPopMatrix();
////////////////quad to be rotated , end
degree++;
glFlush();
}
void init(void) {
glClearColor(.75, .75, .75, 0.0); /* background color select clearing color */
//glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 500, 0, 500);
}
void timer(int x){
glutTimerFunc(100, timer, x);
glutPostRedisplay();
}
int main(int argc, char * argv[]) {
glutInit(&argc, argv);
glutInitWindowPosition(100, 100); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800, 500);
glutCreateWindow("simple"); // default win. 300 x 300
glutTimerFunc(100, timer, x);
init();
glutDisplayFunc(display); // set callback for display function
glutMainLoop();
return 0;
}