SHARE
TWEET

Untitled

a guest Feb 11th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <GL\glut.h>
  2.  
  3. GLfloat xRotated, yRotated, zRotated;
  4. GLdouble size = 1;
  5.  
  6.  
  7. void display(void)
  8. {
  9.  
  10.     glMatrixMode(GL_MODELVIEW);
  11.     // clear the drawing buffer.
  12.     glClear(GL_COLOR_BUFFER_BIT);
  13.     // clear the identity matrix.
  14.     glLoadIdentity();
  15.     // traslate the draw by z = -4.0
  16.     // Note this when you decrease z like -8.0 the drawing will looks far , or smaller.
  17.     glTranslatef(0.0, 0.0, -4.5);
  18.     // Red color used to draw.
  19.     glColor3f(0.8, 0.2, 0.1);
  20.     // changing in transformation matrix.
  21.     // rotation about X axis
  22.     glRotatef(xRotated, 1.0, 0.0, 0.0);
  23.     // rotation about Y axis
  24.     glRotatef(yRotated, 0.0, 1.0, 0.0);
  25.     // rotation about Z axis
  26.     glRotatef(zRotated, 0.0, 0.0, 1.0);
  27.     // scaling transfomation
  28.     glScalef(1.0, 1.0, 1.0);
  29.     // built-in (glut library) function , draw you a Teapot.
  30.     glutSolidTeapot(size);
  31.     // Flush buffers to screen
  32.  
  33.     glFlush();
  34.     // sawp buffers called because we are using double buffering
  35.    // glutSwapBuffers();
  36. }
  37.  
  38. void reshapeFunc(int x, int y)
  39. {
  40.     if (y == 0 || x == 0) return;  //Nothing is visible then, so return
  41.     //Set a new projection matrix
  42.     glMatrixMode(GL_PROJECTION);
  43.     glLoadIdentity();
  44.     //Angle of view:40 degrees
  45.     //Near clipping plane distance: 0.5
  46.     //Far clipping plane distance: 20.0
  47.  
  48.     gluPerspective(40.0, (GLdouble)x / (GLdouble)y, 0.5, 20.0);
  49.  
  50.     glViewport(0, 0, x, y);  //Use the whole window for rendering
  51. }
  52.  
  53. void idleFunc(void)
  54. {
  55.  
  56.     yRotated += 0.01;
  57.  
  58.     display();
  59. }
  60.  
  61.  
  62. int main(int argc, char **argv)
  63. {
  64.     //Initialize GLUT
  65.     glutInit(&argc, argv);
  66.     //double buffering used to avoid flickering problem in animation
  67.     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  68.     // window size
  69.     glutInitWindowSize(400, 350);
  70.     // create the window
  71.     glutCreateWindow("Teapot Rotating Animation");
  72.     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  73.     xRotated = yRotated = zRotated = 30.0;
  74.     xRotated = 33;
  75.     yRotated = 40;
  76.     glClearColor(0.0, 0.0, 0.0, 0.0);
  77.     //Assign  the function used in events
  78.     glutDisplayFunc(display);
  79.     glutReshapeFunc(reshapeFunc);
  80.     glutIdleFunc(idleFunc);
  81.     //Let start glut loop
  82.     glutMainLoop();
  83.     return 0;
  84. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top