Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <glew.h> // Include the GLEW header file
  3. #include <glut.h> // Include the GLUT header file
  4. #include <conio.h>
  5. #include <stdio.h>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. double rotate_by_key=0;
  11.  
  12. double rotate_x=0.5;
  13.  
  14. void keyPress(int key,int x,int y)
  15. {
  16.  
  17. if(key==27)
  18. exit(0);
  19. if (key == GLUT_KEY_UP)
  20. rotate_x += .05;
  21. if (key == GLUT_KEY_DOWN)
  22. rotate_x -= .05;
  23.  
  24. glutPostRedisplay();
  25.  
  26. }
  27.  
  28. void initRendering()
  29. {
  30. glEnable(GL_DEPTH_TEST);
  31. }
  32.  
  33.  
  34. //Called when the window is resized
  35. void handleResize(int w, int h) {
  36. //Tell OpenGL how to convert from coordinates to pixel values
  37. glViewport(0, 0, w, h);
  38.  
  39. glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective
  40.  
  41. //Set the camera perspective
  42. glLoadIdentity(); //Reset the camera
  43. gluPerspective(45.0, //The camera angle
  44. (double)w / (double)h, //The width-to-height ratio
  45. 1.0, //The near z clipping coordinate
  46. 200.0); //The far z clipping coordinate
  47. }
  48.  
  49. void drawScene()
  50. {
  51. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  52.  
  53. glMatrixMode(GL_MODELVIEW);
  54.  
  55. glLoadIdentity();
  56.  
  57. glScalef( rotate_x,rotate_x,1.0f );
  58. //glScalef(1.0f,1.0f,rotate_x);
  59. glRotatef( rotate_by_key,-1.0f, 1.5f, -5.0f );
  60.  
  61. glBegin(GL_POLYGON);
  62.  
  63.  
  64. glVertex3f(1.0f, 0.0f, -5.0f);
  65. glVertex3f(0.0f, 1.0f, -5.0f);
  66.  
  67. glVertex3f(0.0f, -1.0f, -5.0f);
  68. glEnd();
  69.  
  70. glutSwapBuffers();
  71. }
  72.  
  73. int main(int argc,char** argv)
  74. {
  75. glutInit(&argc,argv);
  76.  
  77. glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
  78.  
  79. glutInitWindowSize(400,400);
  80.  
  81. glutCreateWindow("My triangle");
  82.  
  83. initRendering();
  84.  
  85. glutDisplayFunc(drawScene);
  86.  
  87. glutSpecialFunc(keyPress);
  88.  
  89. glutReshapeFunc(handleResize);
  90.  
  91. glutMainLoop();
  92.  
  93. return(0);
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement