X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=3e0f34f5c2a708ad83b160c018af88a76d414f48;hb=023daaaaab63ad4475c5839c7218407903815958;hp=824fbec23671974c6dd92a188ab03940b8c3f918;hpb=fffc1dd40d80fcba7713c7322b39d551d328cecf;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index 824fbec..3e0f34f 100644 --- a/scene.c +++ b/scene.c @@ -463,12 +463,21 @@ void makeMenu() { * @param w New width * @param h New height */ -void windowReshape(int width, int height) { - glViewport(0, 0, (GLsizei)width, (GLsizei)height); // Set our viewport to the size of our window - glMatrixMode(GL_PROJECTION); // Switch to the projection matrix so that we can manipulate how our scene is viewed - glLoadIdentity(); // Reset the projection matrix to the identity matrix so that we don't get any artifacts (cleaning up) - gluPerspective(60, (GLfloat)width / (GLfloat)height, 0.1, 1000.0); // Set the Field of view angle (in degrees), the aspect ratio of our window, and the new and far planes - glMatrixMode(GL_MODELVIEW); // Switch back to the model view matrix, so that we can start drawing shapes correctly +void windowReshape(int w, int h) { + 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(); } /** @@ -489,17 +498,38 @@ void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); + 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); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + gluLookAt(0.7f, 0.4f, 0.9f, -2.0f, -1.0f, -7.0f, 1.0f, 10.0f, 1.0f); + + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); glutSwapBuffers(); } +/** + * init function, sets OpenGL's starting state + */ +void init() { + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective( 60, 1, 0.1, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + /** * Main function * @param argc Number of arguments @@ -525,11 +555,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 @@ -538,5 +568,8 @@ int main(int argc, char **argv) { glutMouseFunc(mouse); makeMenu(); + + init(); + glutMainLoop(); }