#include <iostream>
using namespace std;
#include <gl/glut.h>
int X = 0, Y = 1, Z = 0, wire = 0, ObjectLbl, choice=0;
GLfloat a = 0., b = 0., c = 0., x = 0., y = 0., z = 0., spin = 0., x1 = .2, yy1 = .2, z1
= .2, h = 2, w = 2;
//notice y1 is a reserved name, so I used yy1 instead
GLfloat mat_ambient[] = { .0, 1, .0, 1.0 };
GLfloat mat_specular[] = { .5, .5, 0, 1.0 };
GLfloat mat_shininess[] = { 200. }; //this needs specular (work together)
GLfloat light0_position[] = { 8., 8., -5., .0 };
GLfloat mat_diffuse[] = { 2.0, 0.0, 0.0, 1.0 };
GLfloat mat_diffuse1[] = { 1.0, 0.5, 0.0, 1.0 };
GLfloat mat_diffuse2[] = { 1.5, 0.0, 2.0, 1.0 };
GLfloat mat_diffuse3[] = { 0.3, 0.2, 0.8, 0.0 };
GLfloat mat_diffuse4[] = { 2.0, 0.0, 0.0, 2.0 };
GLfloat mat_diffuse5[] = { 1.5, 0.0, 2.0, 0.0 };
GLfloat mat_diffuse6[] = { 0.0, 2.5, 0.0, 1.0 };
GLfloat mat_diffuse7[] = { 0.0, 2.0, 2.0, 0.0 };
GLfloat mat_diffuse8[] = { 2.0, 2.0, 2.0, 2.0 };
GLfloat mat_diffuse9[] = { 0.0, 0.0, 1.0, 0.0 };
void init(void)
{
glClearColor(.5, .5, .5, .5); //background
glShadeModel(GL_FLAT); //default: SMOOTH
//glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
//glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
glLightfv(GL_LIGHT0, GL_SPECULAR, mat_ambient);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
cout << "nUse:n '?' 'x' 'y' 'z' 'a' 'b' 'c' 'w' 's' 'S' ' ' keys for
animationn" << endl;
glEnable(GL_DEPTH_TEST);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//1
glPushMatrix();
glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse5);
if (choice == 1){ glTranslatef(-.8 + a, .5 + b, 0 + c); }
else{glTranslatef(-.8, .5, 0);}
if (choice == 1 || choice == 0)glRotatef(spin, X, Y, Z);
if (choice == 1 || choice == 0){ glScalef(x1, yy1, z1); }
else{ glScalef(.2, .2, .2); }
glutWireCube(.7);
glPopMatrix();
//2
glPushMatrix();
glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse6);
if (choice == 2){ glTranslatef(-.5 + a, .5 + b, 0 + c); }
else{ glTranslatef(-.5, .5, 0); }
if (choice == 2 || choice == 0)glRotatef(spin, X, Y, Z);
if (choice == 2 || choice == 0){ glScalef(x1, yy1, z1); }
else{ glScalef(.2, .2, .2); }
glutWireTeapot(.3);
glPopMatrix();
//3
glPushMatrix();
glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse7);
if (choice == 3){ glTranslatef(-.2 + a, .5 + b, 0 + c); }
else{ glTranslatef(-.2, .5, 0); }
if (choice == 3 || choice == 0)glRotatef(spin, X, Y, Z);
if (choice == 3 || choice == 0){ glScalef(x1, yy1, z1); }
else{ glScalef(.2, .2, .2); }
glutWireCube(.7);
glPopMatrix();
//4
glPushMatrix();
glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse8);
if (choice == 4){ glTranslatef(.1 + a, .5 + b, 0 + c); }
else{ glTranslatef(.1, .5, 0); }
if (choice == 4 || choice == 0)glRotatef(spin, X, Y, Z);
if (choice == 4 || choice == 0){ glScalef(x1, yy1, z1); }
else{ glScalef(.2, .2, .2); }
glutWireTeapot(.3);
glPopMatrix();
//5
glPushMatrix();
glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse9);
if (choice == 5){ glTranslatef(.4 + a, .5 + b, 0 + c); }
else{ glTranslatef(.4, .5, 0); }
if (choice == 5 || choice == 0)glRotatef(spin, X, Y, Z);
if (choice == 5 || choice == 0){ glScalef(x1, yy1, z1); }
else{ glScalef(.2, .2, .2); }
glutWireCube(.7);
glPopMatrix();
//6
glPushMatrix();
glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse);
if (choice == 6){ glTranslatef(-.8 + a, .0 + b, 0 + c); }
else{ glTranslatef(-.8, .0, 0); }
if (choice == 6 || choice == 0)glRotatef(spin, X, Y, Z);
if (choice == 6 || choice == 0){ glScalef(x1, yy1, z1); }
else{ glScalef(.2, .2, .2); }
if (wire)glutSolidSphere(.5, 16, 8);
else glutWireSphere(.5, 16, 8);
glPopMatrix();
//7
glPushMatrix();
glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse1);
if (choice == 7){ glTranslatef(-.5 + a, .0 + b, 0 + c); }
else{ glTranslatef(-.5, .0, 0); }
if (choice == 7 || choice == 0)glRotatef(spin, X, Y, Z);
if (choice == 7 || choice == 0){ glScalef(x1, yy1, z1); }
else{ glScalef(.2, .2, .2); }
if (wire)glutSolidCube(.7);
else glutWireCube(.7);
glPopMatrix();
//8
glPushMatrix();
glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse2);
if (choice == 8){ glTranslatef(-.2 + a, .0 + b, 0 + c); }
else{ glTranslatef(-.2, .0, 0); }
if (choice == 8 || choice == 0)glRotatef(spin, X, Y, Z);
if (choice == 8 || choice == 0){ glScalef(x1, yy1, z1); }
else{ glScalef(.2, .2, .2); }
if (wire)glutSolidSphere(.5, 16, 8);
else glutWireSphere(.5, 16, 8);
glPopMatrix();
//9
glPushMatrix();
glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse3);
if (choice == 3){ glTranslatef(.1 + a, .0 + b, 0 + c); }
else{ glTranslatef(.1, .0, 0); }
if (choice == 9 || choice == 0)glRotatef(spin, X, Y, Z);
if (choice == 9 || choice == 0){ glScalef(x1, yy1, z1); }
else{ glScalef(.2, .2, .2); }
if (wire)glutSolidCube(.7);
else glutWireCube(.7);
glPopMatrix();
//10
glPushMatrix();
glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse4);
if (choice == 3){ glTranslatef(.4 + a, .0 + b, 0 + c); }
else{ glTranslatef(.4, .0, 0); }
if (choice == 10 || choice == 0)glRotatef(spin, X, Y, Z);
if (choice == 10 || choice == 0){ glScalef(x1, yy1, z1); }
else{ glScalef(.2, .2, .2); }
if (wire)glutSolidSphere(.5, 16, 8);
else glutWireSphere(.5, 16, 8);
glPopMatrix();
glutSwapBuffers();
}
void spinDisplay()
{
spin += 1; if (spin>360.)spin = 0.;
glutPostRedisplay();
}
void keyboard(unsigned char key, int xx, int yy)
{
switch (key)
{
case '?': cout << "nUse:n '?' 'x' 'y' 'z' 'a' 'b' 'c' 'w' 's' 'S' ' ' keys
for animationn" << endl; break;
case 'x': X = 1; Y = Z = 0; break;
case 'y': Y = 1; X = Z = 0; break;
case 'z': Z = 1; X = Y = 0; break;
case 'a': a += .01; break;
case 'b': b += .01; break;
case 'c': c += .01; break;
case 'A': a -= .01; break;
case 'B': b -= .01; break;
case 'C': c -= .01; break;
case 'h': x1 += .1; break;
case 'v': yy1 += .1; break;
case 'd': z1 += .1; break;
case 'H': x1 -= .1; break;
case 'V': yy1 -= .1; break;
case 'D': z1 -= .1; break;
case ' ': spin = x = y = z = .0; break;
case 'w': wire = ++wire % 2; break;
case 's': glShadeModel(GL_SMOOTH); break;
case 'S': glShadeModel(GL_FLAT); break;
}
glutPostRedisplay();
}
int ObjectSpin(int x, int y)
{
if (x >= 70 && x <= 230 && y >= 54 && y <= 140){
ObjectLbl = 1; }
if (x >= 273 && x <= 491 && y >= 67 && y <= 140){
ObjectLbl = 2; }
if (x >= 520 && x <= 680 && y >= 54 && y <= 140){
ObjectLbl = 3; }
if (x >= 723 && x <= 941 && y >= 67 && y <= 140){
ObjectLbl = 4; }
if (x >= 970 && x <= 1120 && y >= 54 && y <= 140){
ObjectLbl = 5; }
if (x >= 37 && x <= 260 && y >= 242 && y <= 360){
ObjectLbl = 6; }
if (x >= 296 && x <= 453 && y >= 256 && y <= 344){
ObjectLbl = 7; }
if (x >= 487 && x <= 711 && y >= 242 && y <= 360){
ObjectLbl = 8; }
if (x >= 746 && x <= 903 && y >= 256 && y <= 344){
ObjectLbl = 9; }
if (x >= 937 && x <= 1162 && y >= 242 && y <= 360){
ObjectLbl = 10; }
return ObjectLbl;
}
void mouse(int button, int state, int xx, int yy)
{
glutIdleFunc(spinDisplay);
switch (button)
{
case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) { choice = ObjectSpin(xx,yy); X =
1; Y =1, Z = -1; } break;
case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN){ choice = 0; }break;
//glutIdleFunc(NULL);
}
glutPostRedisplay();
}
void reshape(int w, int h)
{
glViewport(0., 0., 1500., 800.);
glLoadIdentity();
gluPerspective(80., (GLfloat)w / (GLfloat)h, .1, 190.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //important: last line must be glLoadIdentity() for coloring
with openGL
// glTranslatef (.0, .0, -4.); //do not translate at all if glLoadIdentity() is
used
}
void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(1200, 700); glutInitWindowPosition(0, 0);
glutCreateWindow("Brian's GLUT Window");
init();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keyboard);
glutReshapeFunc(reshape);
glutMainLoop();
}
//////////////////////////////////////////// END OF PROGRAM
///////////////////////////////////

More Related Content

PDF
ASFWS 2012 - Obfuscator, ou comment durcir un code source ou un binaire contr...
DOCX
Robot Motion Source code
PDF
The Ring programming language version 1.5.1 book - Part 51 of 180
PDF
D3.js workshop
PDF
The Ring programming language version 1.7 book - Part 57 of 196
PDF
The Ring programming language version 1.8 book - Part 59 of 202
PDF
Tabela derivada
ZIP
Disney Effects: Building web/mobile castle in OpenGL 2D & 3D
ASFWS 2012 - Obfuscator, ou comment durcir un code source ou un binaire contr...
Robot Motion Source code
The Ring programming language version 1.5.1 book - Part 51 of 180
D3.js workshop
The Ring programming language version 1.7 book - Part 57 of 196
The Ring programming language version 1.8 book - Part 59 of 202
Tabela derivada
Disney Effects: Building web/mobile castle in OpenGL 2D & 3D

What's hot (20)

PDF
D3 svg & angular
PPTX
Scrollytelling
PDF
The Ring programming language version 1.10 book - Part 64 of 212
PPT
X2 T05 06 Partial Fractions
PDF
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
PDF
The Ring programming language version 1.5.4 book - Part 59 of 185
PPTX
ES6(ES2015) is beautiful
PDF
The Ring programming language version 1.6 book - Part 62 of 189
PDF
Tabela completa de derivadas e integrais
PDF
Ejercicio 211 del libro de baldor
PDF
Proga 0622
PPTX
Михаил Матросов, Повседневный С++: boost и STL
PDF
統計的学習の基礎 4章 前半
DOCX
Numerical Method Assignment
PPTX
Unification and Refactoring of Clones
DOCX
Cg my own programs
PDF
The Ring programming language version 1.10 book - Part 81 of 212
DOC
Ocr code
PDF
Python speleology
PDF
Ejercicio 211 del libro de Baldor
D3 svg & angular
Scrollytelling
The Ring programming language version 1.10 book - Part 64 of 212
X2 T05 06 Partial Fractions
第13回数学カフェ「素数!!」二次会 LT資料「乱数!!」
The Ring programming language version 1.5.4 book - Part 59 of 185
ES6(ES2015) is beautiful
The Ring programming language version 1.6 book - Part 62 of 189
Tabela completa de derivadas e integrais
Ejercicio 211 del libro de baldor
Proga 0622
Михаил Матросов, Повседневный С++: boost и STL
統計的学習の基礎 4章 前半
Numerical Method Assignment
Unification and Refactoring of Clones
Cg my own programs
The Ring programming language version 1.10 book - Part 81 of 212
Ocr code
Python speleology
Ejercicio 211 del libro de Baldor
Ad

Similar to openGl example (20)

DOCX
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
PDF
Tutorial Open GL (Listing Code)
DOCX
DOCX
Transformasi 2 dmensi
DOCX
computer graphics opengl programs for cse students
PDF
Ssaw08 0624
PDF
10CSL67 CG LAB PROGRAM 8
PDF
CG OpenGL Shadows + Light + Texture -course 10
PDF
The Ring programming language version 1.10 book - Part 66 of 212
PDF
The Ring programming language version 1.5.3 book - Part 65 of 184
PDF
The Ring programming language version 1.5.4 book - Part 60 of 185
PDF
The Ring programming language version 1.8 book - Part 66 of 202
PDF
10CSL67 CG LAB PROGRAM 3
PDF
The Ring programming language version 1.9 book - Part 65 of 210
PDF
Apply physics laws to the circles- When a circle hits one of the sides.pdf
PDF
2Bytesprog2 course_2014_c9_graph
PDF
The Ring programming language version 1.6 book - Part 57 of 189
DOCX
Programa de objetos 3 d wire
TXT
Ass day2 1_checkerboard...copy in cpp
DOCX
Computer Graphics and Multimedia lab report
#includefloat angle, move, scene, roadmove,turn, on=1; int i, st.docx
Tutorial Open GL (Listing Code)
Transformasi 2 dmensi
computer graphics opengl programs for cse students
Ssaw08 0624
10CSL67 CG LAB PROGRAM 8
CG OpenGL Shadows + Light + Texture -course 10
The Ring programming language version 1.10 book - Part 66 of 212
The Ring programming language version 1.5.3 book - Part 65 of 184
The Ring programming language version 1.5.4 book - Part 60 of 185
The Ring programming language version 1.8 book - Part 66 of 202
10CSL67 CG LAB PROGRAM 3
The Ring programming language version 1.9 book - Part 65 of 210
Apply physics laws to the circles- When a circle hits one of the sides.pdf
2Bytesprog2 course_2014_c9_graph
The Ring programming language version 1.6 book - Part 57 of 189
Programa de objetos 3 d wire
Ass day2 1_checkerboard...copy in cpp
Computer Graphics and Multimedia lab report
Ad

openGl example

  • 1. #include <iostream> using namespace std; #include <gl/glut.h> int X = 0, Y = 1, Z = 0, wire = 0, ObjectLbl, choice=0; GLfloat a = 0., b = 0., c = 0., x = 0., y = 0., z = 0., spin = 0., x1 = .2, yy1 = .2, z1 = .2, h = 2, w = 2; //notice y1 is a reserved name, so I used yy1 instead GLfloat mat_ambient[] = { .0, 1, .0, 1.0 }; GLfloat mat_specular[] = { .5, .5, 0, 1.0 }; GLfloat mat_shininess[] = { 200. }; //this needs specular (work together) GLfloat light0_position[] = { 8., 8., -5., .0 }; GLfloat mat_diffuse[] = { 2.0, 0.0, 0.0, 1.0 }; GLfloat mat_diffuse1[] = { 1.0, 0.5, 0.0, 1.0 }; GLfloat mat_diffuse2[] = { 1.5, 0.0, 2.0, 1.0 }; GLfloat mat_diffuse3[] = { 0.3, 0.2, 0.8, 0.0 }; GLfloat mat_diffuse4[] = { 2.0, 0.0, 0.0, 2.0 }; GLfloat mat_diffuse5[] = { 1.5, 0.0, 2.0, 0.0 }; GLfloat mat_diffuse6[] = { 0.0, 2.5, 0.0, 1.0 }; GLfloat mat_diffuse7[] = { 0.0, 2.0, 2.0, 0.0 }; GLfloat mat_diffuse8[] = { 2.0, 2.0, 2.0, 2.0 }; GLfloat mat_diffuse9[] = { 0.0, 0.0, 1.0, 0.0 }; void init(void) { glClearColor(.5, .5, .5, .5); //background glShadeModel(GL_FLAT); //default: SMOOTH //glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); //glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, light0_position); glLightfv(GL_LIGHT0, GL_SPECULAR, mat_ambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); cout << "nUse:n '?' 'x' 'y' 'z' 'a' 'b' 'c' 'w' 's' 'S' ' ' keys for animationn" << endl; glEnable(GL_DEPTH_TEST); } void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //1 glPushMatrix(); glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse5); if (choice == 1){ glTranslatef(-.8 + a, .5 + b, 0 + c); } else{glTranslatef(-.8, .5, 0);} if (choice == 1 || choice == 0)glRotatef(spin, X, Y, Z); if (choice == 1 || choice == 0){ glScalef(x1, yy1, z1); } else{ glScalef(.2, .2, .2); }
  • 2. glutWireCube(.7); glPopMatrix(); //2 glPushMatrix(); glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse6); if (choice == 2){ glTranslatef(-.5 + a, .5 + b, 0 + c); } else{ glTranslatef(-.5, .5, 0); } if (choice == 2 || choice == 0)glRotatef(spin, X, Y, Z); if (choice == 2 || choice == 0){ glScalef(x1, yy1, z1); } else{ glScalef(.2, .2, .2); } glutWireTeapot(.3); glPopMatrix(); //3 glPushMatrix(); glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse7); if (choice == 3){ glTranslatef(-.2 + a, .5 + b, 0 + c); } else{ glTranslatef(-.2, .5, 0); } if (choice == 3 || choice == 0)glRotatef(spin, X, Y, Z); if (choice == 3 || choice == 0){ glScalef(x1, yy1, z1); } else{ glScalef(.2, .2, .2); } glutWireCube(.7); glPopMatrix(); //4 glPushMatrix(); glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse8); if (choice == 4){ glTranslatef(.1 + a, .5 + b, 0 + c); } else{ glTranslatef(.1, .5, 0); } if (choice == 4 || choice == 0)glRotatef(spin, X, Y, Z); if (choice == 4 || choice == 0){ glScalef(x1, yy1, z1); } else{ glScalef(.2, .2, .2); } glutWireTeapot(.3); glPopMatrix(); //5 glPushMatrix(); glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse9); if (choice == 5){ glTranslatef(.4 + a, .5 + b, 0 + c); } else{ glTranslatef(.4, .5, 0); } if (choice == 5 || choice == 0)glRotatef(spin, X, Y, Z); if (choice == 5 || choice == 0){ glScalef(x1, yy1, z1); } else{ glScalef(.2, .2, .2); } glutWireCube(.7); glPopMatrix(); //6 glPushMatrix(); glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse); if (choice == 6){ glTranslatef(-.8 + a, .0 + b, 0 + c); } else{ glTranslatef(-.8, .0, 0); } if (choice == 6 || choice == 0)glRotatef(spin, X, Y, Z);
  • 3. if (choice == 6 || choice == 0){ glScalef(x1, yy1, z1); } else{ glScalef(.2, .2, .2); } if (wire)glutSolidSphere(.5, 16, 8); else glutWireSphere(.5, 16, 8); glPopMatrix(); //7 glPushMatrix(); glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse1); if (choice == 7){ glTranslatef(-.5 + a, .0 + b, 0 + c); } else{ glTranslatef(-.5, .0, 0); } if (choice == 7 || choice == 0)glRotatef(spin, X, Y, Z); if (choice == 7 || choice == 0){ glScalef(x1, yy1, z1); } else{ glScalef(.2, .2, .2); } if (wire)glutSolidCube(.7); else glutWireCube(.7); glPopMatrix(); //8 glPushMatrix(); glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse2); if (choice == 8){ glTranslatef(-.2 + a, .0 + b, 0 + c); } else{ glTranslatef(-.2, .0, 0); } if (choice == 8 || choice == 0)glRotatef(spin, X, Y, Z); if (choice == 8 || choice == 0){ glScalef(x1, yy1, z1); } else{ glScalef(.2, .2, .2); } if (wire)glutSolidSphere(.5, 16, 8); else glutWireSphere(.5, 16, 8); glPopMatrix(); //9 glPushMatrix(); glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse3); if (choice == 3){ glTranslatef(.1 + a, .0 + b, 0 + c); } else{ glTranslatef(.1, .0, 0); } if (choice == 9 || choice == 0)glRotatef(spin, X, Y, Z); if (choice == 9 || choice == 0){ glScalef(x1, yy1, z1); } else{ glScalef(.2, .2, .2); } if (wire)glutSolidCube(.7); else glutWireCube(.7); glPopMatrix(); //10 glPushMatrix(); glLightfv(GL_LIGHT0, GL_DIFFUSE, mat_diffuse4); if (choice == 3){ glTranslatef(.4 + a, .0 + b, 0 + c); } else{ glTranslatef(.4, .0, 0); } if (choice == 10 || choice == 0)glRotatef(spin, X, Y, Z); if (choice == 10 || choice == 0){ glScalef(x1, yy1, z1); } else{ glScalef(.2, .2, .2); } if (wire)glutSolidSphere(.5, 16, 8); else glutWireSphere(.5, 16, 8); glPopMatrix();
  • 4. glutSwapBuffers(); } void spinDisplay() { spin += 1; if (spin>360.)spin = 0.; glutPostRedisplay(); } void keyboard(unsigned char key, int xx, int yy) { switch (key) { case '?': cout << "nUse:n '?' 'x' 'y' 'z' 'a' 'b' 'c' 'w' 's' 'S' ' ' keys for animationn" << endl; break; case 'x': X = 1; Y = Z = 0; break; case 'y': Y = 1; X = Z = 0; break; case 'z': Z = 1; X = Y = 0; break; case 'a': a += .01; break; case 'b': b += .01; break; case 'c': c += .01; break; case 'A': a -= .01; break; case 'B': b -= .01; break; case 'C': c -= .01; break; case 'h': x1 += .1; break; case 'v': yy1 += .1; break; case 'd': z1 += .1; break; case 'H': x1 -= .1; break; case 'V': yy1 -= .1; break; case 'D': z1 -= .1; break; case ' ': spin = x = y = z = .0; break; case 'w': wire = ++wire % 2; break; case 's': glShadeModel(GL_SMOOTH); break; case 'S': glShadeModel(GL_FLAT); break; } glutPostRedisplay(); } int ObjectSpin(int x, int y) { if (x >= 70 && x <= 230 && y >= 54 && y <= 140){ ObjectLbl = 1; } if (x >= 273 && x <= 491 && y >= 67 && y <= 140){ ObjectLbl = 2; } if (x >= 520 && x <= 680 && y >= 54 && y <= 140){ ObjectLbl = 3; } if (x >= 723 && x <= 941 && y >= 67 && y <= 140){ ObjectLbl = 4; } if (x >= 970 && x <= 1120 && y >= 54 && y <= 140){ ObjectLbl = 5; } if (x >= 37 && x <= 260 && y >= 242 && y <= 360){ ObjectLbl = 6; } if (x >= 296 && x <= 453 && y >= 256 && y <= 344){
  • 5. ObjectLbl = 7; } if (x >= 487 && x <= 711 && y >= 242 && y <= 360){ ObjectLbl = 8; } if (x >= 746 && x <= 903 && y >= 256 && y <= 344){ ObjectLbl = 9; } if (x >= 937 && x <= 1162 && y >= 242 && y <= 360){ ObjectLbl = 10; } return ObjectLbl; } void mouse(int button, int state, int xx, int yy) { glutIdleFunc(spinDisplay); switch (button) { case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) { choice = ObjectSpin(xx,yy); X = 1; Y =1, Z = -1; } break; case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN){ choice = 0; }break; //glutIdleFunc(NULL); } glutPostRedisplay(); } void reshape(int w, int h) { glViewport(0., 0., 1500., 800.); glLoadIdentity(); gluPerspective(80., (GLfloat)w / (GLfloat)h, .1, 190.); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //important: last line must be glLoadIdentity() for coloring with openGL // glTranslatef (.0, .0, -4.); //do not translate at all if glLoadIdentity() is used } void main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(1200, 700); glutInitWindowPosition(0, 0); glutCreateWindow("Brian's GLUT Window"); init(); glutDisplayFunc(display); glutMouseFunc(mouse); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); glutMainLoop(); } //////////////////////////////////////////// END OF PROGRAM ///////////////////////////////////