Main Page | File List

gl.cpp

00001 #include <cstdlib>
00002 #include <GL/glut.h>
00003 
00004 
00005 int main_window;
00006 
00007 void init(void)
00008 {    
00009    glClearColor (0.0, 0.0, 0.0, 0.0);
00010    glShadeModel(GL_SMOOTH);
00011    glEnable(GL_DEPTH_TEST);
00012 
00013    glEnable(GL_LIGHTING);
00014    glEnable(GL_LIGHT0);
00015 }
00016 
00017 
00018 void display(void)
00019 {
00020   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00021 
00022   glMatrixMode(GL_MODELVIEW);
00023   glLoadIdentity();
00024 
00025   glTranslatef(0,0,-2);
00026   glRotatef(45, 0., 1., 0.);
00027   glScalef(.5, 1, 1);
00028   glutSolidCube (1.0);
00029 
00030   glutSwapBuffers();
00031 }
00032 
00033 
00034 void reshape(int w, int h)
00035 {
00036   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
00037 
00038   glMatrixMode(GL_PROJECTION);
00039   glLoadIdentity();
00040   gluPerspective(70.0, (GLfloat) w/(GLfloat) h, .5, 30.0);
00041 }
00042 
00043 
00044 void myGlutIdle( void )
00045 {
00046   /* According to the GLUT specification, the current window is 
00047      undefined during an idle callback.  So we need to explicitly change
00048      it if necessary */
00049   if ( glutGetWindow() != main_window ) 
00050     glutSetWindow(main_window);  
00051 
00052   glutPostRedisplay();
00053 }
00054 
00055 void anothername(unsigned char key, int x, int y)
00056 {
00057   if(key == 'q' || key == 'Q')
00058     exit(0);
00059 }
00060 
00061 
00062 
00063 void mouse(int button, int state, int x, int y) 
00064 {
00065   if (button == GLUT_LEFT_BUTTON) {
00066     if (state == GLUT_DOWN) {
00067       // do something...
00068     }
00069   }
00070   
00071 }
00072  
00073 
00074 int main(int argc, char** argv)
00075 {
00076    glutInit(&argc, argv);
00077    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00078    glutInitWindowSize(512, 512);
00079    glutInitWindowPosition(100, 100);
00080    main_window = glutCreateWindow(argv[0]);
00081 
00082    init();
00083 
00084    glutDisplayFunc(display);
00085    glutReshapeFunc(reshape);
00086    glutIdleFunc( myGlutIdle );
00087 
00088    glutMouseFunc(mouse);
00089 
00090    glutKeyboardFunc(anothername);
00091 
00092    glutMainLoop();
00093    return 0; 
00094 }

Generated on Mon Jul 19 17:20:27 2004 by doxygen 1.3.6