Advertisement
Guest User

tandronlyline

a guest
Apr 9th, 2020
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. /*
  2. Shamsuddin Ahmed
  3. 161-15-1027
  4.  
  5. Draw triangle and rectangle only using lines
  6. */
  7.  
  8.  
  9. #include<windows.h>
  10. #include <GL/glut.h>
  11.  
  12. void init(void)
  13. {
  14.     glClearColor(1.0, 1.0, 1.0, 0.0);   // Set display window colour to white
  15.  
  16.     glMatrixMode(GL_PROJECTION);        // Set projection parameters
  17.     gluOrtho2D(0.0, 400.0, 0.0, 400.0);
  18. }
  19.  
  20. void drawShapes(void)
  21. {
  22.     glClear(GL_COLOR_BUFFER_BIT);   // Clear display window
  23.  
  24.     //Set colour to black
  25.     glColor3f(0.0, 0.0, 0.0);
  26.     //Adjust the point size
  27.     glPointSize(5.0);
  28.  
  29.     //Set colour to red
  30.     glColor3f(1.0, 0.0, 0.0);
  31.  
  32.     // Draw an outlined triangle
  33.     glBegin(GL_LINES);
  34.  
  35.         //Triangle Using Line
  36.         glVertex2i(54.53, 269.1);
  37.         glVertex2i(149.07, 269.1);
  38.  
  39.         glVertex2i(149.07, 269.1);
  40.         glVertex2i(102.77, 355.92);
  41.  
  42.         glVertex2i(102.77, 355.92);
  43.         glVertex2i(54.53, 269.1);
  44.         //Triangle End
  45.  
  46.         //Rectangle Using Line
  47.  
  48.         glVertex2i(203.09, 236.3);
  49.         glVertex2i(299.56, 236.3);
  50.  
  51.         glVertex2i(299.56, 236.3);
  52.         glVertex2i(299.56, 338.56);
  53.  
  54.         glVertex2i(299.56, 338.56);
  55.         glVertex2i(201.16,338.56);
  56.  
  57.         glVertex2i(201.16,338.56);
  58.         glVertex2i(203.09, 236.3);
  59.  
  60.         //Rectangle Using Line
  61.  
  62.  
  63.  
  64.  
  65.     glEnd();
  66.  
  67.     glFlush();  // Process all OpenGL routines
  68. }
  69.  
  70. int main(int argc, char* argv[])
  71. {
  72.     glutInit(&argc, argv);                      // Initalise GLUT
  73.     glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);  // Set display mode
  74.  
  75.     glutInitWindowPosition(50, 100);                // Set window position
  76.     glutInitWindowSize(400, 300);                   // Set window size
  77.     glutCreateWindow("An Example OpenGL Program");  // Create display window
  78.  
  79.     init();                         // Execute initialisation procedure
  80.     glutDisplayFunc(drawShapes);        // Send graphics to display window
  81.     glutMainLoop();                 // Display everything and wait
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement