Advertisement
icatalin

stil L3 P2 [GRAFICA LAB3]

Mar 4th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. //lab 3 problema 2, trebuie sa folosim asta ca sa rezolvam
  2.  
  3. #include <gl/freeglut.h> // nu trebuie uitat freeglut.h (sau glut.h sau gl.h & glu.h)
  4. #include <iostream>
  5. using namespace std;
  6. int X[100];
  7. int Y[100];
  8. int stil[100];// cum as vrea sa desenez
  9. //segment ( X[i] , Y[i] ) to ( X[i+1] , Y[i+1] )
  10. int nr_puncte;
  11.  
  12.  
  13.  
  14. void desen(void) // procedura desenare  
  15. {
  16.     glClear(GL_COLOR_BUFFER_BIT); // reprezentare si colorare fereastra de vizualizare
  17.     int i;
  18.  
  19.     for (i = 0; i < nr_puncte - 1; i++) {
  20.         if (stil[i] == 1)
  21.         {
  22.             glLineWidth(15);
  23.             glColor3f(1, 0, 0);//rosu
  24.             glLineStipple(1, 0x1EED);
  25.         }
  26.         else {
  27.             glEnable(GL_LINE_STIPPLE);
  28.             glLineStipple(1, 0x00FF);
  29.             glLineWidth(10);
  30.             glColor3f(0, 1, 0);//verde
  31.         }
  32.         glBegin(GL_LINES);
  33.         glVertex2i(X[i], Y[i]);
  34.         glVertex2i(X[i + 1], Y[i + 1]);
  35.         glEnd();
  36.         glDisable(GL_LINE_STIPPLE);
  37.     }
  38.  
  39.  
  40.     glColor3f(0, 0, 1);//albastru
  41.     glPointSize(20);
  42.     glBegin(GL_POINTS);
  43.     for (i = 0; i < nr_puncte; i++)
  44.         glVertex2i(X[i], Y[i]);
  45.     glEnd();
  46.  
  47.     glFlush(); // proceseaza procedurile OpenGL cat mai rapid
  48. }
  49. /*
  50.  
  51. void se_intersecteaza(float xA,float yA,
  52.                       float xB,float yB,
  53.                       float xC,float yC,
  54.                       float xD,float yD,){
  55.  
  56. // ec dreptei care trece prin AB
  57.  
  58. float alpha = yB - yA;
  59. float gamma;
  60.     float beta;
  61.  
  62.      if (
  63.          ( alpha * xC + beta * yC +gamma )*
  64.         ( alpha * xD + beta * yD +gamma ) < 0
  65.         ){
  66.      // C si D sunt de o parte si de alta a dreptei AB
  67.      }
  68.  
  69. }
  70.  
  71. */
  72. void functie_pentru_click(int button, int state, int x, int y) {
  73.     if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
  74.     {
  75.         //store the x,y value where the click happened
  76.         cout << "click " << x << " " << y << endl;
  77.         X[nr_puncte] = x;
  78.         Y[nr_puncte] = 700 - y;
  79.         stil[nr_puncte] = nr_puncte % 2;
  80.         nr_puncte++;
  81.  
  82.         glutPostRedisplay();
  83.     }
  84. }
  85.  
  86. void main(int argc, char** argv)
  87. {
  88.     glutInit(&argc, argv); // initializare GLUT
  89.     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // se utilizeaza un singur buffer | modul de colorare RedGreenBlue (= default)
  90.     glutInitWindowPosition(0, 0); // pozitia initiala a ferestrei de vizualizare (in coordonate ecran)
  91.     glutInitWindowSize(1200, 700); // dimensiunile ferestrei
  92.     glutCreateWindow("Puncte & Segmente"); // creeaza fereastra, indicand numele ferestrei de vizualizare - apare in partea superioara
  93.  
  94.     glMatrixMode(GL_PROJECTION);  // se precizeaza este vorba de o reprezentare 2D, realizata prin proiectie ortogonala
  95.     gluOrtho2D(0.0, 1200.0, 0.0, 700.0);
  96.  
  97.     glClearColor(1.0, 1.0, 1.0, 0.0); // precizeaza culoarea de fond a ferestrei de vizualizare
  98.  
  99.     glutMouseFunc(functie_pentru_click);
  100.     glutDisplayFunc(desen); // procedura desen este invocata ori de cate ori este nevoie
  101.     glutMainLoop(); // ultima instructiune a programului, asteapta (eventuale) noi date de intrare
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement