home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / Mesa-3.0 / BeOS / cone_ball.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-31  |  1.9 KB  |  82 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "GL/osmesa.h"
  4. #include "glaux.h"
  5.  
  6. int gl_width=480;
  7. int gl_height=480;
  8.  
  9. void init(void)
  10. {
  11.    GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
  12.    GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
  13.    GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  14.    GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
  15.  
  16.    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  17.    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  18.    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
  19.    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  20.     
  21.    glEnable(GL_LIGHTING);
  22.    glEnable(GL_LIGHT0);
  23.    glEnable(GL_DEPTH_TEST);
  24. }
  25.  
  26. /*
  27.  * reshape simply creates an orthographic projection
  28.  * within the viewport.
  29.  */
  30. void reshape(int w, int h)
  31. {
  32.    glViewport(0,0,w,h);
  33.    glMatrixMode(GL_PROJECTION);
  34.    glLoadIdentity();
  35.    glOrtho(-2.5, 2.5, -2.5, 2.5, -5.0, 5.0);
  36.  
  37.    glMatrixMode(GL_MODELVIEW);
  38.    glLoadIdentity();
  39. }
  40.  
  41. void display(void)
  42. {
  43.    GLfloat red_mat[]   = { 1.0, 0.0, 0.0, 0.5 };
  44.    GLfloat green_mat[] = { 0.0, 1.0, 0.0, 0.5 };
  45.    GLfloat blue_mat[]  = { 0.0, 0.0, 1.0, 0.5};
  46.  
  47.    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  48.  
  49.    glPushMatrix();
  50.    glRotatef(20.0, 1.0, 0.0, 0.0);
  51.  
  52.    glPushMatrix();
  53.    glTranslatef(-0.75, 0.5, 0.0); 
  54.    glRotatef(90.0, 1.0, 0.0, 0.0);
  55.    glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red_mat );
  56.    auxSolidTorus(0.275, 0.85);
  57.    glPopMatrix();
  58.  
  59.    glPushMatrix();
  60.    glTranslatef(-0.75, -0.5, 0.0); 
  61.    glRotatef(270.0, 1.0, 0.0, 0.0);
  62.    glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green_mat );
  63.    auxSolidCone(1.0, 2.0);
  64.    glPopMatrix();
  65.  
  66.    glPushMatrix();
  67.    glTranslatef(0.75, 0.0, -1.0);
  68.    glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat );
  69.    auxSolidSphere(1.0);
  70.    glPopMatrix();
  71.  
  72.    glPopMatrix();
  73. }
  74.  
  75. void render_image(void)
  76. {
  77.     init();
  78.     reshape(gl_width,gl_height);
  79.     display();
  80. }
  81.  
  82.