Assignment 01 Haider Ali 2679
Assignment 01 Haider Ali 2679
Assignment 01 Haider Ali 2679
Assignment 01
Title
Computer Graphics
Scene Description:
Bench: A simple rectangle for the seat and vertical lines for the legs.
Lamppost: A tall vertical rectangle for the post with a circle for the lamp.
Bird: A simple V-shaped bird in the sky.
River: A long curving line for the river.
Mountain: Triangular mountains in the background.
Code OPENGL
#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
void drawLamppost();
void drawBirds();
void drawBench();
void drawHouses();
void drawBoats();
void drawRiver();
void drawSun();
void drawTrees();
void drawMountain();
void ground();
void mydisplay() {
glClear(GL_COLOR_BUFFER_BIT);
ground();
drawRiver();
drawMountain();
drawHouses();
drawTrees();
drawBoats();
drawSun();
drawBench();
drawLamppost();
drawBirds();
glFlush();
}
void drawBench() {
// Bench seat (rectangle)
glColor3f(0.6, 0.3, 0.0);
glBegin(GL_POLYGON);
glVertex2i(170, 55);
glVertex2i(200, 55);
glVertex2i(200, 65);
glVertex2i(170, 65);
glEnd();
void drawLamppost() {
// Post (rectangle)
glColor3f(0.4, 0.4, 0.4);
glBegin(GL_POLYGON);
glVertex2i(175, 70); // Base of the post
glVertex2i(178, 70);
glVertex2i(178, 85); // Top of the post
glVertex2i(175, 85);
glEnd();
void drawBirds() {
glColor3f(0.0, 0.0, 0.0);
glLineWidth(1.0);
// First bird
glBegin(GL_LINES);
glVertex2i(30, 150);
glVertex2i(35, 145);
glVertex2i(35, 145);
glVertex2i(40, 150);
glEnd();
// Second bird
glBegin(GL_LINES);
glVertex2i(45, 160);
glVertex2i(50, 155);
glVertex2i(50, 155);
glVertex2i(55, 160);
glEnd();
// Third bird
glBegin(GL_LINES);
glVertex2i(60, 145);
glVertex2i(65, 140);
glVertex2i(65, 140);
glVertex2i(70, 145);
glEnd();
glFlush();
}
void drawHouses() {
// First house (blue roof, yellow door, purple walls)
glColor3f(0.0, 0.0, 1.0); // Blue roof
glBegin(GL_POLYGON);
glVertex2i(50, 70);
glVertex2i(75, 100);
glVertex2i(100, 70);
glEnd();
void drawBoats() {
// First boat (black base, red top)
glColor3f(0.0, 0.0, 0.0); // Black base
glBegin(GL_POLYGON);
glVertex2i(50, 20);
glVertex2i(70, 20);
glVertex2i(65, 15);
glVertex2i(55, 15);
glEnd();
void drawRiver() {
// Blue river
glColor3f(0.0, 0.5, 1.0);
glBegin(GL_POLYGON);
glVertex2i(0, 0);
glVertex2i(200, 0);
glVertex2i(200, 30);
glVertex2i(0, 30);
glEnd();
}
void drawSun() {
// Sun as a simple ellipse shape
glColor3f(1.0, 0.5, 0.0);
glBegin(GL_POLYGON);
glVertex2i(160, 170); // Top
glVertex2i(150, 180); // Left
glVertex2i(160, 190); // Bottom
glVertex2i(170, 180); // Right
glEnd();
}
void drawTrees() {
// Tree next to the left side of the first house
void drawMountain() {
// Mountains above both houses
glColor3f(0.6, 0.3, 0.0);
void ground() {
// Green ground
glColor3f(0.8078, 0.9490, 0.6824);
glBegin(GL_POLYGON);
glVertex2i(0, 30);
glVertex2i(200, 30);
glVertex2i(200, 100);
glVertex2i(0, 100);
glEnd();
}
void MyInit() {
glClearColor(0.5, 0.8, 1.0, 1.0); // Light blue background for sky
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 200.0, 0.0, 200.0);
}