Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/freeglut.h>
- int lastTime;
- int delta;
- float rotator = 0.0f;
- void ReSizeGLScene(int width, int height) // Resize And Initialize The GL Window
- {
- if (height == 0) // Prevent A Divide By Zero By
- {
- height = 1; // Making Height Equal One
- }
- glViewport(0, 0, width, height); // Reset The Current Viewport
- glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
- glLoadIdentity(); // Reset The Projection Matrix
- // Calculate The Aspect Ratio Of The Window
- gluPerspective(45.0f, (GLfloat) width / (GLfloat) height, 0.1f, 100.0f);
- glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
- glLoadIdentity(); // Reset The Modelview Matrix
- }
- void renderScene(void)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glPushMatrix();
- glTranslatef(0, 0, -3);
- glRotatef(rotator, 0, 1, 0);
- glRotatef(rotator / 4, 0, 0, 1);
- glBegin(GL_TRIANGLES);
- glColor3f(0, 1, 0);
- glVertex3f(-.5, -.5, -.5);
- glVertex3f(.5, .5, -.5);
- glVertex3f(-.5, .5, -.5);
- glColor3f(1, 0, 0);
- glVertex3f(.5, -.5, -.5);
- glVertex3f(.5, .5, .5);
- glVertex3f(.5, -.5, .5);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(1, 1, 0);
- glVertex3f(.5, -.5, .5);
- glVertex3f(.5, -.5, -.5);
- glVertex3f(-.5, -.5, -.5);
- glVertex3f(-.5, -.5, .5);
- glEnd();
- glPopMatrix();
- rotator = rotator + delta / 10.0f;
- glutSwapBuffers();
- glFlush();
- }
- void onIdle()
- {
- int time;
- time = glutGet(GLUT_ELAPSED_TIME);
- delta = time - lastTime;
- lastTime = time;
- //Sleep(50);
- glutPostRedisplay();
- }
- int main(int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
- glutInitWindowPosition(100, 100);
- glutInitWindowSize(320, 320);
- glutCreateWindow("OpenGL Renderer");
- glutDisplayFunc(renderScene);
- glutReshapeFunc(ReSizeGLScene);
- glutIdleFunc(onIdle);
- gluPerspective(45, 1, 2, 10);
- glEnable(GL_DEPTH_TEST);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement