Download OU BE (B-Tech) CSE Mini Projects Code Program on Picking, Menu, Submenu, Rotating Square

Download OU (Osmania University)BE (B-Tech) (Bachelor of Engineering) CSE Best Practicle Programs And Code Program on Picking, Menu, Submenu, Rotating Square

/**************************Picking program for Linux******************/
#include
#define N 5
GLdouble ww=500, wh=500;
void drawobject(GLenum mode)
{
if(mode==GL_RENDER);
glLoadName(l);
glColor3f(l.0,0.0,0.0);
glRectf(0.5,0.5,l.0,1.0);
if(mode==GL_RENDER);
glLoadName(2);
glColor3f(0.0,0.0,1.0);
glRectf(-1.0,-1.0,-0.5,-0.5);
}
void myMouse(int button, int state, int x, int y)
{
GLuint namebuffer[10];
GLint viewport[4];
if(button==GLUT_LEFT_BUTTON && State==GLUT_DOWN)
{
glRenderMode(GL_RENDER);
glGetlntegerv(GL_VlEWPORT,viewport);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadldentityO;
gluPickMatrix((GLdouble)x,(GLdouble)(viewport[3]-y),N,N,viewport);
gluOrth02D(-5,5,-5,5);
drawobject(GL_RENDER);
glMatrixMode(GL_PROJECTION);
glPopMatrixO;
glFIush();
glRenderMode(GL_SELECT);
glutPostRedisplay();
}
}
void display()
{
glCIearCoIor(1.0,1.0,1.0,1.0);
glCIear(GL_COLOR_BUFFER_BIT);
drawobject(GL_SELECT);
glFIush();
}
void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJECTION);
glLoadldentity();
gluOrth02D(-5,5,-5,5);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w,h);
ww=w;
wh=h;
}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_RGB | GLUT_S|NGLE);
glutlnitWindowPosition(50,50);
glutlnitWindowSize(ww,wh);
glutCreateWindow("picking example");
glutMouseFunc(myMouse);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 1; }

/* Program on Picking executes on windows 05*/
#include
#include
#include
#include
#define N 2
using namespace std;
void drawObjects()
{
glLoadName(l);
glColor3f(1.0,0.0,0.0);
glRectf(0.5,0.5,1.0,1.0);
glLoadName(2);
glColor3f(0.0,0.0,l.0);
glRectf(-1.0,-1.0,-0.5,-0.5);
}
void mouse(int button, int state, int x, int y)
{
GLuint namebuffer[10];
GLint viewport[4];
if(button==GLUT_LEFT_BUTTON&&State==GLUT_DOWN)
{
glRenderMode(GL_SELECT);
gllnitNames();
glPushName(-l);
ngelectBuffer(10,namebuffer);
glGetlntegerv(GL_V|EWPORT,viewport);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadldentity();
gluPickMatrix((GLdoub|e) x, (GLdouble) (viewport[3]?y),N,N,viewport);
gluOrth02D(-5,5,-5,5);
drawObjects();
glMatrixMode(GL_PROJECTION);
glPopMatrixO;
glFIush();
glutPostRedisplay();
}
}
void display()
{
gICIear(GL_COLOR_BUFFER_BIT);
drawObjects();
glutSwapBuffersO;
}
void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJECTION);
glLoadldentity();
gluOrth02D(-5,5,-S,5);
glMatrixMode(GL_MODELV|EW);
}
int main(int argc, char **argv)
{
glutlnit(&argc,argv);
glutlnitWindowSize(500,500);
glutlnitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow("Picking");
glutMouseFunc(mouse);
glutDisplayFunc(disp|ay);
glutReshapeFunc(reshape);
glutMainLoop();

/*sample program on Menu using GLUT*/
#include
#include
GLint size=2;
void display()
{
glClearCoIor(0.0,0.0,0.0,1.0);
gICIear(GL_COLOR_BUFFER_BIT);
}
void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJECTION);
glLoadldentity();
gluOrth02D(-10,lO,-10,10);
glMatrixMode(GL_MODELV|EW);
glViewport(0,0,w,h);
}
void draw(int size)
{
ngegin(GL_POLYGON);
glVertex2f(-size, -size);
glVertex2f(size, -size);
glVertex2f(size, size);
glVertex2f(-size, size);
glEnd();
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: glCoIor3f(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("original",2);
glutAddMenuEntry("|ncrease",3);
glutAddMenuEntry("Decrease",4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(disp|ay);
glutReshapeFunc(reshape);
glutMainLoop();

/* Program on sub menu*/
#include
#include
GLint size=2;
int sub_menu;
void display()
{
glClearCoIor(0.0,0.0,0.0,1.0);
gICIear(GL_COLOR_BUFFER_BIT);
}
void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJECTION);
glLoadldentity();
gluOrth02D(-10,lO,-10,10);
glMatrixMode(GL_MODELV|EW);
glViewport(0,0,w,h);
}
void draw(int size)
{
ngegin(GL_POLYGON);
glVertex2f(-size, -size);
glVertex2f(size, -size);
glVertex2f(size, size);
glVertex2f(-size, size);
glEnd();
glFlush();
}
void demo_menu(int id)
{
switch(id)
{
case 1: exit(0);
break;
case 2: glCoIor3f(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("original",2);
glutAddSubMenu("Resize", sub_menu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(disp|ay);
glutReshapeFunc(reshape);
glutMainLoop();
/* Rotating square using double buffer */
#include
#include
#include
GLfloat theta, thetar;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
ngegin(GL_POLYGON);
ngrawBuffer(GL_FRONT_AND_BACK);
glColor3f(0.0,0.0,l.0);
thetar = theta/(3.l4l/180.0);
glVertex2f(cos(thetar),sin(thetar));
glVertex2f(-sin(thetar),cos(thetar));
glVertex2f(-cos(thetar),-sin(thetar));
glVertex2f(sin(thetar),-cos(thetar));
glEndO;
//for Outer circle
ngegin(GL_PO|NTS);
GLroat r=1.0;
for(int i=0;i<=360;i++)
gIVertex2f(cos(i*(3.l41/180))*r, sin(i*(3.141/180))*r);
glEnd();
glutSwapBuffersO;
}
//perform background processing tasks or continuous animation when window system events are not being received.
void idle()
{
theta+=2;
if(theta>=360.0)
theta-=360.0;
glutPostRedisplayO;
}
void myMouse(int btn, int state, int x, int y)
{
if(btn==GLUT_LEFT_BUTTON && State==GLUT_DOWN)
glutldleFunc(idle);
if(btn==GLUT_RIGHT_BUTTON && State==GLUT_DOWN)
glutldleFunc(NULL);
}
void reshape(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glLoadldentity();
glOrtho(-2,2,-2,2,2,-2);
glMatrixMode(GL_MODELV|EW);
glViewport(0,0,w,h);
}
int main(int argc, char **argv)
{
glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("rotate square");
glutDisplayFunc(disp|ay);
glutReshapeFunc(reshape);

glutMouseFunc(myMouse);
glutMainLoop();

This post was last modified on 27 January 2020