#include #include #include // Define a constant for the value of PI #define GL_PI 3.1415f GLfloat xRot = 0.0f; GLfloat yRot = 0.0f; GLint i = 0; int erdo[10][2]={{10,10},{40,30},{30,20},{20,10},{40,40},{50,50},{0,0},{10,20},{30,0},{20,-10}}; 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(), 5.0,5.0,10,60,10); glTranslatef(0.0,0.0,10.0); glColor3f(0.0f,0.8f,0.0f); glutSolidCone(10.0,20.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(), 5.0,5.0,20,60,10); glTranslatef(0.0,0.0,50.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) { 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(); for (j=0; j> Modellezo programresz // ... // << Modellezo programresz 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; // 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 ChangeSizePerspective(GLsizei w, GLsizei h) { GLfloat fAspect; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); fAspect = (GLfloat)w/(GLfloat)h; // Reset coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Produce the perspective projection //gluPerspective(60.0f, // fovy gluPerspective(120.0f, // fovy fAspect, // aspect //10.0, // zNear 10.0, // zNear 100.0 // zFar ); //gluLookAt(0.0, 0.0, 50.0, // eye gluLookAt(0.0, -60.0, 40.0, // eye //0.0, 0.0, 0.0, // center 0.0, 0.0, 0.0, // center //0.0, 1.0, 0.0 // up 0.0, 10.0, 0.0 // up ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } 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); 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; }