Main Page | File List

gl.cpp

00001 #include "TriangleMesh.h"
00002 #include "Sphere.h"
00003 #include "Canvas.h"
00004 
00005 #include <GL/glut.h>
00006 
00007 using namespace columbia;
00008 
00009 int main_window;
00010 
00011 void init(void)
00012 {    
00013    glClearColor (0.0, 0.0, 0.0, 0.0);
00014    glShadeModel(GL_SMOOTH);
00015    glEnable(GL_DEPTH_TEST);
00016 }
00017 
00018 
00019 void display(void)
00020 {
00021   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00022 
00023   glMatrixMode(GL_MODELVIEW);
00024   glLoadIdentity();
00025 
00026   glTranslatef(0,0,-2);
00027   
00028   glBegin(GL_TRIANGLES);
00029   {    
00030     glVertex3f( -1,  0, 0 );
00031     glVertex3f(  1,  0, 0 );
00032     glVertex3f(  0,  1, 0 );
00033   }
00034   glEnd();
00035 
00036   glutSwapBuffers();
00037 }
00038 
00039 
00040 void reshape(int w, int h)
00041 {
00042   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
00043 
00044   glMatrixMode(GL_PROJECTION);
00045   glLoadIdentity();
00046   gluPerspective(70.0, (GLfloat) w/(GLfloat) h, .5, 30.0);
00047 }
00048 
00049 
00050 void myGlutIdle( void )
00051 {
00052   /* According to the GLUT specification, the current window is 
00053      undefined during an idle callback.  So we need to explicitly change
00054      it if necessary */
00055   if ( glutGetWindow() != main_window ) 
00056     glutSetWindow(main_window);  
00057 
00058   glutPostRedisplay();
00059 }
00060 
00061 
00062 
00063 int main(int argc, char** argv)
00064 {
00065    glutInit(&argc, argv);
00066    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00067    glutInitWindowSize(250, 250);
00068    glutInitWindowPosition(100, 100);
00069    main_window = glutCreateWindow(argv[0]);
00070 
00071    init();
00072 
00073    glutDisplayFunc(display);
00074    glutReshapeFunc(reshape);
00075    glutIdleFunc( myGlutIdle );
00076  
00077    glutMainLoop();
00078    return 0; 
00079 }

Generated on Sun Jul 18 20:32:35 2004 by doxygen 1.3.6