h8rt3rmin8r

teapot.c

Dec 15th, 2018
202
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* File: teapot.c
  2.  
  3. */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <GL/glut.h>
  8.  
  9. /* user defined functions declarations */
  10. void mydraw(void);
  11. void display(void);
  12. void init(void);
  13.  
  14. /* drawing routine, called by display every animated frame */
  15. void mydraw(void)
  16. {
  17.   /* Set up the color */
  18.   /* RGB values range from 0.0 to 1.0 */
  19.   glColor3f( 1.0, 0.0, 0.0); // red color
  20.   //glColor3f( 0.0, 1.0, 0.0); // green color
  21.  
  22.   /* draw a teapot */
  23.   glutSolidTeapot(.5); //or glutWireTeapot(.5)
  24.  
  25.   /* try different GLUT primitieves */
  26.   /* Sphere, Cube, Cone, Torus, etc. */
  27. }
  28.  
  29. /* display is called by the glut main loop once for every animated frame */
  30. void display(void)
  31. {
  32.   /* initialize color and depth buffers */
  33.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  34.  
  35.   /* call the routine that actually draws what you want */
  36.   mydraw();
  37.  
  38.   /* update the frame buffer */
  39.   glutSwapBuffers();
  40. }
  41.  
  42. /* called once to set up basic opengl state */
  43. void init(void)
  44. {
  45.   /* Use depth buffering for hidden surface elimination. */
  46.   glEnable(GL_DEPTH_TEST);
  47.  
  48.   /* Set up the perspective matrix */
  49.   glMatrixMode(GL_PROJECTION);
  50.   glLoadIdentity();
  51.  
  52.   /* left, right, bottom, top, near, far */
  53.   /* near and far values are the distances  from the camera to the front and rear clipping planes */
  54.   glFrustum(-1.0, 1.0, -1.0, 1.0, 1., 10.0); // perspective view
  55.   //glOrtho(-1.0, 1.0, -1.0, 1.0, 1., 10.0);  // orthgraphic view
  56.  
  57.   /* Another way to define perspective viewing volume fovy, aspect, near, far */
  58.   //gluPerspective(45.0f, 1., 1., 10.);
  59.  
  60.   /* Set up the model view matrix */
  61.   glMatrixMode(GL_MODELVIEW);
  62.   glLoadIdentity();
  63.  
  64.   /* Camera position */
  65.   /* By the default, the camera is situated at the origin,
  66.   points down the negative z-axis, and has an upper vector (0,1,0)*/
  67.   gluLookAt(0.,0.,2.,0.,0.,0.,0.,1.,0.);
  68.   //gluLookAt(1.,1.,1.,0.,0.,0.,0.,1.,0.);
  69. }
  70.  
  71. int main(int argc, char **argv)
  72. {
  73.   /* GLUT Configuration */
  74.   glutInit(&argc, argv);
  75.   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  76.  
  77.   /* These setup calls are optional - set size and position of the window */
  78.   glutInitWindowSize(600,600);
  79.   glutInitWindowPosition(200,200);
  80.  
  81.   /* Create Window */
  82.   glutCreateWindow("GL Teapot");
  83.  
  84.   /* Set display as a callback for the current window */
  85.   glutDisplayFunc(display);
  86.  
  87.   /* Set basic openGL states */
  88.   init();
  89.  
  90.   /* Enter GLUT event processing loop */
  91.   glutMainLoop();
  92.  
  93.   /* Exit the program */
  94.   return 0;
  95. }
RAW Paste Data