#include #include // Define a constant for the value of PI #define GL_PI 3.1415f static int object = 0; static int type = 0; static GLfloat xRot = 0.0f; static GLfloat yRot = 0.0f; void drawGLUTObject(int which, int how) { if (how) { switch(which) { case 0: glutSolidSphere(10.0, 20, 20); break; case 1: glutSolidCube(20.0); break; case 2: glutSolidCone(10.0, 20.0, 20, 20); break; case 3: glutSolidTorus(4.0, 10.0, 20, 20); break; case 4: glutSolidDodecahedron(); break; case 5: glutSolidOctahedron(); break; case 6: glutSolidTetrahedron(); break; case 7: glutSolidIcosahedron(); break; case 8: glutSolidTeapot(10.0); break; } } else { switch(which) { case 0: glutWireSphere(10.0, 20, 20); break; case 1: glutWireCube(20.0); break; case 2: glutWireCone(10.0, 20.0, 20, 20); break; case 3: glutWireTorus(4.0, 10.0, 20, 20); break; case 4: glutWireDodecahedron(); break; case 5: glutWireOctahedron(); break; case 6: glutWireTetrahedron(); break; case 7: glutWireIcosahedron(); break; case 8: glutWireTeapot(10.0); break; } } } // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glTranslatef(0.0f, 0.0f, -50.0f); if (object%9==4 || object%9==6) glScalef(10.0f, 10.0f, 10.0f); if (object%9==5 || object%9==7) glScalef(15.0f, 15.0f, 15.0f); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); glColor3f(0.2, 0.8, 0.7); drawGLUTObject(object%9, type%2); glPopMatrix(); // Flush drawing commands glutSwapBuffers(); } // This function does any needed initialization on the rendering // context. void SetupRC() { // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); } void SpecialKeys(int key, int x, int y) { int state; state=glutGetModifiers(); if (!(state & GLUT_ACTIVE_SHIFT)) { if(key == GLUT_KEY_LEFT) yRot -= 5.0f; if(key == GLUT_KEY_RIGHT) yRot += 5.0f; if(key == GLUT_KEY_UP) xRot -= 5.0f; if(key == GLUT_KEY_DOWN) xRot += 5.0f; if(xRot>356.0f) xRot=0.0f; if(xRot<-1.0f) xRot=355.0f; if(yRot>356.0f) yRot=0.0f; if(yRot<-1.0f) yRot=355.0f; } else { if(key == GLUT_KEY_LEFT) object -= 1; if(key == GLUT_KEY_RIGHT) object += 1; if(key == GLUT_KEY_UP) type += 1; if(key == GLUT_KEY_DOWN) type -= 1; } // Refresh the Window glutPostRedisplay(); } void ChangeSize(int w, int h) { GLfloat fAspect; GLfloat zNear = 1.0f; GLfloat zFar = 400.0f; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); // Determine the aspect ratio fAspect=(GLfloat)w/(GLfloat)h; // Reset projection matrix stack glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* Establish clipping volume (field of view angle, aspect ratio, distance from the viewer to the near clipping plane, distance from the viewer to the far clipping plane)*/ gluPerspective(45.0f, fAspect, zNear, zFar); // Reset Model view matrix stack glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutCreateWindow("GLUT magasabbszintu objektumok"); glutReshapeFunc(ChangeSize); glutSpecialFunc(SpecialKeys); glutDisplayFunc(RenderScene); SetupRC(); glutMainLoop(); return 0; }