Download OU BE (B-Tech) CSE Mini Projects Code program on display list, mouse,keyboard events, Menus

Download OU (Osmania University)BE (B-Tech) (Bachelor of Engineering) CSE Best Practicle Programs And Code program on display list, mouse,keyboard events, Menus

/* simple graphics program to demonstrate Display list and mouse events */
#include
#include
#define QSTRIP 1
//function to define display list
void display()
{
glClea rColor(0.0,0.0,0.0,0.0);
gICIear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glNewList(QSTR|P, GL_COMP|LE);//disp|ay list
ngegin(GL_QUAD_STR|P);
glColor3f(0.0,0.0,1.0);
g|Vertex3f(0.0,0.0,0.0);//v0
glVertex3f(2.0,0.0,0.0);//v1
glColor3f(0.0,1.0,0.0);
g|Vertex3f(0.0,2.0,0.0);//v2
glVertex3f(2.0,2.0,0.0);//v3
glColor3f(1.0,0.0,0.0);
g|Vertex3f(0.0,4.0,0.0);//v4
glVertex3f(2.0,4.0,0.0);//v5
glEndO;
glEndList();
}
//functions which calls display list
void quad()
{
gICaIIList(QSTR|P);
gIFlush();
}
//reshape event handling function
void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJ ECTION);
glLoadIdentity();
gluOrth02D(-5,5,-5,5);
glMatrixMode(GL_MODELV|EW);
glViewport(0,0,w,h);
}
//mouse event handling function
void myMouse(int button, int state, int x, int y)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
quadO;
if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
exit(0);
}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_S|NGLE);
glutlnitWindowSize(400,400);
glutlnitWindowPosition(100,100);
glutCreateWindow("display list");
glutDisplayFunc(disp|ay);
glutMouseFunc(myMouse);
glutReshapeFunc(reshape);
glutMainLoop();

/* program to draw a small square at each relative location on the screen where the mouse
left button is Clicked and window is closed when 'q? key is pressed*/
#include
#include
#define QSTRIP 1
GLfloat size=50.0;
GLsizei wh=300, ww=300;
void display()
{
glClea rColor(0.0,0.0,0.0,0.0);
gICIear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
}
void drawsquare(int x, int y)
{
ngegin(GL_POLYGON);
glColor3f(0.0,0.0,1.0);
glVertex2f(x+size, y+size);
glVertex2f(x-size, y+size);
glVertex2f(x-size, y-size);
glVertex2f(x+size, y-size);
glEndO;
gIFlush();
}
void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJ ECTION);
glLoadIdentity();
gluOrth02D(0.0,(GLdouble)w,0.0,(GLdouble)h);
glMatrixMode(GL_MODELV|EW);
glViewport(0,0,w,h);
ww=w;
wh=h;
}
void myMouse(int button, int state, int x, int y)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
drawsquare(x,y);
}
void myKey(unsigned char key, int x, int y)
{
if(kev=='Q'| Ikev=='Q')
exit(0);
}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_S|NGLE);
glutlnitWindowSize(ww,wh);
glutlnitWindowPosition(100,100);
glutCreateWindow("display list");
glutDisplayFunc(disp|ay);
glutMouseFunc(myMouse);
glutReshapeFunc(reshape);
glutKeyboardFunc(myKey);
glutMainLoop();

/*sample program on Menu using GLUT*/
#include
#include
GLint size=2;
void display()
{
glCIearCoIor(0.0,0.0,0.0,l.O);
gICIear(GL_COLOR_BUFFER_BIT);
}
void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJECTION);
glLoadldentity();
gluOrth02D(-10,10,-10,10);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w,h);
}
void draw(int size)
{
ngegin(GL_POLYGON);
glVertex2f(-size, -size);
glVertex2f(size, -size);
glVertex2f(size, size);
glVertex2f(-size, size);
gIEnd();
glFlush();
}
void demo_menu(int id)
{
switch(id)
{
case 1: exit(0);
break;
case 3: size=2*size;
glColor3f(0.0,0.0,l.0);
draw(size);
break;
case 4: if(size>3)
size=size/2;
glColor3f(0.0,1.0,0.0);
draw(size);
break;
case 2: glColor3f(1.0,0.0,l.0);
draw(size);
break;
}
glutPostRedisplayO;
}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_DEPTH |GLUT_RGB | GLUT_S|NGLE);
glutlnitWindowPosition(50,50);
glutlnitWindowSize(500,500);
glutCreateWindow("sample menu");
glutCreateMenu(demo_menu);
glutAddMenuEntry("Quit", 1);
glutAddMenuEntry("origina|",2);
glutAddMenuEntry("|ncrease",3);
glutAddMenuEntry("Decrease",4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(disp|ay);

glutReshapeFunc(reshape);
glutMainLoop();
/* Program on Menu and sub menu*/
#include
#include
GLint size=2;
int sub_menu;
void display()
{
glCIearCoIor(0.0,0.0,0.0,l.O);
gICIear(GL_COLOR_BUFFER_BIT);
}
void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJECTION);
glLoadldentity();
gluOrth02D(-10,10,-10,10);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w,h);
}
void draw(int size)
{
ngegin(GL_POLYGON);
glVertex2f(-size, -size);
glVertex2f(size, -size);
glVertex2f(size, size);
glVertex2f(-size, size);
gIEnd();
glFlush();
}
void demo_menu(int id)
{
switch(id)
{
case 1: exit(0);
break;
case 2: glColor3f(1.0,0.0,l.0);
draw(size);
break;
case 3: size=2*size;
glColor3f(0.0,0.0,l.0);
draw(size);
break;
case 4: if(size>3)
size=size/2;
glColor3f(0.0,1.0,0.0);
draw(size);
break;
}
glutPostRedisplayO;
}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_DEPTH |GLUT_RGB | GLUT_S|NGLE);
glutlnitWindowPosition(50,50);
glutlnitWindowSize(500,500);
glutCreateWindow("sample menu");
sub_menu=g|utCreateMenu(demo_menu);
glutAddMenuEntry("|ncrease",3);

glutAddMenuEntry("Decrease",4);
glutCreateMenu(demo_menu);
glutAddMenuEntry("Quit", 1);
glutAddMenuEntry("origina|",2);
glutAddSubMenu("Resize", sub_menu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(disp|ay);
glutReshapeFunc(reshape);
glutMainLoop();}
/*Program for displaying stroke and raster text*/
#include
#include
void displayText( int r, int g, int b, const char *string ){
int] = strlen( string );
glColor3f( r, g, b );
glRasterPost(100.0, 10.0 );
for(inti=0;i//g|utStrokeCharacter( GLUT_STROKE_MONO_ROMAN, string[i] );
glutBitmapCharacter(GLUT_B|TMAP_T|MES_ROMAN_24, string[i]);
}
glFlush();
}
void display()
{
gICIearColor(0.0,0.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
displayText(l.0,0.0,0.0,"M. Praveen Kumar, Assistant Professor, MECS");
}
void reshape(GLsizei w, GLsizei h)
{
glMatrixMode(GL_PROJECTION);
glLoadldentityO;
gluOrth02D(0.0,(GLdouble)w, 0.0,(GLdouble)h);
glMatrixMode(GL_MATR|X_MODE);
}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE);
glutlnitWindowSize(400,400);
glutlnitWindowPosition(100,100);
glutCreateWindow("Text Display");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoopO;

This post was last modified on 27 January 2020