#include
#define N 5
GLdouble ww=500, wh=500;
void drawobject(GLenum mode)
--- Content provided by FirstRanker.com ---
{if(mode==GL_RENDER);
glLoadName(l);
glColor3f(l.0,0.0,0.0);
glRectf(0.5,0.5,l.0,1.0);
--- Content provided by FirstRanker.com ---
if(mode==GL_RENDER);glLoadName(2);
glColor3f(0.0,0.0,1.0);
glRectf(-1.0,-1.0,-0.5,-0.5);
}
--- Content provided by FirstRanker.com ---
void myMouse(int button, int state, int x, int y){
GLuint namebuffer[10];
GLint viewport[4];
if(button==GLUT_LEFT_BUTTON && State==GLUT_DOWN)
--- Content provided by FirstRanker.com ---
{glRenderMode(GL_RENDER);
glGetlntegerv(GL_VlEWPORT,viewport);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
--- Content provided by FirstRanker.com ---
glLoadldentityO;gluPickMatrix((GLdouble)x,(GLdouble)(viewport[3]-y),N,N,viewport);
gluOrth02D(-5,5,-5,5);
drawobject(GL_RENDER);
glMatrixMode(GL_PROJECTION);
--- Content provided by FirstRanker.com ---
glPopMatrixO;glFIush();
glRenderMode(GL_SELECT);
glutPostRedisplay();
}
--- Content provided by FirstRanker.com ---
}void display()
{
glCIearCoIor(1.0,1.0,1.0,1.0);
glCIear(GL_COLOR_BUFFER_BIT);
--- Content provided by FirstRanker.com ---
drawobject(GL_SELECT);glFIush();
}
void reshape(GLint w, GLint h)
{
--- Content provided by FirstRanker.com ---
glMatrixMode(GL_PROJECTION);glLoadldentity();
gluOrth02D(-5,5,-5,5);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w,h);
--- Content provided by FirstRanker.com ---
ww=w;wh=h;
}
int main(int argc, char **argv)
{
--- Content provided by FirstRanker.com ---
glutlnit(&argc, argv);glutlnitDisplayMode(GLUT_RGB | GLUT_S|NGLE);
glutlnitWindowPosition(50,50);
glutlnitWindowSize(ww,wh);
glutCreateWindow("picking example");
--- Content provided by FirstRanker.com ---
glutMouseFunc(myMouse);glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 1; }
--- Content provided by FirstRanker.com ---
/* Program on Picking executes on windows 05*/
#include
#include
#include
--- Content provided by FirstRanker.com ---
#include#define N 2
using namespace std;
void drawObjects()
{
--- Content provided by FirstRanker.com ---
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);
--- Content provided by FirstRanker.com ---
glRectf(-1.0,-1.0,-0.5,-0.5);}
void mouse(int button, int state, int x, int y)
{
GLuint namebuffer[10];
--- Content provided by FirstRanker.com ---
GLint viewport[4];if(button==GLUT_LEFT_BUTTON&&State==GLUT_DOWN)
{
glRenderMode(GL_SELECT);
gllnitNames();
--- Content provided by FirstRanker.com ---
glPushName(-l);ngelectBuffer(10,namebuffer);
glGetlntegerv(GL_V|EWPORT,viewport);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
--- Content provided by FirstRanker.com ---
glLoadldentity();gluPickMatrix((GLdoub|e) x, (GLdouble) (viewport[3]?y),N,N,viewport);
gluOrth02D(-5,5,-5,5);
drawObjects();
glMatrixMode(GL_PROJECTION);
--- Content provided by FirstRanker.com ---
glPopMatrixO;glFIush();
glutPostRedisplay();
}
}
--- Content provided by FirstRanker.com ---
void display(){
gICIear(GL_COLOR_BUFFER_BIT);
drawObjects();
glutSwapBuffersO;
--- Content provided by FirstRanker.com ---
}void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJECTION);
glLoadldentity();
--- Content provided by FirstRanker.com ---
gluOrth02D(-5,5,-S,5);glMatrixMode(GL_MODELV|EW);
}
int main(int argc, char **argv)
{
--- Content provided by FirstRanker.com ---
glutlnit(&argc,argv);glutlnitWindowSize(500,500);
glutlnitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutCreateWindow("Picking");
glutMouseFunc(mouse);
--- Content provided by FirstRanker.com ---
glutDisplayFunc(disp|ay);glutReshapeFunc(reshape);
glutMainLoop();
/*sample program on Menu using GLUT*/
--- Content provided by FirstRanker.com ---
#include#include
GLint size=2;
void display()
{
--- Content provided by FirstRanker.com ---
glClearCoIor(0.0,0.0,0.0,1.0);gICIear(GL_COLOR_BUFFER_BIT);
}
void reshape(GLint w, GLint h)
{
--- Content provided by FirstRanker.com ---
glMatrixMode(GL_PROJECTION);glLoadldentity();
gluOrth02D(-10,lO,-10,10);
glMatrixMode(GL_MODELV|EW);
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);
glEnd();
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: glCoIor3f(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("original",2);
glutAddMenuEntry("|ncrease",3);
glutAddMenuEntry("Decrease",4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
--- Content provided by FirstRanker.com ---
glutDisplayFunc(disp|ay);glutReshapeFunc(reshape);
glutMainLoop();
/* Program on sub menu*/
--- Content provided by FirstRanker.com ---
#include#include
GLint size=2;
int sub_menu;
void display()
--- Content provided by FirstRanker.com ---
{glClearCoIor(0.0,0.0,0.0,1.0);
gICIear(GL_COLOR_BUFFER_BIT);
}
void reshape(GLint w, GLint h)
--- Content provided by FirstRanker.com ---
{glMatrixMode(GL_PROJECTION);
glLoadldentity();
gluOrth02D(-10,lO,-10,10);
glMatrixMode(GL_MODELV|EW);
--- 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);
glEnd();
--- 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: glCoIor3f(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("original",2);
glutAddSubMenu("Resize", sub_menu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(disp|ay);
--- Content provided by FirstRanker.com ---
glutReshapeFunc(reshape);glutMainLoop();
/* Rotating square using double buffer */
#include
#include
--- Content provided by FirstRanker.com ---
#includeGLfloat theta, thetar;
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
--- Content provided by FirstRanker.com ---
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));
--- Content provided by FirstRanker.com ---
glVertex2f(-sin(thetar),cos(thetar));glVertex2f(-cos(thetar),-sin(thetar));
glVertex2f(sin(thetar),-cos(thetar));
glEndO;
//for Outer circle
--- Content provided by FirstRanker.com ---
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();
--- Content provided by FirstRanker.com ---
glutSwapBuffersO;}
//perform background processing tasks or continuous animation when window system events are not being received.
void idle()
{
--- Content provided by FirstRanker.com ---
theta+=2;if(theta>=360.0)
theta-=360.0;
glutPostRedisplayO;
}
--- Content provided by FirstRanker.com ---
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)
--- Content provided by FirstRanker.com ---
glutldleFunc(NULL);}
void reshape(int w, int h)
{
glMatrixMode(GL_PROJECTION);
--- Content provided by FirstRanker.com ---
glLoadldentity();glOrtho(-2,2,-2,2,2,-2);
glMatrixMode(GL_MODELV|EW);
glViewport(0,0,w,h);
}
--- Content provided by FirstRanker.com ---
int main(int argc, char **argv){
glutlnit(&argc, argv);
glutlnitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("rotate square");
--- Content provided by FirstRanker.com ---
glutDisplayFunc(disp|ay);glutReshapeFunc(reshape);
glutMouseFunc(myMouse);
glutMainLoop();
--- Content provided by FirstRanker.com ---