Download OU (Osmania University)BE (B-Tech) (Bachelor of Engineering) CSE Best Practicle Programs And Code Create a simple walk through program using even
#include
int a=2,b=0,ww=600,wh=600,movd;
void polygon()
{
glColor3f(1.0,0.0,0.0);//red polygon
ngegin(GL_POLYGON);
glVertex2f(a-45,b);
glVertex2f(a-15,b);
glVertex2f(a-15,b+30);
glVertex2f(a-45,b+30);
glEnd();
}
void drawRoad()
{
ngegin(GL_QUADS);
glColor3f(0.5,0.5,0.5);
glVertex2f(-60, -600);
glVertex2f(60, -600);
glVertex2f(60, 600);
glVertex2f(-60, 600);
glEndO;
}
void drawDivider()//white patch drawn in middle of road
{
glLoadldentity();
ngranslatef(0, movd, 0);
for(int i = -600; i <= 600; i++)
{
glColor3f(1, 1, 1);
ngegin(GL_QUADS);
glVertex2f(-8, 10 * 15 * i + 20);
glVertex2f(-8, 10 * 15 * i - 20);
glVertex2f(8, 10 * 15 * i - 20);
glVertex2f(8, 10 * 15 * i + 20);
glEndO;
}
glLoadldentity();
}
void display()
{
glCIearCoIor(0.0,1.0,0.3,1.0);
gICIear(GL_COLOR_BUFFER_BIT);
drawRoad(); //for road
drawDivider(); //for divider
polygon(); //for object
glutSwapBuffers();
}
void keyboard(unsigned char button, int x, int y)
{
if(button==GLUT_KEY_LEFT)
a=2;
if(button==GLUT_KEY_R|GHT)
a=60;
if(button==GLUT_KEY_DOWN)
movd=movd+20;
if(button==GLUT_KEY_UP)
movd=movd-20;
glutPostRedisplayO;
}
void reshape (int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECT|ON);
glLoadldentity ();
gluOrth02D(-ww,ww,-wh,wh);
glMatrixMode(GL_MODELVIEW);
glLoadldentityO;
}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_DEPTH |GLUT_RGB | GLUT_DOUBLE);
glutlnitWindowSize(ww,wh);
glutlnitWindowPosition(100,100);
glutCreateWindow("Wa|k Game");
glutSpecialFunc(keyboard);
glutDisplayFunc(disp|ay);
glutReshapeFunc(reshape);
glutMainLoop();
Outgut Screen
I
"5.33 a3 :. .2. >=v?umu u >?E.,:?A:.=:.:
qua) . m?nllg,d~l"agy) m!
3? ?,_u(,,.,-.,-,. - ,. ?r?- gr L=~ ?~ 7
4?!
IM'm
W x\
1 M >
)Wonspmt
I walk um
. B imm
u m w ' unnmq P051913
.1 zrquma dubs; unrgn. Ix-
This post was last modified on 27 January 2020