Search Projects

Wednesday, June 18, 2025

Opengl Computer Graphics Projects on Solar Energy Solar Power

  

We are going to get started Opengl Computer Graphics Projects on Solar Power/Solar Energy.

 

Abstract

The Main aim of this Mini OpenGL Project is to illustrate/demonstrate the working principle of Solar power/Solar Energy using the concepts and usage of pre-built functions in OpenGL.
 
In this we are going to demo Solar power using OpenGL. During day electricity is generated through solar panels which are set in fields called as solar farms and is transmitted to near by homes and excess is stored in a power station. During night the power station supplies the stored power to homes. We have used input devices like mouse and key board to interact with in the OpenGL C/C++ program.

Solar Power


Solar power is the power or say energy generated by conversion of sunlight into electricity using solar panels. For Generating energy or power these panels (Solar Panels), uses the photovoltaic cells in them which, convert light into direct current (DC). The DC, afterwards converted to alternating current (AC) for further use in electricity supply or to grid connection, or for storage in batteries. This is  a renewable, green, clean energy source, with many advantages , helps in minimizing greenhouse gas emissions during operation and save plane from Global warming





1. The Basics

We are going to code this OpenGL C/C++ program using MS Visual Studio, you are free to use other IDE like Code Block, Dev C++ etc.

First we are going to develop front page where user will input their interaction to start the program. A help screen will also create for getting the information or usage. User will have choice and program will accordingly.

We will implement various primitive functions for creating the square, rectangle and circle shape for create the diagram require for the demo of this Opengl Computer Graphics Projects on Solar Energy.

2. Implementation


2. 1 Various functions used in this program.
 glutInit() : interaction between the windowing system and OPENGL is
initiated
 glutInitDisplayMode() : used when double buffering is required and depth
information is required
 glutCreateWindow() : this opens the OPENGL window and displays the title
at top of the window
 glutInitWindowSize() : specifies the size of the window
 glutInitWindowPosition() : specifies the position of the window in screen
co-ordinates
 glutKeyboardFunc() : handles normal ascii symbols
 glutSpecialFunc() : handles special keyboard keys
 glutReshapeFunc() : sets up the callback function for reshaping the window
 glutIdleFunc() : this handles the processing of the background
 glutDisplayFunc() : this handles redrawing of the window
 glutMainLoop() : this starts the main loop, it never returns
 glViewport() : used to set up the viewport
 glVertex3fv() : used to set up the points or vertices in three dimensions
 glColor3fv() : used to render color to faces
 glFlush() : used to flush the pipeline
glutPostRedisplay() : used to trigger an automatic redrawal of the object
 glMatrixMode() : used to set up the required mode of the matrix
 glLoadIdentity() : used to load or initialize to the identity matrix
 glTranslatef() : used to translate or move the rotation centre from one
point to another in three dimensions
glRotatef() : used to rotate an object through a specified rotation angle
This program Opengl Computer Graphics Projects on Solar Energy Solar Power includes following interaction through keyboard.

S->  Toggle Day or night
H-> Get Help Menu
Q-> Quit

4. Source Code


The complete Source code of this Opengl Computer Graphics project can be found in the below. Please Let Us know about your opinion, feedback, question, doubt or any other queries in the comments section below.

void draw(){
if(day){
glClearColor(0.9,0.9,0.9,0.0);
}else{
glClearColor(0.3,0.3,0.3,0.0);
}

glPushMatrix();
glRotatef(angle,1,0,0);
glTranslatef(-10,20,-155);
glScaled(1,1,0.6);
if(day){
glColor3f(1,1,0);
}else{
glColor3f(1,1,1);
}
glutSolidSphere(5,100,100);
glPopMatrix();
glPushMatrix();
glTranslatef(0,-10,5);
glScaled(500,10,1000);
glColor3f(0.8,0.7,0.7);
glutSolidCube(1);
glPopMatrix();

drawHouse(-3,0,-55);
drawHouse(-4,0,-35);
drawHouse(-5,0,-15);
drawHouse(-10,0,-15);
//Solar Panels
for(int i=-1;i<3;i++)
{
for(int j=5;j>-2;j--)
drawSolarPanel(i*2,1,j);
}
//draw power station.
stroke_output(0.8,1.8,"Power Station");
// transformer

glPushMatrix();
glTranslatef(15,5,-100);
//glScaled(0,2,0.2);
glColor3f(1,0.3,0.3);
glutSolidCube(15);
glPopMatrix();
//Transformer Power levels
// y axis from 5 to 18 and show growth in one second delay
if(day){
if(grow<=15000){
grow++;
angle+=0.002;
}
}
else{
if(grow>=0){
grow--;
angle-=0.002;
}
}
if(grow>1000){
glPushMatrix();
glTranslatef(14.8,-2,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();
}
if(grow>2000){
glPushMatrix();
glTranslatef(14.8,-1,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();
}
if(grow>3000){
glPushMatrix();
glTranslatef(14.8,0,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();
}
if(grow>4000){
glPushMatrix();
glTranslatef(14.8,1,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();
}
if(grow>5000){
glPushMatrix();
glTranslatef(14.8,2,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();
}
if(grow>6000){
glPushMatrix();
glTranslatef(14.8,3,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();

}
if(grow>7000){
glPushMatrix();
glTranslatef(14.8,4,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();
}
if(grow>8000){
glPushMatrix();
glTranslatef(14.8,5,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();

}
if(grow>9000){
glPushMatrix();
glTranslatef(14.8,6,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();
}
if(grow>10000){
glPushMatrix();
glTranslatef(14.8,7,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();

}
if(grow>11000){
glPushMatrix();
glTranslatef(14.8,8,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();
}
if(grow>12000){
glPushMatrix();
glTranslatef(14.8,9,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();

}
if(grow>13000){
glPushMatrix();
glTranslatef(14.8,10,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();
}
if(grow>14000){
glPushMatrix();
glTranslatef(14.8,11,-99.8);
glScaled(1,0.05,1);
glColor3f(1,1,0);
glutSolidCube(15);
glPopMatrix();

}
if(grow>15000){
}
}

void doDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
// Write your Own Code Here
if(help1){
help();
}
else
{
draw();
}
GLfloat mat_ambient[]={0.0f,1.0f,2.0f,1.0f};
GLfloat mat_diffuse[]={0.0f,1.5f,.5f,1.0f};
GLfloat mat_specular[]={5.0f,1.0f,1.0f,1.0f};
GLfloat mat_shininess[]={100.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
/*GLfloat lightIntensity[]={3.7f,0.7f,0.7f,1.0f}; Orange
GLfloat light_position[]={2.0f,5.0f,3.0f,1.0f};*/
/*light source properties*/
//if(day){
GLfloat lightIntensity[]={1.7f,1.7f,1.7f,1.0f};
GLfloat light_position[]={2.0f,0.0f,0.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
GLfloat light_position2[]={0.0f,0.0f,8.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position2);
GLfloat light_position3[]={0.0f,5.0f,15.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position3);
glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);
/*}else{
GLfloat lightIntensity[]={0.7f,0.7f,0.7f,0.5f};
GLfloat light_position[]={2.0f,0.0f,0.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
GLfloat light_position2[]={0.0f,0.0f,8.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position2);
GLfloat light_position3[]={0.0f,2.0f,2.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position3);
glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);
}*/
glFlush();
glutSwapBuffers();
}
void mykey(unsigned char key,int x,int y)
{
if(key=='q'||key=='Q')
{
exit(0);
}
if(key=='h'||key=='H')
{
help1=!help1;
glutPostRedisplay();
}
if(key=='s' || key=='S'){
if(day){
day=false;
}else{
day=true;
}
glutPostRedisplay();
glutIdleFunc(doDisplay);
}
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(0,0);
glutCreateWindow("Solar power");
glutDisplayFunc(doDisplay);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glutKeyboardFunc(mykey);
doInit();
glutMainLoop();
return 0;
}


Sunday, April 27, 2025

Create OpenGL CG Projects on Networking Data Communication

We have developed Selective Repeat ARQ a networking based Create OpenGL CG Projects with C/C++. In this post we are going to create new networking based project. As well aware of Internet which help us communicate through various means including mail, chat and social media. We are going to create OpenGL Project on Networking Data Communication. Let's get started with some basics information. 

Abstract - 


Our Aim is to Create, design and the illustrate the concepts and usage of Data Communication over Internet Using OpenGL C/C++. The Communication between two devices begins with a message/information of which one send the message and other receive it. The first device is called source, or sender while the second device i is the destination/receiver, of the message. The destination receives the message and interprets it. Another element involved in the process is called channel, which consists of the media that provides the pathway over which the message can travel from source to destination.


This program is implemented using various OpenGL functions which are shown below

Various functions used in this program.
  • glutInit() : interaction between the windowing system and OPENGL is initiated
  • glutInitDisplayMode() : used when double buffering is required and depth information is required
  • glutCreateWindow() : this opens the OPENGL window and displays the title at top of the window
  • glutInitWindowSize() : specifies the size of the window
  • glutInitWindowPosition() : specifies the position of the window in screen co-ordinates
  • glutKeyboardFunc() : handles normal ASCII symbols
  • glutSpecialFunc() : handles special keyboard keys
  • glutReshapeFunc() : sets up the callback function for reshaping the window
  • glutIdleFunc() : this handles the processing of the background
  • glutDisplayFunc() : this handles redrawing of the window
  • glutMainLoop() : this starts the main loop, it never returns
  • glViewport() : used to set up the viewport
  • glVertex3fv() : used to set up the points or vertices in three dimensions
  • glColor3fv() : used to render color to faces
  • glFlush() : used to flush the pipeline
  • glutPostRedisplay() : used to trigger an automatic redrawal of the object
  • glMatrixMode() : used to set up the required mode of the matrix
  • glLoadIdentity() : used to load or initialize to the identity matrix
  • glTranslatef() : used to translate or move the rotation centre from one point to another in three dimensions
  • glRotatef() : used to rotate an object through a specified rotation angle

Interactions

Interaction with program We can have an interaction with this project using popular input device like mouse and key board are used to interact with this program. Some keys of key board have specific function, we mentioned them below,
  1. ‘s/S’ - Start
  2. ‘n/N’ – Network
  3. ‘a/A’ – About Project
With these above mentioned keys, we can interact with the program. Also we can interact with this program by using mouse (input device), By click on right and left button On right click of mouse menu will occur. Select the option by left click of mouse.




#include
#include
#include
#include
#include
#include 
static double x=0.0,x1=-3.0,x2=3.0,y1=0.0,y2=0;
static double x8=-4.0,x9=4.0,y8=1.0,y9=1;
static double move=-60;
static bool pca2pcb=false,pca2rt=false,rt2pca=false, pcb2pca=false, local=false,
dubai=false;
void P();
void d();
void *font;
void *currentfont;
void setFont(void *font)
{
currentfont=font;
}
void drawstring(float x,float y,float z,char *string)
{
char *c;
glRasterPos3f(x,y,z);
for(c=string;*c!='\0';c++)
{ glColor3f(0.0,1.0,1.0);
glutBitmapCharacter(currentfont,*c);
}
}
void stroke_output(GLfloat x, GLfloat y, char *format,...)
{ va_list args;
char buffer[200], *p;
va_start(args, format);
vsprintf(buffer, format, args);
va_end(args);
glPushMatrix();
DATA COMMUNICATION over INTERNET
11 Dept. of Computer Science & Engineering.
glTranslatef(-2.5, y, 0);
glScaled(0.003, 0.005, 0.005);
for (p = buffer; *p; p++)
glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);
glPopMatrix();
}
//Windows
void window(float x4, float y4)
{
glLoadIdentity();
glColor3f(1.0,1.5,0.5);
glTranslatef(0.0f,0.0f,-11.0f);
for(float j=-2;j<1 .5="" 12="" change="" color="" communication="" computer="" computers="" condition="" data="" dept.="" engineering.="" f="" float="" for="" glcolor3f="" glloadidentity="" glpopmatrix="" glpushmatrix="" glrotatef="" glscaled="" gltranslatef="" glutsolidcube="" glutsolidtorus="" i="" if="" indows="" internet="" j="" of="" ondition="" outer="" over="" pc="" pca="" pcb2pca="" pcb="" router="" science="" to="" void="" window1="" x5="" x6="" x7="=5)" x9="" y5="" y6="" y7="" z7="">=-5 && x9<=-4 && x7==-5)
glColor3f(1,0,0);
glScaled(.7,.7,0);
glRotatef(95,1.0f,0.0f,0.0f);
glTranslatef(x7,y7,z7);
DATA COMMUNICATION over INTERNET
13 Dept. of Computer Science & Engineering.
glutSolidCube(.85);
glPopMatrix();
glPopMatrix();
}
//PC
void cpu(float x7, float y7, float z7)
{ glLoadIdentity();
glColor3f(0.5,0.5,.5);
glTranslatef(0.0f,0.0f,-13.0f);
glPushMatrix();
glPushMatrix();
glScaled(1,.3,0);
glRotatef(95,1.0f,0.0f,0.0f);
glTranslatef(x7,y7,z7);
glutSolidCube(1);
glPopMatrix();
glPushMatrix();
glColor3f(1,1,1);
glScaled(1,.3,0);
glRotatef(95,1.0f,0.0f,0.0f);
glTranslatef(x7,y7,z7);
glutSolidCube(.4);
glPopMatrix();
glPopMatrix();
}
//Draw LAN/WAN
void lan(double x8,double y8)
{
glClearColor(0.6,0.5,.5,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
router(0,-1);
//Data Media (connected to Router)
glPushMatrix();
DATA COMMUNICATION over INTERNET
14 Dept. of Computer Science & Engineering.
glTranslatef(0.0,1.0,-2.0);
glScaled(0.1,5.0,0.1);
glColor3f(1,1,1);
glutWireCube(1.5);
glPopMatrix();
glPushMatrix();
glTranslatef(0.0,0.0,-2.0);
glScaled(5.1,0.1,0.1);
glColor3f(1,1,1);
glutWireCube(1.5);
glPopMatrix();
glPushMatrix();
glTranslatef(0.0,0.0,-2.0);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(1,3.5,-1.0,"ROUTER");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-4.6,.5,-1.0,"PC-A");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-.5,.5,-1.0,"SWITCH");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(4,.5,-1.0,"PC-B");
glPopMatrix();
//Data Transfer
if(pca2pcb){
// data
glPushMatrix();
glTranslatef(x8,y8,-2.0);
glScaled(0.1,0.1,0.1);
glColor3f(x8,0,1);
glutSolidCube(1);
glPopMatrix();
if(x8>=4){
DATA COMMUNICATION over INTERNET
15 Dept. of Computer Science & Engineering.
pcb2pca=true;
pca2pcb=false;
} }
//Ack
if(pcb2pca){
glPushMatrix();
glTranslatef(x8,y8,-2.0);
glScaled(0.1,0.1,0.1);
glColor3f(x8,0,1);
glutSolidCube(1);
glPopMatrix();
}
if(pca2rt)
{
glPushMatrix();
glTranslatef(x8,y8,-2.0);
glScaled(0.1,0.1,0.1);
glColor3f(x8,0,1);
glutSolidCube(1);
glPopMatrix();
}
// move the packet out of LAN
if(pca2rt && rt2pca==false && y8>=6)
{
glutIdleFunc(P);
}
//switch
glPushMatrix();
glColor3f(0.5,0.5,1.5);
glTranslatef(0.0,0,1.0);
glRotatef(15,1.0f,0.0f,0.0f);
glScaled(1.2,0.2,1.0);
glutSolidCube(1);
glPopMatrix();
pc(-5,1,0);
cpu(-3.5,7,1.5);
DATA COMMUNICATION over INTERNET
16 Dept. of Computer Science & Engineering.
pc(5,1,0);
cpu(3.5,7,1.5);
pc(0,20,2);
cpu(0,105,1.5);
glFlush();
glutSwapBuffers();
}
// Draw Network
void network(double ang,double x1,double x2,double y1,double y2)
{
glClearColor(0.0,0.85,1,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
glBegin(GL_POLYGON);
glColor3f(0.0,1.8,0.0);
glVertex2f(-10,0);
glVertex2f(10,0);
glVertex2f(-10,-10);
glVertex2f(-10,10);
glEnd();
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-4.2,2.65,0.0,"LOCAL BUILDING");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-1.5,3.2,0.0,"EARTH Connected with Fibric Wires");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(2.5,2.65,0.0,"DUBAI BUILDING");
//Earth
glPushMatrix();
glColor3f(0.5,0.5,1.5);
glScaled(0.8,1,0.8);
glTranslatef(0.0,2.2,0.0);
glRotatef(ang,0.0f,-1.0f,0.0f);
DATA COMMUNICATION over INTERNET
17 Dept. of Computer Science & Engineering.
glutSolidSphere(1,20,20);
glPopMatrix();
//Building A
glLoadIdentity();
glTranslatef(0.0f,0.0f,-12.0f);
glPushMatrix();
glTranslatef(-3,-0.5,0.0);
glScaled(0.8,2.2,0.8);
glutSolidCube(1.8);
glPopMatrix();
window(-2.6, 1);
//Building B
glLoadIdentity();
glTranslatef(0.0f,0.0f,-12.0f);
glPushMatrix();
glTranslatef(3,-0.5,0.0);
glScaled(0.8,2.2,0.8);
glutSolidCube(1.8);
glPopMatrix();
window1(3.3, 1);
// Line 1
glPushMatrix();
glTranslatef(-3.0,1.0,-2.0);
glScaled(0.1,3.0,0.1);
glColor3f(1,1,1);
glutWireCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(-1.45,2.4,-2.0);
glScaled(3.0,0.2,0.1);
glColor3f(1,1,1);
glutWireCube(1);
glPopMatrix();
//Line 2
glPushMatrix();
DATA COMMUNICATION over INTERNET
18 Dept. of Computer Science & Engineering.
glTranslatef(3.0,1.0,-2.0);
glScaled(0.1,3.0,0.1);
glColor3f(1,1,1);
glutWireCube(1);
glPopMatrix();
glPushMatrix();
glTranslatef(1.45,2.4,-2.0);
glScaled(3.0,0.2,0.1);
glColor3f(1,1,1);
glutWireCube(1);
glPopMatrix();
// Transmission of Datapackets
glPushMatrix();
// Send Packets
if(local){
if(x1==-3 && y1<=2.38)
glTranslatef(-3,y1,-2.0);
if(y1>=2.38 && x1<=3)
glTranslatef(x1,2.38,-2.0);
if(x1>=3 && y1>=0)
glTranslatef(3,y1,-2.0);
if(x1>=3 && y1<=0.0)
{
dubai=true;
local=false;
} }
// Ack packets
if(dubai)
{
if(x2>=3 && y2<=2.38)
glTranslatef(3,y2,-2.0);
if(y2>=2.38 && x2>=-3)
glTranslatef(x2,2.38,-2.0);
if(x2<=-3 && y2>=0.0)
glTranslatef(-3,y2,-2.0);
if(x2<=-3 && y2<=0.0)
DATA COMMUNICATION over INTERNET
19 Dept. of Computer Science & Engineering.
{
dubai=false;
local=true;
rt2pca=true;
x8=0;
y8=6;
glutIdleFunc(d);
} }
glScaled(0.1,0.1,0.1);
glColor3f(1,1,1);
glutSolidCube(1);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void building(double ang)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
glPushMatrix();
glScaled(0.3,1.5,0.3);
glRotatef(90,1.0f,0.0f,0.0f);
glTranslatef(8.5,0,-0.5);
glutSolidTorus(0.2,1.0,40,40);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void about()
{
glClearColor(0.0,0.85,1,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
DATA COMMUNICATION over INTERNET
20 Dept. of Computer Science & Engineering.
glColor3f(0,0,0);
drawstring(-4.2,2,0.0,"About Data Communication");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-3.5,1.5,0.0,"1. Data Communications refers to the exchange of
data between two devices via some");
glColor3f(0,0,0);
drawstring(-3.5,1,0.0," form of transmission medium such as a wire
cable.");
glColor3f(0,0,0);
drawstring(-3.5,.5,0.0,"2. Similarly data and information from one computer
system can be transmitted to");
glColor3f(0,0,0);
drawstring(-3.5,0.0,0.0," other systems across geographical areas.");
glColor3f(0,0,0);
drawstring(-3.5,-0.5,0.0,"3. Thus data transmission is the movement of
information using some standard methods.");
glColor3f(0,0,0);
drawstring(-3.5,-1,0.0,"4. The effectiveness of a data communications
system depends on");
glColor3f(0,0,0);
drawstring(-3.5,-1.5,0.0," four fundamental characteristics: delivery,
accuracy, timeliness, and jitter.");
glColor3f(0,0,0);
drawstring(-3.5,-2,0.0,"5. A network is two or more devices connected
through links.");
glColor3f(0,0,0);
drawstring(-3.5,-2.5,0.0,"6. A link is a communications pathway that
transfers data from one device to another.");
glColor3f(0,0,0);
drawstring(-3.5,-3,0.0,"7. Type of Connection : Point-to-Point &
Multipoint.");
glFlush();
glutSwapBuffers();
}
void s()
DATA COMMUNICATION over INTERNET
21 Dept. of Computer Science & Engineering.
{
lan(-4,1);
}
void n()
{
x-=0.07;
network(x,0,0,0,0);
}
void P()
{
if(local)
{
if(x1==-3 && y1<=2.38){
y1+=0.01;
}
if(y1>=2.38 && x1<=3.0)
{ x1+=0.01;
}
if(x1>=3 && y1>=0.0){
y1-=0.01;
}
x+= .07;
network(x,x1,x2,y1,y2);
}
//Dubai to local
if(dubai)
{
if(x2>=3 && y2<=2.38)
y2+=0.01;
if(y2>=2.38 && x2>=-3)
x2-=0.01;
if(x2<=-3 && y2>=0.0)
y2-=0.01;
x+= .07;
network(x,x1,x2,y1,y2);
} }
DATA COMMUNICATION over INTERNET
22 Dept. of Computer Science & Engineering.
void d()
{
if(pca2pcb)
{ if(x8>=-4 && x8<=4){
x8+=0.01;
}
lan(x8,0);
}
if(pcb2pca)
{
if(x9<=4 && x9>=-4){
x9-=0.01;
}
lan(x9,0);
}
// To Dubai
if(pca2rt & rt2pca==false)
{
if(x8>=-4 && y8<=6){
if(x8<=0)
{x8+=0.01;
}
if(x8>=0 && y8<=6)
{
y8+=0.01;
}
}
lan(x8,y8);
}
if(rt2pca)
{
if(x8<=0 && y8<=6){
if(y8>=0)
{y8-=0.01;
}
if(x8>=-4 && y8<=0)
DATA COMMUNICATION over INTERNET
23 Dept. of Computer Science & Engineering.
{
x8-=0.01;
} }
lan(x8,y8);
} }
void doInit()
{
/* Background and foreground color */
glClearColor(0.0,0.0,0.0,0);
glViewport(0,0,640,480);
/* Select the projection matrix and reset it then
setup our view perspective */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0f,(GLfloat)640/(GLfloat)480,0.1f,200.0f);
/* Select the modelview matrix, which we alter with rotatef() */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearDepth(2.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
}
void display()
{
glClearColor(0.1,0.1,0.5,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(3.0,1.0,1.0);
drawstring(-1.5,3.0,0.0,"DEPARTMENT OF COMPUTER SCIENCE");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.0,1.0,1.0);
drawstring(-3.0,2.5,0.0,"Computer Graphics Mini Project on DATA
COMMUNICATION IN NETWORK");
DATA COMMUNICATION over INTERNET
24 Dept. of Computer Science & Engineering.
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.0,1.0,1.0);
drawstring(-1,2,0,"Using OPENGL");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.0,1.0,1.0);
drawstring(-0.5,1.5,0,"By");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.0,1.0,1.0);
drawstring(-2,1,0,"BUSHRA JABEEN (USN : 3KB10CS022)");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.0,1.0,1.0);
drawstring(-2,.5,0,"BUSHRA SULTANA (USN : 3KB10CS023)");
stroke_output(-2.0, -1, "s --> Start");
stroke_output(-2.0, -1.75, "A --> About");
stroke_output(-2.0, -3,"q --> Quit");
GLfloat mat_ambient[]={0.0f,1.0f,2.0f,1.0f};
GLfloat mat_diffuse[]={0.0f,1.5f,.5f,1.0f};
GLfloat mat_specular[]={5.0f,1.0f,1.0f,1.0f};
GLfloat mat_shininess[]={50.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
GLfloat lightIntensity[]={1.7f,1.7f,1.7f,1.0f};
GLfloat light_position3[]={0.0f,5.0f,5.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position3);
glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);
glEnable(GL_COLOR_MATERIAL);
glFlush();
glutSwapBuffers();
}
void menu(int id)
{
switch(id)
{
case 1:glutIdleFunc(about);
DATA COMMUNICATION over INTERNET
25 Dept. of Computer Science & Engineering.
break;
case 2:glutIdleFunc(s);
break;
case 3:glutIdleFunc(d);
break;
case 4:glutIdleFunc(P);
break;
case 5:glutIdleFunc(n);
break;
case 6:
pca2pcb=true;
x8=-4;
glutIdleFunc(d);
break;
case 7:
local=true;
dubai=false;
pca2rt=true;
x8=-4.0;x9=4.0;y8=0.0; y9=0;
pca2pcb=false;
pcb2pca=false;
glutIdleFunc(d);
break;
case 8: pca2rt=false;
pca2pcb=false;
x8=-4.0;x9=4.0;y8=1.0; y9=0;
x=0.0;x1=-3.0;x2=3.0;y1=0.0;y2=2.38;
pca2pcb=false;pca2rt=false; pcb2pca=false;
glutIdleFunc(s);
break;
case 9:exit(0);
break;
}
glFlush();
glutSwapBuffers();
glutPostRedisplay();
DATA COMMUNICATION over INTERNET
26 Dept. of Computer Science & Engineering.
}
void mykey(unsigned char key,int x,int y)
{
if(key=='s')
{
glutIdleFunc(s);
}
if(key=='n')
{
glutIdleFunc(n);
}
if(key=='P')
{
glutIdleFunc(P);
}
if(key=='A')
{
glutIdleFunc(about);
}
if(key=='q'||key=='Q')
{
exit(0);
}
}
void main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(1000,480);
glutInitWindowPosition(0,0);
glutCreateWindow("Data Communication in Network");
glutDisplayFunc(display);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
DATA COMMUNICATION over INTERNET
27 Dept. of Computer Science & Engineering.
glEnable(GL_NORMALIZE);
glutKeyboardFunc(mykey);
glutCreateMenu(menu);
glutAddMenuEntry("About Project 'A'",1);
glutAddMenuEntry("Local Area Network(LAN) 's'",2);
glutAddMenuEntry("Local Area Network(LAN) 'n'",3);
glutAddMenuEntry("Wide Area Network(WAN) 'P'",5);
glutAddMenuEntry("Transfer data from PC-A to PC-B '1'",6);
glutAddMenuEntry("Transfer data from PC-A to Company B -->'2'",7);
glutAddMenuEntry("Reset 'r'",8);
glutAddMenuEntry("Quit 'q'",9);
glutAttachMenu(GLUT_RIGHT_BUTTON);
doInit();
glutMainLoop();
}


Wednesday, February 26, 2025

Internal combustion engine - IC engine - OpenGL Computer Graphics Project

In this post we are going to referring to a project that involves computer graphics related to an internal combustion (IC) engine in particular petrol engine.We are going to focus on the design of engine components, simulations of the engine cycle and will going to show visualizations of how the internal combustion (IC) engine works.

An internal combustion engine (IC Engine) is a type of heat engine that generates power by burning (using oxidizer usually air) fuel (typically gasoline(petrol), diesel, or natural gas etc) inside a combustion chamber. IC engines are used in many vehicles, including cars, motorcycles, trucks, and airplanes. Below is Figure of an Typical  IC engine.



Before going to OpenGL Computer Graphics Project for IC engine let us know some more information about Internal combustion engine.

Here’s a breakdown of how an internal combustion engine works:

  1. Intake: The engine draws in a mixture of fuel and air into the combustion chamber.

  2. Compression: The intake valve closes, and the piston moves upwards, compressing the fuel-air mixture. This increases the pressure and temperature of the mixture.

  3. Power/Combustion: A spark plug ignites the compressed fuel-air mixture, causing a controlled explosion. This explosion pushes the piston down, which creates the mechanical energy to power the engine.

  4. Exhaust: The exhaust valve opens, and the piston moves upwards again to expel the combustion gases out of the cylinder.

The cycle repeats continuously, with pistons moving up and down, creating the power needed to drive a vehicle or perform work. There are two common types of internal combustion engines:

  • Two-stroke engines: Complete a power cycle with two strokes of the piston (one up and one down).
  • Four-stroke engines: Complete a power cycle in four strokes (intake, compression, power, and exhaust).

Usages : 

Keyboard: 'Space' : stop/start Engine 
                    '+' :  Speed up Engine 
                     '-' :  Speed down Engine





Code : 

//Simple Program:
#include<stdlib.h>
#include<GL/glut.h>
#include <math.h>

void *font = GLUT_BITMAP_TIMES_ROMAN_24; char buff[10]; void *fonts[] = { GLUT_BITMAP_9_BY_15, GLUT_BITMAP_TIMES_ROMAN_10, GLUT_BITMAP_TIMES_ROMAN_24 }; int cc=25,cb=65,s=0,speed=30,status=1; float pointer=25; typedef struct { GLfloat x,y;} Pt; Pt q1, q2,q3,q4; GLfloat colors[][3] = {{0.5,0.5,0.5},{0.5,0.5,0.5},{0.8,0.8,0.8},{0.8,0.8,0.8},{0.8,0.8,0.8},{0.4,0.4,0.4}}; void init() { glClearColor(0.0,0,0,0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,499.0,0.0,499.0); glutPostRedisplay(); } void DrawLine(Pt n1, Pt n2) { glBegin(GL_LINES); for (int i=0;i<3;i++){ glVertex2f(n1.x+i, n1.y+i); glVertex2f(n2.x+i, n2.y+i); } glEnd(); // glFlush(); } void point (float x,float y){ glPointSize(10.0f); glBegin(GL_POINTS); glVertex2f(x,y); glEnd(); //glFlush(); } void rect(Pt n1, Pt n2,Pt n3, Pt n4){ glBegin(GL_QUADS); // Draw The Cube Using quads // glColor3f(0.0f,1.0f,0.0f); // Color Blue glVertex2f(n1.x, n1.y); glVertex2f(n2.x, n2.y); glVertex2f(n3.x, n3.y); glVertex2f(n4.x, n4.y); glEnd(); // End Drawing The Cube //glFlush(); } void Circle(float cx, float cy, float r, int num_segments,int h) { //glColor3f(0.0,0.0,1.0); float xx,yy,n; if(h==1) glBegin(GL_LINE_LOOP);// for not filled circle else glBegin(GL_TRIANGLE_FAN); for (int ii = 0; ii < num_segments; ii++) { float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component glVertex2f(x + cx, y + cy);//output vertex } glEnd(); } void quad(Pt n1, Pt n2,int i){ glBegin(GL_QUADS); // Draw The Cube Using quads // glColor3f(0.0f,1.0f,0.0f); // Color Blue glVertex2f(n1.x-i, n1.y); glVertex2f(n1.x+i, n1.y); glVertex2f(n2.x+i, n2.y); glVertex2f(n2.x-i, n2.y); glEnd(); // End Drawing The Cube //glFlush(); } void quadd(Pt n1, Pt n2){ glBegin(GL_QUADS); // Draw The Cube Using quads //glColor3f(0.0f,1.0f,0.0f); // Color Blue glVertex2f(n1.x, n1.y-5); glVertex2f(n1.x, n1.y+5); glVertex2f(n2.x, n2.y+5); glVertex2f(n2.x, n2.y-5); glEnd(); // End Drawing The Cube //glFlush(); } void rectangle(Pt n1, Pt n2,int i){ glBegin(GL_QUADS); // Draw The Cube Using quads //glColor3f(0.0f,1.0f,0.0f); // Color Blue glVertex2f(n1.x-i, n1.y); glVertex2f(n2.x+i, n1.y); glVertex2f(n2.x+i, n2.y); glVertex2f(n1.x-i, n2.y); glEnd(); // End Drawing The Cube //glFlush(); } void outlet(float x,float y){ glColor3fv(colors[3]); glBegin(GL_TRIANGLE_FAN); if(s==1 ) { if(cc>=75 && cc<100 || cc>=0 && cc<=25) glColor3f(0.9,0.96,0.96); } if(s==0){ if(cc>25 && cc<=50){ float r=(cc-25)*0.006; glColor3f(0.9-(r),0.95-(r),0.95-(r)); }} float cx=x+50,cy=y+225,r=32; for (int ii = 0; ii < 100; ii++) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=25 && ii<=50) glVertex2f(x + cx, y + cy);//output vertex } r=10; for (int ii = 100; ii >=0; ii--) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=25 && ii<=50) glVertex2f(x + cx, y + cy);//output vertex } glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2f(x+100, y+234); glVertex2f(x+100, y+256); glVertex2d(x+41, y+256); glVertex2f(x+41, y+234); glEnd(); } void outletcover(float x,float y){ glColor3fv(colors[1]); //glColor3f(0,0,0); glBegin(GL_TRIANGLE_FAN); float cx=x+50,cy=y+225,r=34; for (int ii = 0; ii < 100; ii++) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=25 && ii<=50) glVertex2f(x + cx, y + cy);//output vertex } r=8; for (int ii = 100; ii >=0; ii--) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=25 && ii<=50) glVertex2f(x + cx, y + cy);//output vertex } glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2f(x+100, y+232); glVertex2f(x+100, y+259); glVertex2d(x+42, y+259); glVertex2f(x+42, y+232); glEnd(); } void Crank(float cx, float cy, float r, int num_segments) { glColor3f(0.0,0.0,1.0); float xx,yy,n; glBegin(GL_LINE_LOOP);// for not filled circle //glBegin(GL_TRIANGLE_FAN); for (int ii = 0; ii < num_segments; ii++) { float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii==cc){ xx=x+ cx; yy=y+ cy; } } glEnd(); if(cc>=0 && cc<25) {n=cy+125+(cc*1.4);} else if(cc>=25 && cc<=75) {n=cy+160-((cc-25)*1.4);} else if(cc>75 && cc<100) {n=cy+90+((cc-75)*1.4);} glColor3f(0.0f,1.0f,0.0f); q1.x=xx; q1.y=yy; /*glColor3f(0.0f,0.0f,1.0f); q2.x=cx; q2.y=cy; quad(q1,q2,5); q2.x=cx; q2.y=cy; quadd(q1,q2);*/ glColor3f(0.4f,0.4f,0.4f); q2.x=cx; q2.y=n; quad(q1,q2,5); q1.x=cx; q1.y=n; q2.x=cx; q2.y=n+40; //glColor3f(0.0f,0.0f,1.0f); glColor3fv(colors[0]); quad(q1,q2,45); glColor3f(0.4f,0.4f,0.4f); glColor3f(0.4f,0.4f,0.4f); q1.x=cx; q1.y=n+18; q2.x=cx; q2.y=n+28; //quad(q1,q2,45); q1.x=cx; q1.y=n+30; q2.x=cx; q2.y=n+39; //quad(q1,q2,45); Circle(xx,yy,10,100,0);//crank connector Circle(cx,n+10,10,100,0);//piston connecting rod } void Crankrod(float cx, float cy, float r, int num_segments) { float xx,yy,n,xxx,yyy,flg=0; glBegin(GL_TRIANGLE_FAN); for (int ii = 0; ii < num_segments; ii++) { float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=cb && ii<=(cb+20)){ glVertex2f(x + cx, y + cy);//output vertex if(flg!=1) {xxx=x+cx; yyy=y+cy;} } if(cb>=80 && ii<=(20-(100-cb))){ glVertex2f(x + cx, y + cy);//output vertex xxx=x+cx; yyy=y+cy; flg=1; } if(ii==cb){ xx=x+ cx; yy=y+ cy; } } glEnd(); q1.x=xx; q1.y=yy; q2.x=xxx; q2.y=yyy; q3.x=cx; q3.y=cy; q4.x=cx; q4.y=cy; rect(q1,q2,q3,q4); //glColor3f(0.0,0.0,0.0); //Circle(xx,yy,3,100,0); }void valve(float x,float y){ float p=0; if(s==0){ if(cc>=25 && cc<=50) p=-(cc-25)*0.6; else if(cc>50 && cc<75) p=-15+(cc-50)*0.6; } //glColor3f(1.0f,0.0f,0.0f); glColor3fv(colors[5]); q1.x=x-30; q1.y=y+225+p; q2.x=x-30; q2.y=y+220+p; quad(q1,q2,10); q1.x=x-30; q1.y=y+225+p; q2.x=x-30; q2.y=y+276+p; quad(q1,q2,2); p=0; if(s==1){ if(cc>=0 && cc<25) p=-15+(cc)*0.6; if(cc>=75 && cc<100) p=-(cc-75)*0.6; } q1.x=x+30; q1.y=y+225+p; q2.x=x+30; q2.y=y+220+p; quad(q1,q2,10); q1.x=x+30; q1.y=y+225+p; q2.x=x+30; q2.y=y+276+p; quad(q1,q2,2); } void cover(float x,float y){// x=900;y=500; //glColor3f(1.0,1.0,0.0); glBegin(GL_TRIANGLE_FAN); glVertex2d(x-120,y+60); glVertex2d(x-55,y+125); glVertex2d(x+55,y+125); glVertex2d(x+120,y+60); glVertex2d(x+120,y-120); glVertex2d(x-120,y-120); glEnd(); glBegin(GL_TRIANGLE_FAN); //glVertex2d(780,560); glVertex2d(x-55,y+125); glVertex2d(x-55,y+225); glVertex2d(x-20,y+250); glVertex2d(x+20,y+250); glVertex2d(x+55,y+225); glVertex2d(x+55,y+125); glEnd(); } void innlet(float x,float y){ glColor3fv(colors[3]); glBegin(GL_TRIANGLE_FAN); if(s==0 ) { if(cc>=27 && cc<75) glColor3f(0.0,0.5,1.0); if(cc>=75 && cc<100){ float r=(cc-75)*0.032; glColor3f(0.0+r,0.5+(r/2.66),1.0-(r/4)); } } float cx=x-50,cy=y+225,r=32; for (int ii = 0; ii < 100; ii++) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=0 && ii<=25) glVertex2f(x + cx, y + cy);//output vertex }r=10; for (int ii = 100; ii >=0; ii--) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=0 && ii<=25) glVertex2f(x + cx, y + cy);//output vertex } glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2f(x-100, y+256); glVertex2f(x-100, y+235); glVertex2d(x-49,y+235); glVertex2f(x-49, y+256); glEnd(); } void innletcover(float x,float y){ glColor3fv(colors[1]); glBegin(GL_TRIANGLE_FAN); float cx=x-50,cy=y+225,r=34; for (int ii = 0; ii < 100; ii++) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=0 && ii<=25) glVertex2f(x + cx, y + cy);//output vertex }r=8; for (int ii = 100; ii >=0; ii--) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=0 && ii<=25) glVertex2f(x + cx, y + cy);//output vertex } glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2f(x-100, y+259); glVertex2f(x-100, y+232); glVertex2d(x-47,y+232); glVertex2f(x-47, y+259); glEnd(); } void spark(float x,float y){ glColor3f(1,1,0.1); glBegin(GL_TRIANGLE_FAN); //glBegin(GL_LINE_LOOP); //glVertex2f(x-5,y+220); glVertex2f(x+3,y+220); glVertex2f(x+16,y+225); glVertex2f(x+10,y+220); glVertex2f(x+17,y+215); glVertex2f(x-3,y+220); glVertex2f(x-16,y+225); glVertex2f(x-11,y+220); glVertex2f(x-17,y+215); glVertex2f(x+3,y+220); glVertex2f(x+5,y+220); glVertex2f(x,y+210); glVertex2f(x-5,y+220); glEnd(); } void plug(float x,float y){ //float x=217,y=301; glColor3f(0.3,0.3,0.3); glBegin(GL_TRIANGLE_FAN); glVertex2f(x-2, y+19); glVertex2f(x+3, y+19); glVertex2f(x+3, y+24); glVertex2f(x-2, y+24); glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2f(x-7, y+19); glVertex2f(x+8, y+19); glVertex2f(x+8, y+1); glVertex2f(x-7, y+1); glEnd(); glColor3f(0.0,0.0,0.0); glBegin(GL_QUADS); glVertex2f(x-17, y-1); glVertex2f(x+19, y-1); glVertex2f(x+19, y+1); glVertex2f(x-17, y+1); glEnd(); glColor3f(1.8,1.8,1.0); glBegin(GL_TRIANGLE_FAN); glVertex2f(x-9, y-1); glVertex2f(x+10, y-1); glVertex2f(x+10, y-31); glVertex2f(x-9, y-31); glEnd(); glColor3f(0.0,0.0,0.0); glBegin(GL_LINES); for(int i=0;i<5;i++) { glVertex2f(x+10, (y-1)-(5*i)); glVertex2f(x-9, (y-6)-(5*i)); } glEnd(); glColor3f(1.8,1.8,1.0); glPointSize(7.0f); glBegin(GL_POINTS); glVertex2d(x+1,y-31); glEnd(); glBegin(GL_LINES); glVertex2d(x+6,y-32); glVertex2d(x+6,y-41); glEnd(); glBegin(GL_LINES); glVertex2d(x-2,y-41); glVertex2d(x+6,y-41); glEnd(); glColor3f(0.3,0.3,0.3); glBegin(GL_LINES); float cx=x+25,cy=y+24,r=25; for (int ii = 0; ii < 100; ii++) { float theta = 2.0f * 3.1415926f * float(ii) / float(100);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=25 && ii<=50) glVertex2f(x + cx, y + cy);//output vertex } glEnd(); } void fuel(float x,float y){ float j,i=x,k=y+227,l,flag=0; if(s==0){k=y+224; if( cc>25 && cc<=75){ l=y+170-((cc-25)*1.4); flag=1; glColor3f(0.0,0.5,1.0);//fuel color } if( cc>75 && cc<100){ l=y+100+((cc-75)*1.4); flag=1; float rr=(cc-75)*0.02; glColor3f(rr,0.5-(rr/2),1-rr);//fuel color } if( cc>=0 && cc<25){ l=y+135+(cc*1.4); flag=1; float rr=(cc)*0.02; glColor3f(rr+0.5,0.25-(rr/2),0.5-rr);//fuel color } } if(s==1){ k=(y+225); if(cc>=25 && cc<=75){ l=y+170-((cc-25)*1.4); flag=1; float rr=(cc-25)*0.02; if(rr>=0.95) rr=0.95; glColor3f(1-(rr*0.1),0+rr,0+rr); } if( cc>75 && cc<100){ l=y+100+((cc-75)*1.4); flag=1; glColor3f(0.9,0.95,0.95); } if( cc>=0 && cc<=25){ l=y+135+(cc*1.4); flag=1; glColor3f(0.9,0.95,0.95);//gas color } } if(flag==1){ glBegin(GL_LINES); for(j=k;j>l;j--) { glVertex2f(i-43,j); glVertex2f(i+44,j); } glEnd(); } } void board(float x,float y){ //glColor3f(0.0,1.0,1.0); glColor3f(0.95,1,1); glBegin(GL_QUADS); glVertex2f(x-450,y-250); glVertex2f(x+450,y-250); glVertex2f(x+450,y+450); glVertex2f(x-450,y+450); glEnd(); //glColor3f(0.85,1,1); glColor3f(0.2,.8,.5); glBegin(GL_QUADS); glVertex2f(x-400,y-200); glVertex2f(x+400,y-200); glVertex2f(x+400,y+400); glVertex2f(x-400,y+400); glEnd(); } void smallboard(float x,float y){ //glColor3f(0.0,1.0,1.0); glColor3f(0.95,1,1); glBegin(GL_QUADS); glVertex2f(x-200,y-200); glVertex2f(x+200,y-200); glVertex2f(x+200,y+200); glVertex2f(x-200,y+200); glEnd(); //glColor3f(0.85,1,1); glColor3f(0.2,.8,.5); glBegin(GL_QUADS); glVertex2f(x-160,y-160); glVertex2f(x+160,y-160); glVertex2f(x+160,y+160); glVertex2f(x-160,y+160); glEnd(); } /*void board(float x,float y){ glColor3f(0.3,0.3,0.3); //glColor3f(0.95,1,1); glBegin(GL_QUADS); glVertex2f(x-550,y-250); glVertex2f(x+550,y-250); glVertex2f(x+550,y+450); glVertex2f(x-550,y+450); glEnd(); glColor3f(1.0,1.0,1.0); //glColor3f(0.2,.8,.5); glBegin(GL_QUADS); glVertex2f(x-500,y-200); glVertex2f(x+500,y-200); glVertex2f(x+500,y+400); glVertex2f(x-500,y+400); glEnd(); }*/ void text(int x, int y, char *string,int j) { int len, i; glRasterPos2f(x, y); len = (int) strlen(string); for (i = 0; i < len; i++) { glutBitmapCharacter(fonts[j], string[i]); } } void indicator(float cx, float cy, float r, int num_segments,int h) { //glColor3f(0.0,0.0,1.0); float xx,yy,n; glBegin(GL_TRIANGLE_FAN); glVertex2f(cx, cy);//output vertex for (int ii = 0; ii <= num_segments; ii++) { float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii>=h && ii<=(h+25)) glVertex2f(x + cx, y + cy);//output vertex } glEnd(); } void kk(float cx, float cy, float r, int num_segments){ for (int ii = 0; ii <= num_segments; ii++) { float theta = 2.0f * 3.1415926f * float(ii) / float(num_segments);//get the current angle float x = r * cosf(theta);//calculate the x component float y = r * sinf(theta);//calculate the y component if(ii==pointer || ii==(pointer-0.5)) glVertex2f(x + cx, y + cy);//output vertex } } void tip(float cx, float cy, float r, int num_segments){ float xx,yy,n; glBegin(GL_TRIANGLE_FAN); glVertex2f(cx-5, cy-5);//output vertex kk(cx,cy,r,num_segments); glVertex2f(cx+5, cy-5);//output vertex glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2f(cx-5, cy-5);//output vertex kk(cx,cy,r,num_segments); glVertex2f(cx-5, cy+5);//output vertex glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2f(cx-5, cy+5);//output vertex kk(cx,cy,r,num_segments); glVertex2f(cx+5, cy+5);//output vertex glEnd(); glBegin(GL_TRIANGLE_FAN); glVertex2f(cx+5, cy-5);//output vertex kk(cx,cy,r,num_segments); glVertex2f(cx+5, cy+5);//output vertex glEnd(); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glClear(GL_COLOR_BUFFER_BIT); int x=800,y=500; //Circle(x, y, 100, 100,0); glColor3f(0.0,1.0,1.0); board(x,y); glColor3fv(colors[1]); cover(x,y); glColor3f(0.8,0.8,0.8); innletcover(x,y); innlet(x,y); outletcover(x,y); outlet(x,y); // glColor3f(1.0,1.0,1.0); glColor3fv(colors[4]); Circle(x, y, 110, 100,0); q1.x=x-44; q1.y=y+100; q2.x=x-44; q2.y=y+225; q3.x=x+44; q3.y=y+225; q4.x=x+44; q4.y=y+100; rect(q1,q2,q3,q4); //inner cylinder fuel(x,y); glColor3f(0.0,0.0,1.0); //reectangle(); //point(x,y+325); glColor3fv(colors[0]); //Crankrod(x, y, 65, 100); Circle(x, y, 50, 100,0); glColor3fv(colors[2]); Crank(x, y, 35, 100); glColor3f(0.0,0.0,1.0); valve(x,y); plug(x,y+253); if(s==0 && cc>=22 && cc<=25 ) spark(x+1,y-2); if(s==1 && cc<=28 && cc>=25 ) spark(x+1,y-2); // title glColor3f(0.0,0.0,1.0); text(x-115,y+415,"IC Petrol Engine",2); y+=150; smallboard(x+700,y); glColor3f(0.3,0.3,0.3); Circle(x+700, y, 145, 100,0); glColor3f(0.9,0.95,0.95); indicator(x+700, y, 140, 100,0); //exhaust glColor3f(0.0,0.5,1.0); indicator(x+700, y, 140, 100,25); //suction glColor3f(0.8,0.5,0.5); indicator(x+700, y, 140, 100,50);//compression glColor3f(0.9,1.0,0.5); indicator(x+700, y, 140, 100,75);// working glColor3f(0.3,0.3,0.3); Circle(x+700, y, 15, 100,0); //glColor3f(0.0,0.0,0.0); tip(x+700, y, 100, 100); glColor3f(0.0,0.0,1.0); text(x+600,y+170,"Stroke Indicator",2); //lables glColor3f(0.0,0.5,1.0); point(x+520,y-240); glColor3f(0.5,0.9,1.0); text(x+540,y-245,"Suction Stroke",0); glColor3f(0.8,0.5,0.5); point(x+520,y-260); glColor3f(0.5,0.9,1.0); text(x+540,y-265,"Compression Stroke",0); glColor3f(0.9,1.0,0.5); point(x+520,y-280); glColor3f(0.5,0.9,1.0); text(x+540,y-285,"Working Stroke",0); glColor3f(0.9,0.95,0.95); point(x+520,y-300); glColor3f(0.5,0.9,1.0); text(x+540,y-305,"Exhaust Stroke",0); text(x-510,y-450,"Press 'space' to start/stop Press '+' to speedup engine Press '-' to slowdown engine",0); glFlush(); //quad(); } void start(){ if(status==1) { cb++; cc++; pointer+=0.5; } if(cc==100) { cc=0; } if(pointer==100) { pointer=0; } if(cb==100) cb=0; display(); //Game title if(cc==25){ if(s==0) s=1; else s=0; } Sleep(speed); } void keypress(unsigned char key, int x,int y){ if (key=='+') {speed--; if(speed<=0) speed=0;} if (key=='-') {speed++;if(speed>=500) speed=500;} if(key==' ') {if(status==0) status=1; else status=0; }} void myReshape(int w,int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0); glMatrixMode(GL_PROJECTION); } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize (600, 600); glutCreateWindow("Introduction to Open GL"); glutReshapeFunc(myReshape); glutKeyboardFunc(keypress); glutDisplayFunc(display); glutIdleFunc(start); init(); glutMainLoop();
}

Here are a few common components that could be part of such the OpenGL Computer Graphics Project:

  1. 3D Visualization: Creating a detailed 3D model of a petrol engine, showing key parts like the pistons, crankshaft, valves, and camshaft.

  2. Animation of Engine Cycle: Simulating and animating the stages of the engine cycle, like intake, compression, power, and exhaust strokes.

  3. Computational Fluid Dynamics (CFD) Simulation: Visualizing airflow and combustion processes inside the engine, potentially showing how fuel and air mix, ignite, and exhaust gases are expelled.

  4. Performance Simulation: Using computer graphics to illustrate how engine performance (such as horsepower, torque, fuel consumption) changes with different variables (e.g., RPM, throttle position).