daily pastebin goal
60%
SHARE
TWEET

new

a guest Aug 10th, 2018 60 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #include <GL\glut.h>
  2.  GLfloat xRotated, yRotated, zRotated;
  3. void init(void)
  4. {
  5. glClearColor(0,0,0,0);
  6.  
  7. }
  8.  
  9. void DrawCube(void)
  10. {
  11.  
  12.      glMatrixMode(GL_MODELVIEW);
  13.     // clear the drawing buffer.
  14.     glClear(GL_COLOR_BUFFER_BIT);
  15.    glLoadIdentity();
  16.         glTranslatef(0.0,0.0,-10.5);
  17.     glRotatef(xRotated,1.0,0.0,0.0);
  18.     // rotation about Y axis
  19.     glRotatef(yRotated,0.0,1.0,0.0);
  20.     // rotation about Z axis
  21.     glRotatef(zRotated,0.0,0.0,1.0);
  22.   glBegin(GL_QUADS);        // Draw The Cube Using quads
  23.     glColor3f(0.0f,1.0f,0.0f);    // Color Blue
  24.     glVertex3f( 1.0f, 1.0f,-1.0f);    // Top Right Of The Quad (Top)
  25.     glVertex3f(-1.0f, 1.0f,-1.0f);    // Top Left Of The Quad (Top)
  26.     glVertex3f(-1.0f, 1.0f, 1.0f);    // Bottom Left Of The Quad (Top)
  27.     glVertex3f( 1.0f, 1.0f, 1.0f);    // Bottom Right Of The Quad (Top)
  28.     glColor3f(1.0f,0.5f,0.0f);    // Color Orange
  29.     glVertex3f( 1.0f,-1.0f, 1.0f);    // Top Right Of The Quad (Bottom)
  30.     glVertex3f(-1.0f,-1.0f, 1.0f);    // Top Left Of The Quad (Bottom)
  31.     glVertex3f(-1.0f,-1.0f,-1.0f);    // Bottom Left Of The Quad (Bottom)
  32.     glVertex3f( 1.0f,-1.0f,-1.0f);    // Bottom Right Of The Quad (Bottom)
  33.     glColor3f(1.0f,0.0f,0.0f);    // Color Red    
  34.     glVertex3f( 1.0f, 1.0f, 1.0f);    // Top Right Of The Quad (Front)
  35.     glVertex3f(-1.0f, 1.0f, 1.0f);    // Top Left Of The Quad (Front)
  36.     glVertex3f(-1.0f,-1.0f, 1.0f);    // Bottom Left Of The Quad (Front)
  37.     glVertex3f( 1.0f,-1.0f, 1.0f);    // Bottom Right Of The Quad (Front)
  38.     glColor3f(1.0f,1.0f,0.0f);    // Color Yellow
  39.     glVertex3f( 1.0f,-1.0f,-1.0f);    // Top Right Of The Quad (Back)
  40.     glVertex3f(-1.0f,-1.0f,-1.0f);    // Top Left Of The Quad (Back)
  41.     glVertex3f(-1.0f, 1.0f,-1.0f);    // Bottom Left Of The Quad (Back)
  42.     glVertex3f( 1.0f, 1.0f,-1.0f);    // Bottom Right Of The Quad (Back)
  43.     glColor3f(0.0f,0.0f,1.0f);    // Color Blue
  44.     glVertex3f(-1.0f, 1.0f, 1.0f);    // Top Right Of The Quad (Left)
  45.     glVertex3f(-1.0f, 1.0f,-1.0f);    // Top Left Of The Quad (Left)
  46.     glVertex3f(-1.0f,-1.0f,-1.0f);    // Bottom Left Of The Quad (Left)
  47.     glVertex3f(-1.0f,-1.0f, 1.0f);    // Bottom Right Of The Quad (Left)
  48.     glColor3f(1.0f,0.0f,1.0f);    // Color Violet
  49.     glVertex3f( 1.0f, 1.0f,-1.0f);    // Top Right Of The Quad (Right)
  50.     glVertex3f( 1.0f, 1.0f, 1.0f);    // Top Left Of The Quad (Right)
  51.     glVertex3f( 1.0f,-1.0f, 1.0f);    // Bottom Left Of The Quad (Right)
  52.     glVertex3f( 1.0f,-1.0f,-1.0f);    // Bottom Right Of The Quad (Right)
  53.   glEnd();            // End Drawing The Cube
  54. glFlush();
  55. }
  56.  
  57.  
  58. void animation(void)
  59. {
  60.  
  61.      yRotated += 0.01;
  62.      xRotated += 0.02;
  63.     DrawCube();
  64. }
  65.  
  66.  
  67. void reshape(int x, int y)
  68. {
  69.     if (y == 0 || x == 0) return;  //Nothing is visible then, so return
  70.     //Set a new projection matrix
  71.     glMatrixMode(GL_PROJECTION);  
  72.     glLoadIdentity();
  73.     //Angle of view:40 degrees
  74.     //Near clipping plane distance: 0.5
  75.     //Far clipping plane distance: 20.0
  76.      
  77.     gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);
  78.     glMatrixMode(GL_MODELVIEW);
  79.     glViewport(0,0,x,y);  //Use the whole window for rendering
  80. }
  81.  
  82. int main(int argc, char** argv){
  83.  
  84. glutInit(&argc, argv);
  85. //we initizlilze the glut. functions
  86. glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  87. glutInitWindowPosition(100, 100);
  88. glutCreateWindow(argv[0]);
  89. init();
  90. glutDisplayFunc(DrawCube);
  91. glutReshapeFunc(reshape);
  92. //Set the function for the animation.
  93. glutIdleFunc(animation);
  94. glutMainLoop();
  95. return 0;
  96. }
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