X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=860d82148772e5af50abdf7cd4d2004d214a8b20;hb=78c62e6812b8564a6bc0a6838ff4aaed25e30914;hp=b85ed9f38fd862c8df463e501286d0b3f15e0811;hpb=688788bca476f49c2a198755204816f105267a14;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index b85ed9f..860d821 100644 --- a/scene.c +++ b/scene.c @@ -464,24 +464,20 @@ void makeMenu() { * @param h New height */ void windowReshape(int w, int h) { - glViewport(0, 0, w, h); // Reset The Current Viewport - glMatrixMode(GL_PROJECTION); // Select The Projection Matrix - glLoadIdentity(); // Reset The Projection Matrix - - // Calculate The Aspect Ratio Of The Window - gluPerspective(45.0f,45.0f,0.1f,100.0f); - - glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix - glLoadIdentity(); // Reset The Modelview Matrix - - /*glViewport(0, 0, w, h); - glMatrixMode(GL_PROJECTION); /* switch matrix mode - glLoadIdentity(); - if (w <= h) - gluOrtho2D(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w, 2.0 * (GLfloat) h / (GLfloat) w); - else - gluOrtho2D(-2.0 * (GLfloat) w / (GLfloat) h, 2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0); - glMatrixMode(GL_MODELVIEW); /* return to modelview mode */ + GLdouble near = -10.0; + GLdouble far = 10.0; + + glViewport(0, 0, (GLsizei) w, (GLsizei) h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (w <= h) + glOrtho(near, far, near*(GLfloat)h/(GLfloat)w, + far*(GLfloat)h/(GLfloat)w, near, far); + else + glOrtho(near*(GLfloat)w/(GLfloat)h, + far*(GLfloat)w/(GLfloat)h, near, far, near, far); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); } /** @@ -502,16 +498,20 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - glTranslatef(-1.5f, 0.0f, -6.0f); - + glTranslatef( 0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); - glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red - glVertex3f(-1.0f, 1.0f, 0.0f); // Top left - glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right - glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right - glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left + glVertex3f( 0.0f, 1.0f, -1.0f); + glVertex3f( 0.0f, 1.0f, 1.0f); + glVertex3f( 0.0f, -1.0f, 1.0f); + glVertex3f( 0.0f, -1.0f, -1.0f); glEnd(); + + glTranslatef( 0.0f, 0.0f, -5.0f); // Move into the Screen 10.0 + glutSolidTeapot(1); + + gluLookAt(0.7f, 0.4f, 0.9f, -2.0f, -1.0f, -7.0f, 1.0f, 10.0f, 1.0f); + glutSwapBuffers(); } @@ -540,11 +540,11 @@ int main(int argc, char **argv) { glutInitWindowSize(500, 500); glutCreateWindow("Scene Editor"); - glShadeModel(GL_SMOOTH); // Enables Smooth Shading - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background - glClearDepth(1.0f); // Depth Buffer Setup - glEnable(GL_DEPTH_TEST); // Enables Depth Testing - glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do + glShadeModel(GL_SMOOTH); // Enables Smooth Shading + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background + glClearDepth(1.0f); // Depth Buffer Setup + glEnable(GL_DEPTH_TEST); // Enables Depth Testing + glDepthFunc(GL_LEQUAL); // the type glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations @@ -553,5 +553,11 @@ int main(int argc, char **argv) { glutMouseFunc(mouse); makeMenu(); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective( 60, 1, 0.1, 1000.0); + glMatrixMode(GL_MODELVIEW); + glutMainLoop(); }