icatalin

tema 3.1 [grafica]

Mar 17th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 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 = 700, winHeight = 700;
  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.  
  27.     regHex = glGenLists(2);
  28.  
  29.     glNewList(regHex, GL_COMPILE);
  30.  
  31.         glColor3f(0.0, 1.0, 0.0);
  32.         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  33.  
  34.         glBegin(GL_POLYGON);
  35.         for (k = 0; k < 100; k++)
  36.         {
  37.             hexTheta = TWO_PI * k / 100;
  38.             hexVertex.x = 150 + 100 * cos(hexTheta);
  39.             hexVertex.y = 150 + 100 * sin(hexTheta);
  40.             glVertex2i(hexVertex.x, hexVertex.y);
  41.         }
  42.         glEnd();
  43.  
  44.     glEndList();
  45.  
  46.  
  47.     glNewList(regHex + 1, GL_COMPILE);
  48.         glColor3f(0.0, 0.0, 1.0);
  49.         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  50.  
  51.         glBegin(GL_POLYGON);
  52.  
  53.         for (k = 0; k < 100; k++)
  54.         {
  55.             hexTheta = TWO_PI * k / 100;
  56.             hexVertex.x = 150 + 130 * cos(hexTheta);
  57.             hexVertex.y = -150 + 130 * sin(hexTheta);
  58.             glVertex2i(hexVertex.x, hexVertex.y);
  59.         }
  60.         glEnd();
  61.  
  62.     glEndList();
  63. }
  64.  
  65. void displayHex(void)
  66. {
  67.     glClear(GL_COLOR_BUFFER_BIT);
  68.  
  69.  
  70.     glColor3f(1.0, 0.0, 0.0);
  71.     glBegin(GL_LINES);
  72.     glVertex2i(150, 150);
  73.     glVertex2i(250, 150);
  74.     glEnd();
  75.  
  76.     glBegin(GL_LINES);
  77.     glVertex2i(150, -150);
  78.     glVertex2i(280, -150);
  79.     glEnd();
  80.  
  81.     glRasterPos2i(152, 152);
  82.     glColor3f(0.0f, 0.0f, 1.0f);
  83.     glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)"(raza = 100)");
  84.  
  85.     glRasterPos2i(152, -148);
  86.     glColor3f(0.0, 0.0, 0.0);
  87.     glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char*)"(raza = 130)");
  88.  
  89.     glCallList(regHex);
  90.     glCallList(regHex+1);
  91.     glPopMatrix();
  92.  
  93.  
  94.     glFlush();
  95. }
  96.  
  97.  
  98.  
  99. void winReshapeFcn(GLint newWidth, GLint newHeight)
  100. {
  101.     glViewport(0, 0, (GLsizei)newWidth, (GLsizei)newHeight);
  102.  
  103.     glMatrixMode(GL_PROJECTION);
  104.     glLoadIdentity();
  105.     gluOrtho2D(-320.0, 320.0, -320.0, 320.0);
  106.  
  107.     glMatrixMode(GL_MODELVIEW);
  108.     glLoadIdentity();
  109.  
  110.     glClear(GL_COLOR_BUFFER_BIT);
  111. }
  112.  
  113.  
  114. void main(int argc, char** argv)
  115. {
  116.     glutInit(&argc, argv);
  117.     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  118.     glutInitWindowPosition(300, 300);
  119.     glutInitWindowSize(winWidth, winHeight);
  120.     glutCreateWindow("Hexagon - utilizarea listelor de display");
  121.  
  122.     init();
  123.     glutDisplayFunc(displayHex);
  124.     glutReshapeFunc(winReshapeFcn);
  125.  
  126.     glutMainLoop();
  127.  
  128. }
Advertisement
Add Comment
Please, Sign In to add comment