Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #include<windows.h>
  2. #include <iostream>
  3. #include <stdlib.h>
  4. #include <GL/glut.h>
  5. using namespace std;
  6.  
  7. //Initializes 3D rendering
  8. void initRendering() {
  9. //Makes 3D drawing work when something is in front of something else
  10. glEnable(GL_DEPTH_TEST);
  11. }
  12. //Called when the window is resized
  13. void handleResize(int w, int h) {
  14. //Tell OpenGL how to convert from coordinates to pixel values
  15. glViewport(0, 0, w, h);
  16. glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective
  17. //Set the camera perspective
  18. glLoadIdentity(); //Reset the camera
  19. gluPerspective(45.0, //The camera angle
  20. (double)w / (double)h, //The width-to-height ratio
  21. 1.0, //The near z clipping coordinate
  22. 200.0); //The far z clipping coordinate
  23. }
  24. //Draws the 3D scene
  25. void drawScene() {
  26. //Clear information from last draw
  27. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  28. glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
  29. glLoadIdentity(); //Reset the drawing perspective
  30. glBegin(GL_TRIANGLES); //Begin triangle coordinates
  31. //Triangle
  32. glVertex3f(0.0,40.0,0.0);
  33. glVertex3f(15.0,-20.0,15.0);
  34. glVertex3f(-15.0,-20.0,15.0);
  35. glEnd(); //End triangle coordinates
  36. glBegin(GL_TRIANGLES); //Begin triangle coordinates
  37. //Triangle
  38. glVertex3f(0,40,0);
  39. glVertex3f(-15,-20,-15);
  40. glVertex3f(-15,-20,15);
  41. glEnd(); //End triangle coordinates
  42. glBegin(GL_TRIANGLES); //Begin triangle coordinates
  43. //Triangle
  44. glVertex3f(0.0,40.0,0.0);
  45. glVertex3f(-15.0,-20.0,-15.0);
  46. glVertex3f(15.0,-20.0,-15.0);
  47. glEnd(); //End triangle coordinates
  48.  
  49. glBegin(GL_TRIANGLES); //Begin triangle coordinates
  50. //Triangle
  51. glVertex3f(0,40,0);
  52. glVertex3f(15,-20,-15);
  53. glVertex3f(15,-20,15);
  54. glEnd(); //End triangle coordinates
  55.  
  56. glBegin(GL_TRIANGLES); //Begin triangle coordinates
  57. //Triangle
  58. glVertex3f(-15,-20,15);
  59. glVertex3f(-15.0,-20.0,15.0);
  60. glVertex3f(15.0,-20.0,15.0);
  61. glEnd(); //End triangle coordinates
  62. glBegin(GL_TRIANGLES); //Begin triangle coordinates
  63.  
  64. //Triangle
  65. glVertex3f(15,-20,15);
  66. glVertex3f(-15,-20,-15);
  67. glVertex3f(15,-20,-15);
  68. glEnd(); //End triangle coordinates
  69. glutSwapBuffers(); //Send the 3D scene to the screen
  70. }
  71. int main(int argc, char** argv) {
  72. //Initialize GLUT
  73. glutInit(&argc, argv);
  74. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  75. glutInitWindowSize(400, 400); //Set the window size
  76. //Create the window
  77. glutCreateWindow("Basic Shapes");
  78. initRendering(); //Initialize rendering
  79. //Set handler functions for drawing, keypresses, and window resizes
  80. glutDisplayFunc(drawScene);
  81. glutReshapeFunc(handleResize);
  82. glutMainLoop(); //Start the main loop
  83. return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement