#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; int erdo[10][3]={{-10,-10,1},{40,-30,2},{30,20,1},{20,10,2},{45,25,2},{45,52,1},{0,0,2},{-10,20,1},{30,0,1},{20,-10,1}}; void drawPine(int x, int y) { glPushMatrix(); glTranslatef((float)x,(float)y,0.0); glColor3f(0.6f,0.4f,0.2f); //glutSolidCone(5.0,5.0,60,10); gluCylinder(gluNewQuadric(), 2.0,2.0,10,60,10); glColor3f(0.0f,0.6f,0.0f); glTranslatef(0.0,0.0,10.0); glutSolidCone(10.0,20.0,10,10); glTranslatef(0.0,0.0,10.0); glutSolidCone(7.0,15.0,10,10); glTranslatef(0.0,0.0,10.0); glutSolidCone(4.0,15.0,10,10); glPopMatrix(); } void drawNormalTree(int x, int y) { glPushMatrix(); glTranslatef((float)x,(float)y,0.0); glColor3f(0.6f,0.4f,0.2f); //glutSolidCone(5.0,5.0,60,10); gluCylinder(gluNewQuadric(), 2.0,2.0,30,60,10); glTranslatef(0.0,0.0,30.0); glColor3f(0.0f,0.8f,0.0f); glutSolidSphere(10.0,40,40); //glutSolidCone(10.0,20.0,10,10); glPopMatrix(); } void drawTree(int x, int y, int which) { //drawPine(x,y); if( which == 1) drawNormalTree(x,y); if( which == 2) drawPine(x,y); } // 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 < 10; j++) { drawTree(erdo[j][0],erdo[j][1], erdo[j][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 ); 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; }