Complete Football Assignment
Complete Football Assignment
#include <GL/glut.h>
#include <corecrt_math.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
// Main container
glColor3f(1.0, 1.0, 1.0); // Set color to white
glBegin(GL_QUADS);
glVertex2f(-0.9, -0.7); // Bottom-left vertex
glVertex2f(0.9, -0.7); // Bottom-right vertex
glVertex2f(0.9, 0.7); // Top-right vertex
glVertex2f(-0.9, 0.7); // Top-left vertex
glEnd();
// White rectangles on the right and left sides of the green rectangle
glColor3f(1.0, 1.0, 1.0); // white
// Left rectangle
glBegin(GL_QUADS);
glVertex2f(-0.55, -0.1); // Bottom-left vertex
glVertex2f(-0.65, -0.1); // Bottom-right vertex
glVertex2f(-0.65, 0.1); // Top-right vertex
glVertex2f(-0.55, 0.1); // Top-left vertex
glEnd();
// Right rectangle
glBegin(GL_QUADS);
glVertex2f(0.65, -0.1); // Bottom-left vertex
glVertex2f(0.55, -0.1); // Bottom-right vertex
glVertex2f(0.55, 0.1); // Top-right vertex
glVertex2f(0.65, 0.1); // Top-left vertex
glEnd();
// Black borders for the white rectangles
// Circle radius
float circleRadius = 0.02; // Adjust as needed
// Left circle
glBegin(GL_POLYGON);
for (int i = 0; i < 360; i++) {
float theta = i * 3.14159 / 180;
glVertex2f(leftCircleX - circleRadius * sin(theta), circleY + circleRadius
* cos(theta));
}
glEnd();
// Right circle
glBegin(GL_POLYGON);
for (int i = 0; i < 360; i++) {
float theta = i * 3.14159 / 180;
glVertex2f(rightCircleX + circleRadius * sin(theta), circleY + circleRadius
* cos(theta));
}
glEnd();
glLineWidth(3.0);
glColor3f(0.0, 0.0, 0.0); // green
glBegin(GL_LINE_LOOP);
glVertex2f(-0.65, -0.35); // Bottom-left vertex
glVertex2f(0.65, -0.35); // Bottom-right vertex
glVertex2f(0.65, 0.35); // Top-right vertex
glVertex2f(-0.65, 0.35); // Top-left vertex
glEnd();
glLineWidth(3.0);
// Inner circle
// left semicircle
glPushMatrix();
glTranslatef(leftSemiCircleCenterX, leftSemiCircleCenterY, 0.0);
glRotatef(leftSemiCircleAngle, 0.0, 0.0, 1.0); // Rotate around the z-axis
glTranslatef(-leftSemiCircleCenterX, -leftSemiCircleCenterY, 0.0);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
for (int i = 0; i <= 180; ++i) {
float angle = i * 3.14159 / 180;
float x = leftSemiCircleCenterX + leftSemiCircleRadius * cos(angle);
float y = leftSemiCircleCenterY + leftSemiCircleRadius * sin(angle);
glVertex2f(x, y);
}
glEnd();
glPopMatrix(); // Restore the previous transformation matrix
drawText("Football Game", -0.2, 0.55, 1.0, 1.0, 1.0); // white color values
drawText("Football Match", -0.31, -0.65, 0.0, 0.0, 0.0); // White color,
slightly offset
glFlush();
}
void init() {
glClearColor(1.0, 1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0, 1.0, -1.0, 1.0); //rthographic projection
}