Pages

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;
}


No comments:

Post a Comment