Wednesday, February 5, 2025
HomeAnimationSimple City Scenery Opengl Computer Graphics Project

Simple City Scenery Opengl Computer Graphics Project


This project uses different OpenGL functions to create different objects.

Coding for Sun

glLoadIdentity();
glBegin(GL_POLYGON);
glColor3ub(255.0f, 255.0f, 128.0f);
float angle10;
for (int i=0;i{
angle10=i*3.1416/180;
glVertex2f(0.0+0.12*cos(angle10),0.9+0.12*sin(angle10));

}
glEnd();

Coding for Moon

glLoadIdentity();
glBegin(GL_POLYGON);
glColor3ub(255, 255, 255);
GLfloat x5=.7f;
GLfloat y5=.7f;
GLfloat radius5 =.07f;
GLfloat twicePi5 = 2.0f * PI;
GLfloat triangleAmount5=100;
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x5, y5); // center of circle
for(int i = 0; i {
glVertex2f(
x5 + (radius5 * cos(i * twicePi5 / triangleAmount5)),
y5 + (radius5 * sin(i * twicePi5 / triangleAmount5))
);
}
glEnd();

Code for Airplane

glLoadIdentity();

glPushMatrix();
glScalef(0.4,0.4,0);
glTranslatef(0.0f,1.5f, 0.0f);
glTranslatef(position6, 0.0f, 0.0f);

glBegin(GL_POLYGON); // airplane outer body
glColor3ub(234, 229, 229); // white
glVertex2f(-0.3f, 0.2f);
glVertex2f(0.3f, 0.2f);
glVertex2f(0.4f, 0.3f);
glVertex2f(0.45f, 0.4f);
glVertex2f(0.45f, 0.5f);
glVertex2f(0.3f, 0.4f);
glVertex2f(0.0f, 0.4f);
glVertex2f(-0.2f, 0.4f);
glVertex2f(-0.3f, 0.4f);
glVertex2f(-0.35f, 0.38f);
glVertex2f(-0.4f, 0.3f);
glVertex2f(-0.35f, 0.23f);
glVertex2f(-0.3f, 0.2f);
glEnd();
glBegin(GL_POLYGON); // airplane front window
glColor3ub(117, 69, 160); // purple one
glVertex2f(-0.37f, 0.35f);
glVertex2f(-0.32f, 0.35f);
glVertex2f(-0.3f, 0.36f);
glVertex2f(-0.3f, 0.38f);
glVertex2f(-0.35f, 0.38f);
glEnd();
glBegin(GL_LINES); // airplane front window
glColor3ub(255, 255, 255); // white
glVertex2f(-0.35f, 0.35f);
glVertex2f(-0.33f, 0.38f);
glVertex2f(-0.33f, 0.35f);
glVertex2f(-0.31f, 0.38f);
glEnd();
glBegin(GL_LINES); // airplane front door
glColor3ub(144, 126, 181); // purple one
glVertex2f(-0.25f, 0.26f);
glVertex2f(-0.23f, 0.24f);
glVertex2f(-0.23f, 0.24f);
glVertex2f(-0.18f, 0.24f);
glVertex2f(-0.18f, 0.24f);
glVertex2f(-0.16f, 0.26f);
glVertex2f(-0.16f, 0.26f);
glVertex2f(-0.16f, 0.36f);
glVertex2f(-0.16f, 0.36f);
glVertex2f(-0.18f, 0.38f);
glVertex2f(-0.18f, 0.38f);
glVertex2f(-0.23f, 0.38f);
glVertex2f(-0.23f, 0.38f);
glVertex2f(-0.25f, 0.36f);
glVertex2f(-0.25f, 0.36f);
glVertex2f(-0.25f, 0.26f);
glEnd();
glBegin(GL_QUADS); // Airplane front wind
glColor3ub(117, 69, 160); // purple one
glVertex2f(0.02f, 0.15f);
glVertex2f(0.05f, 0.15f);
glVertex2f(-0.03f, 0.26f);
glVertex2f(-0.1f, 0.26f);
glEnd();
glBegin(GL_QUADS); // Airplane back wind
glColor3ub(117, 69, 160); // purple one
glVertex2f(-0.08f, 0.4f);
glVertex2f(0.0f, 0.4f);
glVertex2f(0.07f, 0.49f);
glVertex2f(0.04f, 0.49f);
glEnd();
// Airplane window
glColor3ub(117, 69, 160); // purple one
GLfloat x2=-0.09f;
GLfloat y2=0.35f;
GLfloat radius1 =.02f;
int triangleAmount1 = 100;
GLfloat twicePi1 = 2.0f * PI;
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x2, y2); // center of circle
for(int i = 0; i {
glVertex2f(
x2 + (radius1 * cos(i * twicePi1 / triangleAmount1)),
y2 + (radius1 * sin(i * twicePi1 / triangleAmount1))
);
}
glEnd();
// Airplane window
glColor3ub(117, 69, 160); // purple one
GLfloat x3=-0.02f;
GLfloat y3=0.35f;
radius1 =.02f;
twicePi1 = 2.0f * PI;
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x3, y3); // center of circle
for(int i = 0; i {
glVertex2f(
x3 + (radius1 * cos(i * twicePi1 / triangleAmount1)),
y3 + (radius1 * sin(i * twicePi1 / triangleAmount1))
);
}
glEnd();
// Airplane window
glColor3ub(117, 69, 160); // purple one
GLfloat x4=0.06f;
GLfloat y4=0.35f;
radius1 =.02f;
twicePi1 = 2.0f * PI;
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x4, y4); // center of circle
for(int i = 0; i {
glVertex2f(
x4 + (radius1 * cos(i * twicePi1 / triangleAmount1)),
y4 + (radius1 * sin(i * twicePi1 / triangleAmount1))
);
}
glEnd();

glPopMatrix();

Code for Birds

glLoadIdentity();
glPushMatrix();
glTranslatef(position5,0.0f, 0.0f);
glBegin(GL_POLYGON);
glColor3ub(0.0, 0.0, 0.0);
float angle41;
for (int i=0;i{
angle41=i*3.1416/180;
glVertex2f(0.8+0.04*cos(angle41),0.7+0.02*sin(angle41));

}
glEnd();

glBegin(GL_POLYGON);
glColor3ub(0.0, 0.0, 0.0);
float angle42;
for (int i=0;i{
angle42=i*3.1416/180;
glVertex2f(0.75+0.02*cos(angle42),0.71+0.02*sin(angle42));

}
glEnd();

glBegin(GL_POLYGON);
glColor3ub(255.0, 255.0, 255.0);
float angle43;
for (int i=0;i{
angle43=i*3.1416/180;
glVertex2f(0.74+0.005*cos(angle43),0.71+0.005*sin(angle43));

}
glEnd();
//wing

glBegin(GL_TRIANGLES);
glColor3ub(255.0, 255.0, 255.0);
glVertex2f(0.8f,0.75f);
glVertex2f(0.79,0.71f);
glVertex2f(0.785f,0.8f);
glEnd();

//lip
glBegin(GL_TRIANGLES);
glColor3ub(255.0, 0.0, 0.0);
glVertex2f(0.73f,0.72f);
glVertex2f(0.69f,0.71f);
glVertex2f(0.73f,0.70f);
glEnd();

In our Simple City Scenery opengl computer graphics program we have used three birds. You can use many birds you like, just adjust the coordinate of thier body so they fit in the scene. Code for the bird will be common for all just need some tweak in the coordinates.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments

Skip to toolbar