[go: up one dir, main page]

0% found this document useful (0 votes)
3 views36 pages

Submission Guidelines-: Lab Taks-3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 36

Lab Taks-3

Submission Guidelines-

 Rename the file to your id only. If your id is 18-XXXXX-1, then the file name must be 18-
XXXXX-1.docx.
 Must submit within time that will be discussed in class VUES to the section named Lab
Tak-3
 Must include resources for all the section in the table

Question- 1

Draw five storied building with windows and a front door

Graph Plot (Picture)-


Code-
#include <windows.h> // for MS Windows

#include <GL/glut.h> // GLUT, include glu.h and gl.h

/* Handler for window-repaint event. Call back when the window first appears and

whenever the window needs to be re-painted. */

void triangleOne(){
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.9f, 1.0f);
glVertex2f(-1.4f, 3.4f);
glVertex2f(1.4f, 3.4f); // x, y
glVertex2f(0.0f, 4.0f); // x, y

glEnd();
}

void squareOne(){
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.5f, 1.0f);
glVertex2f(-1.4f, 3.4f);
glVertex2f(-1.4f, 3.1f);
glVertex2f(1.4f, 3.1f);
glVertex2f(1.4f, 3.4f);

glEnd();
}

void squareTwo(){
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.5f, 0.0f);
glVertex2f(-1.4f, 3.1f);
glVertex2f(-1.4f, -2.0f);
glVertex2f(1.4f, -2.0f);
glVertex2f(1.4f, 3.1f);

glEnd();
}

void squareThree(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.5f, 1.0f);
glVertex2f(-0.5f, -2.0f);
glVertex2f(0.5f, -2.0f);
glVertex2f(0.5f, -1.2f);
glVertex2f(-0.5f, -1.2f);

glEnd();
}

void squareFour(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.0f, 1.0f);
glVertex2f(-0.4f, -2.0f);
glVertex2f(0.4f, -2.0f);
glVertex2f(0.4f, -1.3f);
glVertex2f(-0.4f, -1.3f);

glEnd();
}

void RectangleOne(){
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.7f, 1.0f);
glVertex2f(-0.6f, -0.9f);
glVertex2f(-0.6f, -1.0f);
glVertex2f(0.6f, -1.0f);
glVertex2f(0.6f, -0.9f);

glEnd();
}

void RectangleTwo(){
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.7f, 1.0f);
glVertex2f(-0.6f, 0.1f);
glVertex2f(-0.6f, 0.0f);
glVertex2f(0.6f, 0.0f);
glVertex2f(0.6f, 0.1f);

glEnd();
}

void RectangleThree(){
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.7f, 1.0f);
glVertex2f(-0.6f, 1.1f);
glVertex2f(-0.6f, 1.0f);
glVertex2f(0.6f, 1.0f);
glVertex2f(0.6f, 1.1f);

glEnd();
}

void RectangleFour(){
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.7f, 1.0f);
glVertex2f(-0.6f, 2.1f);
glVertex2f(-0.6f, 2.0f);
glVertex2f(0.6f, 2.0f);
glVertex2f(0.6f, 2.1f);

glEnd();
}

void WindowOne(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.0f, 1.0f);
glVertex2f(-0.4f, -0.9f);
glVertex2f(-0.4f, -0.5f);
glVertex2f(0.4f, -0.5f);
glVertex2f(0.4f, -0.9f);

glEnd();
}

void WindowTwo(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.0f, 1.0f);
glVertex2f(-0.4f, 0.1f);
glVertex2f(-0.4f, 0.5f);
glVertex2f(0.4f, 0.5f);
glVertex2f(0.4f, 0.1f);

glEnd();
}

void WindowThree(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.0f, 1.0f);
glVertex2f(-0.4f, 1.1f);
glVertex2f(-0.4f, 1.5f);
glVertex2f(0.4f, 1.5f);
glVertex2f(0.4f, 1.1f);

glEnd();
}
void WindowFour(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.0f, 1.0f);
glVertex2f(-0.4f, 2.1f);
glVertex2f(-0.4f, 2.5f);
glVertex2f(0.4f, 2.5f);
glVertex2f(0.4f, 2.1f);

glEnd();
}
void Line1(){
glBegin(GL_LINES);
glLineWidth(1);
glColor3ub(0,0,0);
glVertex2f(0.0f,-0.5f);
glVertex2f(0.0f, -0.9f); // x, y
glEnd();
}

void Line2(){
glBegin(GL_LINES);
glLineWidth(1);
glColor3ub(0,0,0);
glVertex2f(0.0f,0.1f);
glVertex2f(0.0f, 0.5f); // x, y
glEnd();
}

void Line3(){
glBegin(GL_LINES);
glLineWidth(1);
glColor3ub(0,0,0);
glVertex2f(0.0f,1.1f);
glVertex2f(0.0f, 1.5f); // x, y
glEnd();
}

void Line4(){
glBegin(GL_LINES);
glLineWidth(1);
glColor3ub(0,0,0);
glVertex2f(0.0f,2.1f);
glVertex2f(0.0f, 2.5f); // x, y
glEnd();
}

void building(){
triangleOne();
squareOne();
squareTwo();
squareThree();
squareFour();
RectangleOne();
RectangleTwo();
RectangleThree();
RectangleFour();
WindowOne();
WindowTwo();
WindowThree();
WindowFour();
Line1();
Line2();
Line3();
Line4();
}

void display() {
glClearColor(255.0f, 255.0f, 255.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer (background)
building();
glFlush(); // Render now

/* Main function: GLUT runs as a console application starting at main() */

int main(int argc, char** argv) {

glutInit(&argc, argv); // Initialize GLUT

glutCreateWindow("OpenGL Setup"); // Create a window with the given title

glutInitWindowSize(720, 1080); // Set the window's initial width & height


glutDisplayFunc(display); // Register display callback handler for window re-paint
gluOrtho2D(-5,5,-5,5);
glutMainLoop(); // Enter the event-processing loop

return 0;

Output Screenshot (Full Screen)-

Question- 2

Draw a tree

Graph Plot (Picture)-


Code-
#include <windows.h> // for MS Windows

#include <GL/glut.h> // GLUT, include glu.h and gl.h

/* Handler for window-repaint event. Call back when the window first appears and

whenever the window needs to be re-painted. */

void squareOne(){
glBegin(GL_POLYGON);
glColor3f(0.9f, 0.5f, 0.0f);
glVertex2f(3.0f, -2.2f);
glVertex2f(3.4f, -2.2f);
glVertex2f(3.4f, -4.0f);
glVertex2f(3.0f, -4.0f);

glEnd();
}

void triangleOne(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.4f, -2.2f);
glVertex2f(3.4f, -1.8f); // x, y
glVertex2f(4.0f, -3.0f); // x, y

glEnd();
}

void triangleTwo(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.4f, -1.8f);
glVertex2f(3.4f, -1.4f); // x, y
glVertex2f(4.6f, -2.8f); // x, y

glEnd();
}

void triangleThree(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.8f, -1.4f);
glVertex2f(3.4f, -1.4f); // x, y
glVertex2f(4.2f, -1.8f); // x, y

glEnd();
}
void triangleFour(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(2.6f, -1.4f);
glVertex2f(3.8f, -1.4f); // x, y
glVertex2f(3.2f, -0.8f); // x, y

glEnd();
}

void triangleFive(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(2.6f, -1.4f);
glVertex2f(3.0f, -1.4f); // x, y
glVertex2f(2.2f, -1.8f); // x, y

glEnd();
}

void triangleSix(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.0f, -1.4f);
glVertex2f(1.8f, -2.4f); // x, y
glVertex2f(3.0f, -1.8f); // x, y

glEnd();
}

void triangleSeven(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.0f, -1.8f);
glVertex2f(2.2f, -3.0f); // x, y
glVertex2f(3.0f, -2.2f); // x, y
glEnd();
}

void squareTwo(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.0f, -2.2f);
glVertex2f(3.4f, -2.2f);
glVertex2f(3.4f, -1.4f);
glVertex2f(3.0f, -1.4f);

glEnd();
}

void tree(){
squareOne();
triangleOne();
triangleTwo();
triangleThree();
triangleFour();
triangleFive();
triangleSix();
triangleSeven();
squareTwo();
}

void display() {
glClearColor(255.0f, 255.0f, 255.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer (background)
tree();
glFlush(); // Render now

/* Main function: GLUT runs as a console application starting at main() */

int main(int argc, char** argv) {

glutInit(&argc, argv); // Initialize GLUT


glutCreateWindow("OpenGL Setup"); // Create a window with the given title

glutInitWindowSize(720, 1080); // Set the window's initial width & height

glutDisplayFunc(display); // Register display callback handler for window re-paint


gluOrtho2D(-5,5,-5,5);
glutMainLoop(); // Enter the event-processing loop

return 0;

Output Screenshot (Full Screen)-

Question- 3

Draw a lamppost with black background

Graph Plot (Picture)-


Code-
#include <windows.h> // for MS Windows

#include <GL/glut.h>
#include<math.h>

void squareOne(){
glBegin(GL_POLYGON);
glColor3f(0.9f, 1.0f, 1.0f);
glVertex2f(-3.0f, -1.4f);
glVertex2f(-2.8f, -1.4f);
glVertex2f(-2.8f, -4.0f);
glVertex2f(-3.0f, -4.0f);

glEnd();
}

void squareTwo(){
glBegin(GL_POLYGON);
glColor3f(0.9f, 1.0f, 1.0f);
glVertex2f(-2.8f, -1.4f);
glVertex2f(-3.6f, -1.4f);
glVertex2f(-3.6f, -1.5f);
glVertex2f(-2.8f, -1.5f);

glEnd();
}

void squareThree(){
glBegin(GL_POLYGON);
glColor3f(0.9f, 1.0f, 1.0f);
glVertex2f(-3.3f, -1.5f);
glVertex2f(-3.3f, -1.6f);
glVertex2f(-3.2f, -1.6f);
glVertex2f(-3.2f, -1.5f);

glEnd();
}

void semicircle(){
glBegin(GL_POLYGON);
glColor3f(0.85, 0.850, 0.10); // White color

// Define semi-circle
float radius = 0.1;
float pi = 3.14159265359;
for (int i = 0; i >= -180; i--) {
float angle = i * 2*pi / 180.0;
glVertex2f((cos(angle) * radius-3.25), (sin(angle) * radius)-1.6);
}

glEnd();
glFlush();}

void lampPost(){
squareOne();

squareTwo();
squareThree();
semicircle();
}

void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer (background)
lampPost();
glFlush(); // Render now

/* Main function: GLUT runs as a console application starting at main() */

int main(int argc, char** argv) {

glutInit(&argc, argv); // Initialize GLUT

glutCreateWindow("OpenGL Setup"); // Create a window with the given title

glutInitWindowSize(720, 1080); // Set the window's initial width & height

glutDisplayFunc(display); // Register display callback handler for window re-paint


gluOrtho2D(-5,5,-5,5);
glutMainLoop(); // Enter the event-processing loop

return 0;

Output Screenshot (Full Screen)-


Question- 4

Draw a bench

Graph Plot (Picture)-

Code-

#include <windows.h> // for MS Windows

#include <GL/glut.h>
#include<math.h>
void squareOne(){
glBegin(GL_POLYGON);
glColor3f(0.9f, 1.0f, 1.0f);
glVertex2f(-0.9f, -2.8f);
glVertex2f(0.0f, -2.8f);
glVertex2f(0.0f, -3.0f);
glVertex2f(-0.9f, -3.0f);

glEnd();
}

void squareTwo(){
glBegin(GL_POLYGON);
glColor3f(0.7f, 1.0f, 1.0f);
glVertex2f(-0.9f, -3.0f);
glVertex2f(0.0f, -3.0f);
glVertex2f(-0.15f, -3.3f);
glVertex2f(-1.05f, -3.3f);

glEnd();
}

void squareThree(){
glBegin(GL_POLYGON);
glColor3f(0.8f, 0.4f, 0.2f);
glVertex2f(-1.05f, -3.3f);
glVertex2f(-1.0f, -3.3f);
glVertex2f(-1.0f, -3.5f);
glVertex2f(-1.05f, -3.5f);

glEnd();
}

void squareFour(){
glBegin(GL_POLYGON);
glColor3f(0.8f, 0.4f, 0.2f);
glVertex2f(-0.9f, -3.3f);
glVertex2f(-0.85f, -3.3f);
glVertex2f(-0.85f, -3.35f);
glVertex2f(-0.9f, -3.35f);
glEnd();
}

void squareFive(){
glBegin(GL_POLYGON);
glColor3f(0.8f, 0.4f, 0.2f);
glVertex2f(0.0f, -3.0f);
glVertex2f(0.0f, -3.15f);
glVertex2f(-0.05f, -3.15f);
glVertex2f(-0.05f, -3.1f);

glEnd();
}

void squareSix(){
glBegin(GL_POLYGON);
glColor3f(0.8f, 0.4f, 0.2f);
glVertex2f(-0.2f, -3.3f);
glVertex2f(-0.15f, -3.3f);
glVertex2f(-0.15f, -3.5f);
glVertex2f(-0.2f, -3.5f);

glEnd();
}

void bench(){
squareOne();

squareTwo();
squareThree();
squareFour();
squareFive();
squareSix();
}

void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer (background)
bench();
glFlush(); // Render now

/* Main function: GLUT runs as a console application starting at main() */

int main(int argc, char** argv) {

glutInit(&argc, argv); // Initialize GLUT

glutCreateWindow("OpenGL Setup"); // Create a window with the given title

glutInitWindowSize(720, 1080); // Set the window's initial width & height

glutDisplayFunc(display); // Register display callback handler for window re-paint


gluOrtho2D(-5,5,-5,5);
glutMainLoop(); // Enter the event-processing loop

return 0;

Output Screenshot (Full Screen)-


Question- 5

Use the building, tree, lamppost and bench to create a scenario

Graph Plot (Picture)-


Code-
#include <windows.h> // for MS Windows

#include <GL/glut.h>
#include<math.h>

void triangleOneB(){
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.9f, 1.0f);
glVertex2f(-1.4f, 3.4f);
glVertex2f(1.4f, 3.4f); // x, y
glVertex2f(0.0f, 4.0f); // x, y

glEnd();
}
void squareOneB(){
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.5f, 1.0f);
glVertex2f(-1.4f, 3.4f);
glVertex2f(-1.4f, 3.1f);
glVertex2f(1.4f, 3.1f);
glVertex2f(1.4f, 3.4f);

glEnd();
}

void squareTwoB(){
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.5f, 0.0f);
glVertex2f(-1.4f, 3.1f);
glVertex2f(-1.4f, -2.0f);
glVertex2f(1.4f, -2.0f);
glVertex2f(1.4f, 3.1f);

glEnd();
}

void squareThreeB(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.5f, 1.0f);
glVertex2f(-0.5f, -2.0f);
glVertex2f(0.5f, -2.0f);
glVertex2f(0.5f, -1.2f);
glVertex2f(-0.5f, -1.2f);

glEnd();
}

void squareFourB(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.0f, 1.0f);
glVertex2f(-0.4f, -2.0f);
glVertex2f(0.4f, -2.0f);
glVertex2f(0.4f, -1.3f);
glVertex2f(-0.4f, -1.3f);

glEnd();
}

void RectangleOneB(){
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.7f, 1.0f);
glVertex2f(-0.6f, -0.9f);
glVertex2f(-0.6f, -1.0f);
glVertex2f(0.6f, -1.0f);
glVertex2f(0.6f, -0.9f);

glEnd();
}

void RectangleTwoB(){
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.7f, 1.0f);
glVertex2f(-0.6f, 0.1f);
glVertex2f(-0.6f, 0.0f);
glVertex2f(0.6f, 0.0f);
glVertex2f(0.6f, 0.1f);

glEnd();
}

void RectangleThreeB(){
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.7f, 1.0f);
glVertex2f(-0.6f, 1.1f);
glVertex2f(-0.6f, 1.0f);
glVertex2f(0.6f, 1.0f);
glVertex2f(0.6f, 1.1f);

glEnd();
}

void RectangleFourB(){
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.7f, 1.0f);
glVertex2f(-0.6f, 2.1f);
glVertex2f(-0.6f, 2.0f);
glVertex2f(0.6f, 2.0f);
glVertex2f(0.6f, 2.1f);

glEnd();
}

void WindowOneB(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.0f, 1.0f);
glVertex2f(-0.4f, -0.9f);
glVertex2f(-0.4f, -0.5f);
glVertex2f(0.4f, -0.5f);
glVertex2f(0.4f, -0.9f);

glEnd();
}

void WindowTwoB(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.0f, 1.0f);
glVertex2f(-0.4f, 0.1f);
glVertex2f(-0.4f, 0.5f);
glVertex2f(0.4f, 0.5f);
glVertex2f(0.4f, 0.1f);

glEnd();
}

void WindowThreeB(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.0f, 1.0f);
glVertex2f(-0.4f, 1.1f);
glVertex2f(-0.4f, 1.5f);
glVertex2f(0.4f, 1.5f);
glVertex2f(0.4f, 1.1f);

glEnd();
}

void WindowFourB(){
glBegin(GL_POLYGON);
glColor3f(5.0f, 0.0f, 1.0f);
glVertex2f(-0.4f, 2.1f);
glVertex2f(-0.4f, 2.5f);
glVertex2f(0.4f, 2.5f);
glVertex2f(0.4f, 2.1f);

glEnd();
}
void Line1B(){
glBegin(GL_LINES);
glLineWidth(1);
glColor3ub(0,0,0);
glVertex2f(0.0f,-0.5f);
glVertex2f(0.0f, -0.9f); // x, y
glEnd();
}

void Line2B(){
glBegin(GL_LINES);
glLineWidth(1);
glColor3ub(0,0,0);
glVertex2f(0.0f,0.1f);
glVertex2f(0.0f, 0.5f); // x, y
glEnd();
}

void Line3B(){
glBegin(GL_LINES);
glLineWidth(1);
glColor3ub(0,0,0);
glVertex2f(0.0f,1.1f);
glVertex2f(0.0f, 1.5f); // x, y
glEnd();
}

void Line4B(){
glBegin(GL_LINES);
glLineWidth(1);
glColor3ub(0,0,0);
glVertex2f(0.0f,2.1f);
glVertex2f(0.0f, 2.5f); // x, y
glEnd();
}

void building(){
triangleOneB();
squareOneB();
squareTwoB();
squareThreeB();
squareFourB();
RectangleOneB();
RectangleTwoB();
RectangleThreeB();
RectangleFourB();
WindowOneB();
WindowTwoB();
WindowThreeB();
WindowFourB();
Line1B();
Line2B();
Line3B();
Line4B();
}

void squareOneT(){
glBegin(GL_POLYGON);
glColor3f(0.9f, 0.5f, 0.0f);
glVertex2f(3.0f, -2.2f);
glVertex2f(3.4f, -2.2f);
glVertex2f(3.4f, -4.0f);
glVertex2f(3.0f, -4.0f);

glEnd();
}

void triangleOneT(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.4f, -2.2f);
glVertex2f(3.4f, -1.8f); // x, y
glVertex2f(4.0f, -3.0f); // x, y

glEnd();
}

void triangleTwoT(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.4f, -1.8f);
glVertex2f(3.4f, -1.4f); // x, y
glVertex2f(4.6f, -2.8f); // x, y

glEnd();
}

void triangleThreeT(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.8f, -1.4f);
glVertex2f(3.4f, -1.4f); // x, y
glVertex2f(4.2f, -1.8f); // x, y

glEnd();
}

void triangleFourT(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(2.6f, -1.4f);
glVertex2f(3.8f, -1.4f); // x, y
glVertex2f(3.2f, -0.8f); // x, y

glEnd();
}

void triangleFiveT(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(2.6f, -1.4f);
glVertex2f(3.0f, -1.4f); // x, y
glVertex2f(2.2f, -1.8f); // x, y

glEnd();
}
void triangleSixT(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.0f, -1.4f);
glVertex2f(1.8f, -2.4f); // x, y
glVertex2f(3.0f, -1.8f); // x, y

glEnd();
}

void triangleSevenT(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.0f, -1.8f);
glVertex2f(2.2f, -3.0f); // x, y
glVertex2f(3.0f, -2.2f); // x, y

glEnd();
}

void squareTwoT(){
glBegin(GL_POLYGON);
glColor3f(0.1f, 0.5f, 0.1f);
glVertex2f(3.0f, -2.2f);
glVertex2f(3.4f, -2.2f);
glVertex2f(3.4f, -1.4f);
glVertex2f(3.0f, -1.4f);

glEnd();
}

void tree(){
squareOneT();
triangleOneT();
triangleTwoT();
triangleThreeT();
triangleFourT();
triangleFiveT();
triangleSixT();
triangleSevenT();
squareTwoT();
}

void squareOne(){
glBegin(GL_POLYGON);
glColor3f(0.9f, 1.0f, 1.0f);
glVertex2f(-3.0f, -1.4f);
glVertex2f(-2.8f, -1.4f);
glVertex2f(-2.8f, -4.0f);
glVertex2f(-3.0f, -4.0f);

glEnd();
}

void squareTwo(){
glBegin(GL_POLYGON);
glColor3f(0.9f, 1.0f, 1.0f);
glVertex2f(-2.8f, -1.4f);
glVertex2f(-3.6f, -1.4f);
glVertex2f(-3.6f, -1.5f);
glVertex2f(-2.8f, -1.5f);

glEnd();
}

void squareThree(){
glBegin(GL_POLYGON);
glColor3f(0.9f, 1.0f, 1.0f);
glVertex2f(-3.3f, -1.5f);
glVertex2f(-3.3f, -1.6f);
glVertex2f(-3.2f, -1.6f);
glVertex2f(-3.2f, -1.5f);

glEnd();
}

void semicircle(){
glBegin(GL_POLYGON);

glColor3f(0.85, 0.850, 0.10); // White color


// Define semi-circle
float radius = 0.1;
float pi = 3.14159265359;
for (int i = 0; i >= -180; i--) {
float angle = i * 2*pi / 180.0;
glVertex2f((cos(angle) * radius-3.25), (sin(angle) * radius)-1.6);
}

glEnd();
glFlush();}

void lampPost(){
squareOne();

squareTwo();
squareThree();
semicircle();
}

void squareOneE(){
glBegin(GL_POLYGON);
glColor3f(0.9f, 1.0f, 1.0f);
glVertex2f(-0.9f, -2.8f);
glVertex2f(0.0f, -2.8f);
glVertex2f(0.0f, -3.0f);
glVertex2f(-0.9f, -3.0f);

glEnd();
}

void squareTwoE(){
glBegin(GL_POLYGON);
glColor3f(0.7f, 1.0f, 1.0f);
glVertex2f(-0.9f, -3.0f);
glVertex2f(0.0f, -3.0f);
glVertex2f(-0.15f, -3.3f);
glVertex2f(-1.05f, -3.3f);
glEnd();
}

void squareThreeE(){
glBegin(GL_POLYGON);
glColor3f(0.8f, 0.4f, 0.2f);
glVertex2f(-1.05f, -3.3f);
glVertex2f(-1.0f, -3.3f);
glVertex2f(-1.0f, -3.5f);
glVertex2f(-1.05f, -3.5f);

glEnd();
}

void squareFourE(){
glBegin(GL_POLYGON);
glColor3f(0.8f, 0.4f, 0.2f);
glVertex2f(-0.9f, -3.3f);
glVertex2f(-0.85f, -3.3f);
glVertex2f(-0.85f, -3.35f);
glVertex2f(-0.9f, -3.35f);

glEnd();
}

void squareFiveE(){
glBegin(GL_POLYGON);
glColor3f(0.8f, 0.4f, 0.2f);
glVertex2f(0.0f, -3.0f);
glVertex2f(0.0f, -3.15f);
glVertex2f(-0.05f, -3.15f);
glVertex2f(-0.05f, -3.1f);

glEnd();
}

void squareSixE(){
glBegin(GL_POLYGON);
glColor3f(0.8f, 0.4f, 0.2f);
glVertex2f(-0.2f, -3.3f);
glVertex2f(-0.15f, -3.3f);
glVertex2f(-0.15f, -3.5f);
glVertex2f(-0.2f, -3.5f);

glEnd();
}

void bench(){
squareOneE();

squareTwoE();
squareThreeE();
squareFourE();
squareFiveE();
squareSixE();
}

void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer (background)

building();
tree();
lampPost();
bench();

glFlush(); // Render now

/* Main function: GLUT runs as a console application starting at main() */

int main(int argc, char** argv) {

glutInit(&argc, argv); // Initialize GLUT

glutCreateWindow("OpenGL Setup"); // Create a window with the given title

glutInitWindowSize(720, 1080); // Set the window's initial width & height

glutDisplayFunc(display); // Register display callback handler for window re-paint


gluOrtho2D(-5,5,-5,5);
glutMainLoop(); // Enter the event-processing loop

return 0;

Output Screenshot (Full Screen)-

You might also like