Advertisement
anik11556

Untitled

Jan 27th, 2024
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <GL/glut.h>
  2. #define Height 600
  3. #define Width 800
  4.  
  5.  
  6. void displaySquareWithLines(void)
  7. {
  8.    glClear(GL_COLOR_BUFFER_BIT);
  9.  
  10.  
  11.    // Define the size of the square
  12.    GLfloat size = 600.0; // Assuming the height is the reference size
  13.  
  14.  
  15.    // Calculate the coordinates to center the square
  16.    GLfloat aspectRatio = (GLfloat)Width / (GLfloat)Height;
  17.    GLfloat xLeft = -size / 2.0 * aspectRatio;
  18.    GLfloat xRight = size / 2.0 * aspectRatio;
  19.    GLfloat yBottom = -size / 2.0;
  20.    GLfloat yTop = size / 2.0;
  21.  
  22.  
  23.    // Draw the square
  24.    glBegin(GL_LINES);
  25.        glColor3f(0.0, 0.0, 1.0); // Set color to blue
  26.        glVertex3f(xLeft, yBottom, 0.0); // Bottom-left corner
  27.        glVertex3f(xRight, yBottom, 0.0); // Bottom-right corner
  28.  
  29.  
  30.        glVertex3f(xRight, yBottom, 0.0); // Bottom-right corner
  31.        glVertex3f(xRight, yTop, 0.0); // Top-right corner
  32.  
  33.  
  34.        glVertex3f(xRight, yTop, 0.0); // Top-right corner
  35.        glVertex3f(xLeft, yTop, 0.0); // Top-left corner
  36.  
  37.  
  38.        glVertex3f(xLeft, yTop, 0.0); // Top-left corner
  39.        glVertex3f(xLeft, yBottom, 0.0); // Bottom-left corner
  40.    glEnd();
  41.  
  42.  
  43.    // Draw the mid vertical line
  44.    glBegin(GL_LINES);
  45.        glColor3f(1.0, 0.0, 0.0); // Set color to red
  46.        glVertex3f(0.0, yBottom, 0.0); // Start point of the line
  47.        glVertex3f(0.0, yTop, 0.0); // End point of the line
  48.    glEnd();
  49.  
  50.  
  51.    // Draw the mid horizontal line
  52.    glBegin(GL_LINES);
  53.        glColor3f(1.0, 0.0, 0.0); // Set color to red
  54.        glVertex3f(xLeft, 0.0, 0.0); // Start point of the line
  55.        glVertex3f(xRight, 0.0, 0.0); // End point of the line
  56.    glEnd();
  57.  
  58.  
  59.    glFlush();
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement