FirstRanker.com /**************************Picking program for Linux******************/
Firstranker's choice
#include<GL/glut.h>
--- Content provided by FirstRanker.com ---
#define N 5
GLdouble ww=500, wh=500;
void drawobject(GLenum mode)
{
if(mode==GL_RENDER);
--- Content provided by FirstRanker.com ---
{
glLoadName(1);
glColor3f(1.0,0.0,0.0);
glRectf(0.5,0.5,1.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];
--- Content provided by FirstRanker.com ---
GLint viewport[4];
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
glRenderMode(GL_RENDER);
glGetIntegerv(GL_VIEWPORT,viewport);
--- Content provided by FirstRanker.com ---
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix((GLdouble)x, (GLdouble)(viewport[3]-y),N,N,viewport);
gluOrtho2D(-5,5,-5,5);
--- Content provided by FirstRanker.com ---
drawobject(GL_RENDER);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glFlush();
glRenderMode(GL_SELECT);
--- Content provided by FirstRanker.com ---
glutPostRedisplay();
}
}
void display()
{
--- Content provided by FirstRanker.com ---
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
drawobject(GL_SELECT);
glFlush();
}
--- Content provided by FirstRanker.com ---
void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-5,5,-5,5);
--- Content provided by FirstRanker.com ---
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w,h);
ww=w;
wh=h;
}
--- Content provided by FirstRanker.com ---
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
glutInitWindowPosition(50,50);
--- Content provided by FirstRanker.com ---
glutInitWindowSize(ww,wh);
glutCreateWindow("picking example");
glutMouseFunc(myMouse);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
--- Content provided by FirstRanker.com ---
glutMainLoop();
return 1; }
Firstranker's choice
#include<windows.h>
--- Content provided by FirstRanker.com ---
#include<iostream>
#include<GL/glu.h>
#include<GL/glut.h>
#define N 2
using namespace std;
--- Content provided by FirstRanker.com ---
void drawObjects()
{
glLoadName(1);
glColor3f(1.0,0.0,0.0);
glRectf(0.5,0.5,1.0,1.0);
--- Content provided by FirstRanker.com ---
glLoadName(2);
glColor3f(0.0,0.0,1.0);
glRectf(-1.0,-1.0,-0.5,-0.5);
}
void mouse(int button, int state, int x, int y)
--- Content provided by FirstRanker.com ---
{
GLuint namebuffer[10];
GLint viewport[4];
if(button==GLUT_LEFT_BUTTON&&state==GLUT_DOWN)
{
--- Content provided by FirstRanker.com ---
glRenderMode(GL_SELECT);
gllnitNames();
glPushName(-1);
glSelectBuffer(10, namebuffer);
glGetIntegerv(GL_VIEWPORT,viewport);
--- Content provided by FirstRanker.com ---
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3]-y), N, N, viewport);
gluOrtho2D(-5,5,-5,5);
--- Content provided by FirstRanker.com ---
drawObjects();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glFlush();
glutPostRedisplay();
--- Content provided by FirstRanker.com ---
}
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
--- Content provided by FirstRanker.com ---
drawObjects();
glutSwapBuffers();
}
void reshape(GLint w, GLint h)
{
--- Content provided by FirstRanker.com ---
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-5,5,-5,5);
glMatrixMode(GL_MODELVIEW);
}
--- Content provided by FirstRanker.com ---
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitWindowSize(500,500);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
--- Content provided by FirstRanker.com ---
glutCreateWindow("Picking");
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
--- Content provided by FirstRanker.com ---
}
FirstRanker.com /*sample program on Menu using GLUT*/
Firstranker's choice
#include<windows.h>
#include<GL/glut.h>
--- Content provided by FirstRanker.com ---
GLint size=2;
void display()
{
glClearColor(0.0,0.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
--- Content provided by FirstRanker.com ---
}
void reshape(GLint w, GLint h)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
--- Content provided by FirstRanker.com ---
gluOrtho2D(-10,10,-10,10);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w,h);
}
void draw(int size)
--- Content provided by FirstRanker.com ---
{
glBegin(GL_POLYGON);
glVertex2f(-size, -size);
glVertex2f(size, -size);
glVertex2f(size, size);
--- Content provided by FirstRanker.com ---
glVertex2f(-size, size);
glEnd();
glFlush();
}
void demo_menu(int id)
--- Content provided by FirstRanker.com ---
{
switch(id)
{
case 1: exit(0);
break;
--- Content provided by FirstRanker.com ---
case 3: size=2*size;
glColor3f(0.0,0.0,1.0);
draw(size);
break;
case 4: if(size>3)
--- Content provided by FirstRanker.com ---
size=size/2;
glColor3f(0.0,1.0,0.0);
draw(size);
break;
case 2: glColor3f(1.0,0.0,1.0);
--- Content provided by FirstRanker.com ---
draw(size);
break;
}
}
glutPostRedisplay();
--- Content provided by FirstRanker.com ---
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH|GLUT_RGB|GLUT_SINGLE);
--- Content provided by FirstRanker.com ---
glutInitWindowPosition(50,50);
glutInitWindowSize(500,500);
glutCreateWindow("sample menu");
glutCreateMenu(demo_menu);
glutAddMenuEntry("Quit", 1);
--- Content provided by FirstRanker.com ---
glutAddMenuEntry("original",2);
glutAddMenuEntry("Increase",3);
glutAddMenuEntry("Decrease",4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(display);
--- Content provided by FirstRanker.com ---
glutReshapeFunc(reshape);
glutMainLoop();
}
FirstRanker.com /* Program on sub menu*/
Firstranker's choice
--- Content provided by FirstRanker.com ---
#include<windows.h>
#include<GL/glut.h>
GLint size=2;
int sub_menu;
void display()
--- Content provided by FirstRanker.com ---
{
glClearColor(0.0,0.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
}
void reshape(GLint w, GLint h)
--- Content provided by FirstRanker.com ---
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10,10,-10,10);
glMatrixMode(GL_MODELVIEW);
--- Content provided by FirstRanker.com ---
glViewport(0,0,w,h);
}
void draw(int size)
{
glBegin(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: glColor3f(1.0,0.0,1.0);
draw(size);
--- Content provided by FirstRanker.com ---
break;
case 3: size=2*size;
glColor3f(0.0,0.0,1.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 ---
}
}
glutPostRedisplay();
}
int main(int argc, char **argv)
--- Content provided by FirstRanker.com ---
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH|GLUT_RGB|GLUT_SINGLE);
glutInitWindowPosition(50,50);
glutInitWindowSize(500,500);
--- Content provided by FirstRanker.com ---
glutCreateWindow("sample menu");
sub_menu=glutCreateMenu(demo_menu);
glutAddMenuEntry("Increase",3);
glutAddMenuEntry("Decrease",4);
glutCreateMenu(demo_menu);
--- Content provided by FirstRanker.com ---
Firstranker's choice
glutAddMenuEntry("original",2);
glutAddSubMenu("Resize", sub_menu);
glutAttachMenu(GLUT_RIGHT_BUTTON);
--- Content provided by FirstRanker.com ---
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
}
/* Rotating square using double buffer */
--- Content provided by FirstRanker.com ---
#include<windows.h>
#include<GL/glut.h>
#include<math.h>
GLfloat theta, thetar;
void display()
--- Content provided by FirstRanker.com ---
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glDrawBuffer(GL_FRONT_AND_BACK);
glColor3f(0.0,0.0,1.0);
--- Content provided by FirstRanker.com ---
thetar = theta/(3.141/180.0);
glVertex2f(cos(thetar),sin(thetar));
glVertex2f(-sin(thetar),cos(thetar));
glVertex2f(-cos(thetar),-sin(thetar));
glVertex2f(sin(thetar),-cos(thetar));
--- Content provided by FirstRanker.com ---
glEnd();
//for Outer circle
glBegin(GL_POINTS);
GLfloat r=1.0;
for(int i=0;i<=360;i++)
--- Content provided by FirstRanker.com ---
glVertex2f(cos(i*(3.141/180))*r, sin(i*(3.141/180))*r);
glEnd();
glutSwapBuffers();
//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;
glutPostRedisplay();
--- Content provided by FirstRanker.com ---
}
void myMouse(int btn, int state, int x, int y)
{
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
glutIdleFunc(idle);
--- Content provided by FirstRanker.com ---
if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
glutIdleFunc(NULL);
}
void reshape(int w, int h)
{
--- Content provided by FirstRanker.com ---
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glOrtho(-2,2,-2,2,2,-2);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w,h);
--- Content provided by FirstRanker.com ---
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
--- Content provided by FirstRanker.com ---
glutCreateWindow("rotate square");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
Mpuse funcimy Mouseioice
--- Content provided by FirstRanker.com ---
glutMainLoop();
}
--- Content provided by FirstRanker.com ---
This download link is referred from the post: AKTU B-Tech Last 10 Years 2010-2020 Previous Question Papers || Dr. A.P.J. Abdul Kalam Technical University