Alex9090

Untitled

Mar 5th, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. /*Hearn & Baker */
  2. #include <windows.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5. #include <GL/freeglut.h>
  6.  
  7. const double TWO_PI = 6.2831853;
  8.  
  9. GLsizei winWidth = 500, winHeight = 500;
  10. GLuint regHex;
  11. static GLfloat rotTheta = 0.0;
  12.  
  13. class scrPt
  14. {
  15. public:
  16. GLint x, y;
  17. };
  18.  
  19. static void init (void)
  20. {
  21. scrPt hexVertex;
  22. GLdouble hexTheta;
  23. GLint k;
  24.  
  25. glClearColor (1.0, 1.0, 1.0, 1.0);
  26. regHex = glGenLists (1); //o singura lista display noua
  27. regHex2 = glGenLists(1);
  28. glNewList (regHex, GL_COMPILE); //instructiuni de desen
  29. glColor3f (1.0, 0.0, 0.0);
  30. glBegin (GL_POLYGON);
  31. for (k=0; k < 6; k++)
  32. {
  33. hexTheta = TWO_PI * k / 6;
  34. hexVertex.x = 150 + 100 * cos (hexTheta);
  35. hexVertex.y = 150 + 100 * sin (hexTheta);
  36. glVertex2i (hexVertex.x, hexVertex.y);
  37. }
  38. glEnd ( );
  39. glEndList ( );
  40. glNewList (regHex2, GL_COMPILE); //instructiuni de desen
  41. glColor3f (1.0, 0.0, 0.0);
  42. glBegin (GL_POLYGON);
  43. for (k=0; k < 6; k++)
  44. {
  45. hexTheta = TWO_PI * k / 6;
  46. hexVertex.x = 0 + 50 * cos (hexTheta);
  47. hexVertex.y = 0 + 50 * sin (hexTheta);
  48. glVertex2i (hexVertex.x, hexVertex.y);
  49. }
  50. glEnd ( );
  51. glEndList ( );
  52. }
  53. //facem 2 cercuri
  54. //2 cercuri
  55. void displayHex (void)
  56. {
  57. glClear (GL_COLOR_BUFFER_BIT);
  58.  
  59.  
  60. glCallList (regHex);
  61. glPushMatrix();
  62. glTranslated(-80,-80,0);
  63. glCallList(regHex);
  64. glPopMatrix ( );
  65.  
  66.  
  67. glFlush ( );
  68. }
  69.  
  70.  
  71.  
  72. void winReshapeFcn (GLint newWidth, GLint newHeight)
  73. {
  74. glViewport (0, 0, (GLsizei) newWidth, (GLsizei) newHeight);
  75.  
  76. glMatrixMode (GL_PROJECTION);
  77. glLoadIdentity ( );
  78. gluOrtho2D (-320.0, 320.0, -320.0, 320.0);
  79.  
  80. glMatrixMode (GL_MODELVIEW);
  81. glLoadIdentity ( );
  82.  
  83. glClear (GL_COLOR_BUFFER_BIT);
  84. }
  85.  
  86.  
  87. void main (int argc, char **argv)
  88. {
  89. glutInit (&argc, argv);
  90. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  91. glutInitWindowPosition (150, 150);
  92. glutInitWindowSize (winWidth, winHeight);
  93. glutCreateWindow ("Hexagon - utilizarea listelor de display");
  94.  
  95. init ( );
  96. glutDisplayFunc (displayHex);
  97. glutReshapeFunc (winReshapeFcn);
  98.  
  99. glutMainLoop ( );
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment