Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- #define Height 600
- #define Width 800
- void displaySquareWithLines(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- // Define the size of the square
- GLfloat size = 600.0; // Assuming the height is the reference size
- // Calculate the coordinates to center the square
- GLfloat aspectRatio = (GLfloat)Width / (GLfloat)Height;
- GLfloat xLeft = -size / 2.0 * aspectRatio;
- GLfloat xRight = size / 2.0 * aspectRatio;
- GLfloat yBottom = -size / 2.0;
- GLfloat yTop = size / 2.0;
- // Draw the square
- glBegin(GL_LINES);
- glColor3f(0.0, 0.0, 1.0); // Set color to blue
- glVertex3f(xLeft, yBottom, 0.0); // Bottom-left corner
- glVertex3f(xRight, yBottom, 0.0); // Bottom-right corner
- glVertex3f(xRight, yBottom, 0.0); // Bottom-right corner
- glVertex3f(xRight, yTop, 0.0); // Top-right corner
- glVertex3f(xRight, yTop, 0.0); // Top-right corner
- glVertex3f(xLeft, yTop, 0.0); // Top-left corner
- glVertex3f(xLeft, yTop, 0.0); // Top-left corner
- glVertex3f(xLeft, yBottom, 0.0); // Bottom-left corner
- glEnd();
- // Draw the mid vertical line
- glBegin(GL_LINES);
- glColor3f(1.0, 0.0, 0.0); // Set color to red
- glVertex3f(0.0, yBottom, 0.0); // Start point of the line
- glVertex3f(0.0, yTop, 0.0); // End point of the line
- glEnd();
- // Draw the mid horizontal line
- glBegin(GL_LINES);
- glColor3f(1.0, 0.0, 0.0); // Set color to red
- glVertex3f(xLeft, 0.0, 0.0); // Start point of the line
- glVertex3f(xRight, 0.0, 0.0); // End point of the line
- glEnd();
- glFlush();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement