FirstRanker Logo

FirstRanker.com - FirstRanker's Choice is a hub of Question Papers & Study Materials for B-Tech, B.E, M-Tech, MCA, M.Sc, MBBS, BDS, MBA, B.Sc, Degree, B.Sc Nursing, B-Pharmacy, D-Pharmacy, MD, Medical, Dental, Engineering students. All services of FirstRanker.com are FREE

📱

Get the MBBS Question Bank Android App

Access previous years' papers, solved question papers, notes, and more on the go!

Install From Play Store

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

This post was last modified on 27 January 2020

/* simple graphics program to demonstrate Display list and mouse events */
#include
#include
#define QSTRIP 1
//function to define display list

--- Content provided by FirstRanker.com ---

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

--- Content provided by FirstRanker.com ---

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

--- Content provided by FirstRanker.com ---

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

--- Content provided by FirstRanker.com ---

glEndO;
glEndList();
}
//functions which calls display list
void quad()

--- Content provided by FirstRanker.com ---

{
gICaIIList(QSTR|P);
gIFlush();
}
//reshape event handling function

--- Content provided by FirstRanker.com ---

void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJ ECTION);
glLoadIdentity();
gluOrth02D(-5,5,-5,5);

--- Content provided by FirstRanker.com ---

glMatrixMode(GL_MODELV|EW);
glViewport(0,0,w,h);
}
//mouse event handling function
void myMouse(int button, int state, int x, int y)

--- Content provided by FirstRanker.com ---

{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
quadO;
if(button==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
exit(0);

--- Content provided by FirstRanker.com ---

}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_S|NGLE);

--- Content provided by FirstRanker.com ---

glutlnitWindowSize(400,400);
glutlnitWindowPosition(100,100);
glutCreateWindow("display list");
glutDisplayFunc(disp|ay);
glutMouseFunc(myMouse);

--- Content provided by FirstRanker.com ---

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*/

--- Content provided by FirstRanker.com ---

#include
#include
#define QSTRIP 1
GLfloat size=50.0;
GLsizei wh=300, ww=300;

--- Content provided by FirstRanker.com ---

void display()
{
glClea rColor(0.0,0.0,0.0,0.0);
gICIear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
}

--- Content provided by FirstRanker.com ---

void drawsquare(int x, int y)
{
ngegin(GL_POLYGON);
glColor3f(0.0,0.0,1.0);
glVertex2f(x+size, y+size);

--- Content provided by FirstRanker.com ---

glVertex2f(x-size, y+size);
glVertex2f(x-size, y-size);
glVertex2f(x+size, y-size);
glEndO;
gIFlush();

--- Content provided by FirstRanker.com ---

}
void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJ ECTION);
glLoadIdentity();

--- Content provided by FirstRanker.com ---

gluOrth02D(0.0,(GLdouble)w,0.0,(GLdouble)h);
glMatrixMode(GL_MODELV|EW);
glViewport(0,0,w,h);
ww=w;
wh=h;

--- Content provided by FirstRanker.com ---

}
void myMouse(int button, int state, int x, int y)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
drawsquare(x,y);

--- Content provided by FirstRanker.com ---

}
void myKey(unsigned char key, int x, int y)
{
if(kev=='Q'| Ikev=='Q')
exit(0);

--- Content provided by FirstRanker.com ---

}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_S|NGLE);

--- Content provided by FirstRanker.com ---

glutlnitWindowSize(ww,wh);
glutlnitWindowPosition(100,100);
glutCreateWindow("display list");
glutDisplayFunc(disp|ay);
glutMouseFunc(myMouse);

--- Content provided by FirstRanker.com ---

glutReshapeFunc(reshape);
glutKeyboardFunc(myKey);
glutMainLoop();

/*sample program on Menu using GLUT*/

--- Content provided by FirstRanker.com ---

#include
#include
GLint size=2;
void display()
{

--- Content provided by FirstRanker.com ---

glCIearCoIor(0.0,0.0,0.0,l.O);
gICIear(GL_COLOR_BUFFER_BIT);
}
void reshape(GLint w, GLint h)
{

--- Content provided by FirstRanker.com ---

glMatrixMode(GL_PROJECTION);
glLoadldentity();
gluOrth02D(-10,10,-10,10);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w,h);

--- Content provided by FirstRanker.com ---

}
void draw(int size)
{
ngegin(GL_POLYGON);
glVertex2f(-size, -size);

--- Content provided by FirstRanker.com ---

glVertex2f(size, -size);
glVertex2f(size, size);
glVertex2f(-size, size);
gIEnd();
glFlush();

--- Content provided by FirstRanker.com ---

}
void demo_menu(int id)
{
switch(id)
{

--- Content provided by FirstRanker.com ---

case 1: exit(0);
break;
case 3: size=2*size;
glColor3f(0.0,0.0,l.0);
draw(size);

--- Content provided by FirstRanker.com ---

break;
case 4: if(size>3)
size=size/2;
glColor3f(0.0,1.0,0.0);
draw(size);

--- Content provided by FirstRanker.com ---

break;
case 2: glColor3f(1.0,0.0,l.0);
draw(size);
break;
}

--- Content provided by FirstRanker.com ---

glutPostRedisplayO;
}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);

--- Content provided by FirstRanker.com ---

glutlnitDisplayMode(GLUT_DEPTH |GLUT_RGB | GLUT_S|NGLE);
glutlnitWindowPosition(50,50);
glutlnitWindowSize(500,500);
glutCreateWindow("sample menu");
glutCreateMenu(demo_menu);

--- Content provided by FirstRanker.com ---

glutAddMenuEntry("Quit", 1);
glutAddMenuEntry("origina|",2);
glutAddMenuEntry("|ncrease",3);
glutAddMenuEntry("Decrease",4);
glutAttachMenu(GLUT_RIGHT_BUTTON);

--- Content provided by FirstRanker.com ---

glutDisplayFunc(disp|ay);

glutReshapeFunc(reshape);
glutMainLoop();
/* Program on Menu and sub menu*/

--- Content provided by FirstRanker.com ---

#include
#include
GLint size=2;
int sub_menu;
void display()

--- Content provided by FirstRanker.com ---

{
glCIearCoIor(0.0,0.0,0.0,l.O);
gICIear(GL_COLOR_BUFFER_BIT);
}
void reshape(GLint w, GLint h)

--- Content provided by FirstRanker.com ---

{
glMatrixMode(GL_PROJECTION);
glLoadldentity();
gluOrth02D(-10,10,-10,10);
glMatrixMode(GL_MODELVIEW);

--- Content provided by FirstRanker.com ---

glViewport(0,0,w,h);
}
void draw(int size)
{
ngegin(GL_POLYGON);

--- Content provided by FirstRanker.com ---

glVertex2f(-size, -size);
glVertex2f(size, -size);
glVertex2f(size, size);
glVertex2f(-size, size);
gIEnd();

--- Content provided by FirstRanker.com ---

glFlush();
}
void demo_menu(int id)
{
switch(id)

--- Content provided by FirstRanker.com ---

{
case 1: exit(0);
break;
case 2: glColor3f(1.0,0.0,l.0);
draw(size);

--- Content provided by FirstRanker.com ---

break;
case 3: size=2*size;
glColor3f(0.0,0.0,l.0);
draw(size);
break;

--- Content provided by FirstRanker.com ---

case 4: if(size>3)
size=size/2;
glColor3f(0.0,1.0,0.0);
draw(size);
break;

--- Content provided by FirstRanker.com ---

}
glutPostRedisplayO;
}
int main(int argc, char **argv)
{

--- Content provided by FirstRanker.com ---

glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_DEPTH |GLUT_RGB | GLUT_S|NGLE);
glutlnitWindowPosition(50,50);
glutlnitWindowSize(500,500);
glutCreateWindow("sample menu");

--- Content provided by FirstRanker.com ---

sub_menu=g|utCreateMenu(demo_menu);
glutAddMenuEntry("|ncrease",3);

glutAddMenuEntry("Decrease",4);
glutCreateMenu(demo_menu);

--- Content provided by FirstRanker.com ---

glutAddMenuEntry("Quit", 1);
glutAddMenuEntry("origina|",2);
glutAddSubMenu("Resize", sub_menu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(disp|ay);

--- Content provided by FirstRanker.com ---

glutReshapeFunc(reshape);
glutMainLoop();}
/*Program for displaying stroke and raster text*/
#include
#include

--- Content provided by FirstRanker.com ---

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] );

--- Content provided by FirstRanker.com ---

glutBitmapCharacter(GLUT_B|TMAP_T|MES_ROMAN_24, string[i]);
}
glFlush();
}
void display()

--- Content provided by FirstRanker.com ---

{
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");
}

--- Content provided by FirstRanker.com ---

void reshape(GLsizei w, GLsizei h)
{
glMatrixMode(GL_PROJECTION);
glLoadldentityO;
gluOrth02D(0.0,(GLdouble)w, 0.0,(GLdouble)h);

--- Content provided by FirstRanker.com ---

glMatrixMode(GL_MATR|X_MODE);
}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);

--- Content provided by FirstRanker.com ---

glutlnitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE);
glutlnitWindowSize(400,400);
glutlnitWindowPosition(100,100);
glutCreateWindow("Text Display");
glutDisplayFunc(display);

--- Content provided by FirstRanker.com ---

glutReshapeFunc(reshape);
glutMainLoopO;