Advertisement
FaisalAhemdBijoy

GL

Apr 11th, 2021
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1.  
  2. #include <GL/gl.h>
  3. #include <GL/glu.h>
  4. #include <GL/glut.h>
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7. #include <windows.h>
  8.  
  9. switch(state)
  10. {
  11. case 0:
  12.     break;
  13. case 1:
  14.     glPushMatrix();
  15.     glTranslatef(-1,0,0);
  16.     rectangle(0,0,1,2);
  17.     glPopMatrix();
  18.     break;
  19. case 2:
  20.     glPushMatrix();
  21.     glRotatef(rot,0,0);
  22.     triangle();
  23.     glPopMatrix();
  24.     break;
  25. case 3:
  26.     glPushMatrix();
  27.     glTranslatef(-0.5,-0.5,-2);
  28.     glRotatef(-45,1,0,0);
  29.     glRotatef(45,1,0,1);
  30.     glTranslatef(0.5,0.5,0.5);
  31.     glRotatef(rot*0.1,1,1,1);
  32.     glTranslatef(-0.5,-0.5,-0.5);
  33.    
  34.     cube(1.0);
  35.     glPopMatrix();
  36.     break;
  37.    
  38. }
  39. glFlush();
  40. glutSwapBuffers();
  41.  
  42. void myKeyboardFunc(unsigned char key, int x, int y)
  43. {
  44.     switch(key)
  45.     {
  46.     case '0':
  47.         state=0;
  48.         break;
  49.     case '1':
  50.         state=1;
  51.     case '2':
  52.         state=2;
  53.         flagRotate=true;
  54.         rot=0;
  55.         break;
  56.     case '3':
  57.         state=3;
  58.         flagRotate=true;
  59.         rot=0;
  60.         break;
  61.     case 's':
  62.         flagRotate=false;
  63.         break;
  64.     case 27:
  65.         exit(1);
  66.     }
  67.     glutPostRedisplay();
  68. }
  69. void animate()
  70. {
  71.     if (flagRotate == true)
  72.     {
  73.         rot=(rot+1);
  74.        
  75.     }
  76.     glutPostRedisplay();
  77. }
  78. int main(int argc, char **argv)
  79. {
  80.     glutInit(&argc,argv);
  81.     glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
  82.    
  83.     glutInitWindowPosition(100,100);
  84.     glutInitWindowSize(windowWidth,windowHeight);
  85.     glutCreateWindow('Assignment 1');
  86.    
  87.     glShadeModel(GL_SMOOTH);
  88.     glEnable(GL_DEPTH_TEST);
  89.    
  90.     glutDisplayFunc(display);
  91.     glutKeyboardFunc(myKeyboardFunc);
  92.     glutIdleFunc(animate);
  93.    
  94.     glutMainLoop();
  95.     return 0;
  96.    
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement