Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *
- * GLUT Shapes Demo
- *
- * Written by Nigel Stewart November 2003
- *
- * This program is test harness for the sphere, cone
- * and torus shapes in GLUT.
- *
- * Spinning wireframe and smooth shaded shapes are
- * displayed until the ESC or q key is pressed. The
- * number of geometry stacks and slices can be adjusted
- * using the + and - keys.
- */
- #ifdef __APPLE__
- #include <GLUT/glut.h>
- #else
- #include <GL/glut.h>
- #endif
- #include <stdlib.h>
- float counter = 0;
- /* GLUT callback Handlers */
- void reshape(GLsizei width, GLsizei height){
- if (height == 0) height = 1;
- GLfloat aspect = (GLfloat)width / (GLfloat)height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(60.0f, aspect, 0.1f, 100.0f);
- }
- void initOpenGL(){
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glClearDepth(1.0f);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LEQUAL);
- glShadeModel(GL_SMOOTH);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
- }
- void display(){
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glTranslatef(0.0f, 0.0f, -7.0f);
- if(counter<360){
- glRotatef(counter, 1.0, 0.0, 0.0);
- }else{
- glRotatef(counter, 0.0, 1.0, 0.0);
- }
- counter += 0.01;
- glBegin(GL_QUADS);
- glColor3f(1.0f, 0.0f, 0.0f);
- glVertex3f( 1.0f, 1.0f, -1.0f);
- glVertex3f(-1.0f, 1.0f, -1.0f);
- glVertex3f(-1.0f, 1.0f, 1.0f);
- glVertex3f( 1.0f, 1.0f, 1.0f);
- glColor3f(1.0f, 0.5f, 0.0f);
- glVertex3f( 1.0f, -1.0f, 1.0f);
- glVertex3f(-1.0f, -1.0f, 1.0f);
- glVertex3f(-1.0f, -1.0f, -1.0f);
- glVertex3f( 1.0f, -1.0f, -1.0f);
- glColor3f(1.0f, 0.0f, 0.0f);
- glVertex3f( 1.0f, 1.0f, 1.0f);
- glVertex3f(-1.0f, 1.0f, 1.0f);
- glVertex3f(-1.0f, -1.0f, 1.0f);
- glVertex3f( 1.0f, -1.0f, 1.0f);
- glColor3f(1.0f, 1.0f, 0.0f);
- glVertex3f(-1.0f, 1.0f, 1.0f);
- glVertex3f(-1.0f, 1.0f, -1.0f);
- glVertex3f(-1.0f, -1.0f, -1.0f);
- glVertex3f(-1.0f, -1.0f, 1.0f);
- glColor3f(1.0f, 0.0f, 1.0f);
- glVertex3f(1.0f, 1.0f, -1.0f);
- glVertex3f(1.0f, 1.0f, 1.0f);
- glVertex3f(1.0f, -1.0f, 1.0f);
- glVertex3f(1.0f, -1.0f, -1.0f);
- glEnd();
- glutSwapBuffers();
- }
- int main(int argc, char** argv) {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
- glutInitWindowSize(640, 480);
- glutInitWindowPosition(50, 50);
- glutCreateWindow("Primitive");
- glutDisplayFunc(display);
- glutIdleFunc(display);
- glutReshapeFunc(reshape);
- initOpenGL();
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement