#include #include #include // Define a constant for the value of PI #define GL_PI 3.1415f static float orbitDegreeZ = 0.0f; static float orbitDegreeX = 0.0f; static float zoom = 1.0f; GLint i = 0; unsigned char pattern[1024] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0, 0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0, 0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0, 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0, 0,0,0,0,1,1,1,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, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; void drawCube(int a) { int half = a / 2; //glClear(GL_COLOR_BUFFER_BIT); //glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); //glShadeModel(GL_FLAT); //glPolygonStipple(pattern); //glEnable(GL_POLYGON_STIPPLE); glColor3f(0.0f,1.0f,0.0f); glBegin(GL_POLYGON); glVertex3i(-half,-half,0); glVertex3i(half,-half,0); glVertex3i(half,-half,a); glVertex3i(-half,-half,a); glEnd(); glColor3f(0.0f,1.0f,1.0f); glBegin(GL_POLYGON); glVertex3i(-half,-half,0); glVertex3i(-half,half,0); glVertex3i(-half,half,a); glVertex3i(-half,-half,a); glEnd(); glColor3f(1.0f,0.0f,0.0f); glBegin(GL_POLYGON); glVertex3i(-half,half,0); glVertex3i(half,half,0); glVertex3i(half,half,a); glVertex3i(-half,half,a); glEnd(); glColor3f(1.0f,1.0f,0.0f); glBegin(GL_POLYGON); glVertex3i(half,half,0); glVertex3i(half,-half,0); glVertex3i(half,-half,a); glVertex3i(half,half,a); glEnd(); glColor3f(1.0f,0.0f,1.0f); glBegin(GL_POLYGON); glVertex3i(-half,-half,0); glVertex3i(half,-half,0); glVertex3i(half,half,0); glVertex3i(-half,half,0); glEnd(); glColor3f(0.0f,0.0f,1.0f); glBegin(GL_POLYGON); glVertex3i(-half,-half,a); glVertex3i(half,-half,a); glVertex3i(half,half,a); glVertex3i(-half,half,a); glEnd(); glEnable(GL_POLYGON_STIPPLE); } // Called to draw scene void RenderScene(void) { int j = 0; // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(-50.0 + orbitDegreeX, 1.0f, 0.0f, 0.0f); glRotatef(orbitDegreeZ, 0.0f,0.0f,1.0f); for (j =0; j < 1024; j++) { pattern[j] *=(unsigned char)250; } drawCube(10); 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 ); glEnable(GL_DEPTH_TEST); } void Timer(int value) { printf("Timer esemeny (%d)\n", value); i++; if( i==10 ) i= 0; glutPostRedisplay(); glutTimerFunc(1000, Timer, value + 1); } void Idle() { glutPostRedisplay(); } void ChangeSizeOrtho(int w, int h) { //GLfloat nRange = 25.0f; GLfloat nRange = 30.0f; //GLfloat nRange = 80.0f ; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); // Reset projection matrix stack glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Establish clipping volume (left, right, bottom, top, near, far) if (w <= h) glOrtho (-nRange, nRange, -nRange*h/w, nRange*h/w, -nRange, nRange); else glOrtho (-nRange*w/h, nRange*w/h, -nRange, nRange, -nRange, nRange); // Reset Model view matrix stack glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void SpecialKeys(int key, int x, int y) { if (key == GLUT_KEY_UP ) { orbitDegreeX += 1.0f; } if (key == GLUT_KEY_DOWN ) { orbitDegreeX -= 1.0f; } if (key == GLUT_KEY_LEFT ) { orbitDegreeZ -= 1.0f; } if (key == GLUT_KEY_RIGHT) { orbitDegreeZ += 1.0f; } if ( orbitDegreeX > 80.0f ) orbitDegreeX = 80.0f; if ( orbitDegreeX < -50.0f ) orbitDegreeX = -50.0f; if (orbitDegreeZ <= 360.0f) orbitDegreeZ -= 360.0f; if (orbitDegreeZ < 0.0f) orbitDegreeZ = 360.0f - orbitDegreeZ; glutPostRedisplay(); } int main(int argc, char* argv[]) { // >> Inicializalas glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(300, 300); glutCreateWindow("GLUT Alap"); // << Inicializalas // >> Callback fuggvenyek glutReshapeFunc(ChangeSizeOrtho); // Parhuzamos vetites //glutReshapeFunc(ChangeSizePerspective); // Perspektiv vetites glutSpecialFunc(SpecialKeys); //glutKeyboardFunc(Keyboard); //glutKeyboardFunc(Keyboard); glutDisplayFunc(RenderScene); //glutTimerFunc(1000, Timer, 1); // 1 mp mulva meghivodik a Timer() fuggveny //glutIdleFunc(Idle); // Idle(), ha nem tortenik semmi // << Callback fuggvenyek SetupRC(); glutMainLoop(); return 0; }