Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * GLUT Shapes Demo
- *
- * Written by Nigel Stewart November 2003
- *
- * This program is test harness for the sphere, cone
- * and torus shapes in GLUT.
- *
- * Spinning wireframe and smooth shaded shapes are
- * displayed until the ESC or q key is pressed. The
- * number of geometry stacks and slices can be adjusted
- * using the + and - keys.
- */
- #include <windows.h>
- /*
- * GLUT Shapes Demo
- *
- * Written by Nigel Stewart November 2003
- *
- * This program is test harness for the sphere, cone
- * and torus shapes in GLUT.
- *
- * Spinning wireframe and smooth shaded shapes are
- * displayed until the ESC or q key is pressed. The
- * number of geometry stacks and slices can be adjusted
- * using the + and - keys.
- */
- #include<windows.h>
- #ifdef __APPLE__
- #include <GLUT/glut.h>
- #else
- #include <GL/glut.h>
- #endif
- #include <stdlib.h>
- static int slices = 16;
- static int stacks = 16;
- float degree=0.0,deg=0.0,deg2=0.0;
- /* GLUT callback Handlers */
- static void resize(int width, int height)
- {
- const float ar = (float) width / (float) height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-ar, ar, -1.0, 4.0, 4.0, 100.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity() ;
- //gluLookAt(1,1,1,1,1,0,0,-1,0);
- }
- void Cube()
- {
- //Basement
- glBegin(GL_QUADS);
- glColor3d(1,0,0);
- glVertex3f(0.0,2.0,10.0);
- glVertex3f(0.0,0.0,10.0);
- glVertex3f(10.0,0.0,10.0);
- glVertex3f(10.0,2.0,10.0);
- glColor3d(0,1,0);
- glVertex3f(10.0,2.0,10.0);
- glVertex3f(10.0,0.0,10.0);
- glVertex3f(10.0,0.0,0.0);
- glVertex3f(10.0,2.0,0.0);
- glColor3d(0,0,1);
- glVertex3f(0.0,2.0,0.0);
- glVertex3f(10.0,2.0,0.0);
- glVertex3f(10.0,0.0,0.0);
- glVertex3f(0.0,0.0,0.0);
- glColor3d(1,0,1);
- glVertex3f(0.0,2.0,0.0);
- glVertex3f(0.0,0.0,0.0);
- glVertex3f(0.0,0.0,10.0);
- glVertex3f(0.0,2.0,10.0);
- glColor3d(1,1,0);
- glVertex3f(0.0,0.0,0.0);
- glVertex3f(10.0,0.0,0.0);
- glVertex3f(10.0,0.0,10.0);
- glVertex3f(0.0,0.0,10.0);
- glColor3d(0,1,1);
- glVertex3f(0.0,2.0,0.0);
- glVertex3f(0.0,2.0,10.0);
- glVertex3f(10.0,2.0,10.0);
- glVertex3f(10.0,2.0,0.0);
- glEnd();
- //Upper board
- glBegin(GL_QUADS);
- glColor3d(1,0,0);
- glVertex3f(2.5,12.0,7.5);
- glVertex3f(2.5,10.0,7.5);
- glVertex3f(7.5,10.0,7.5);
- glVertex3f(7.5,12.0,7.5);
- glColor3d(0,1,0);
- glVertex3f(7.5,12.0,7.5);
- glVertex3f(7.5,10.0,7.5);
- glVertex3f(7.5,10.0,2.5);
- glVertex3f(7.5,12.0,2.5);
- glColor3d(0,0,1);
- glVertex3f(2.5,12.0,2.5);
- glVertex3f(7.5,12.0,2.5);
- glVertex3f(7.5,10.0,2.5);
- glVertex3f(2.5,10.0,2.5);
- glColor3d(1,0,1);
- glVertex3f(2.5,12.0,2.5);
- glVertex3f(2.5,10.0,2.5);
- glVertex3f(2.5,10.0,7.5);
- glVertex3f(2.5,12.0,7.5);
- glColor3d(1,1,0);
- glVertex3f(2.5,10.0,2.5);
- glVertex3f(7.5,10.0,2.5);
- glVertex3f(7.5,10.0,7.5);
- glVertex3f(2.5,10.0,7.5);
- glColor3d(0,1,1);
- glVertex3f(2.5,12.0,2.5);
- glVertex3f(2.5,12.0,7.5);
- glVertex3f(7.5,12.0,7.5);
- glVertex3f(7.5,12.0,2.5);
- glEnd();
- //legs 1
- glBegin(GL_QUADS);
- glColor3d(1,0,0);
- glVertex3f(0,0,10);
- glVertex3f(1,0,10);
- glVertex3f(5,20,6);
- glVertex3f(4,20,6);
- glColor3d(0,1,0);
- glVertex3f(1,0,10);
- glVertex3f(0,0,9);
- glVertex3f(4,20,5);
- glVertex3f(5,20,6);
- glColor3d(0,0,1);
- glVertex3f(4,20,5);
- glVertex3f(0,0,9);
- glVertex3f(0,0,10);
- glVertex3f(4,20,6);
- glEnd();
- //2
- glBegin(GL_QUADS);
- glColor3d(1,0,0);
- glVertex3f(5,20,6);
- glVertex3f(9,0,10);
- glVertex3f(10,0,10);
- glVertex3f(6,20,6);
- glColor3d(0,1,0);
- glVertex3f(6,20,6);
- glVertex3f(10,0,10);
- glVertex3f(10,0,9);
- glVertex3f(6,20,5);
- glColor3d(0,0,1);
- glVertex3f(5,20,6);
- glVertex3f(6,20,5);
- glVertex3f(10,0,9);
- glVertex3f(9,0,10);
- glEnd();
- //3
- glBegin(GL_QUADS);
- glColor3d(1,0,0);
- glVertex3f(6,20,5);
- glVertex3f(10,0,1);
- glVertex3f(10,0,0);
- glVertex3f(6,20,4);
- glColor3d(0,1,0);
- glVertex3f(6,20,4);
- glVertex3f(10,0,0);
- glVertex3f(9,0,0);
- glVertex3f(5,20,4);
- glColor3d(0,0,1);
- glVertex3f(6,20,5);
- glVertex3f(5,20,4);
- glVertex3f(9,0,0);
- glVertex3f(10,0,1);
- glEnd();
- //4
- glBegin(GL_QUADS);
- glColor3d(1,0,0);
- glVertex3f(5,20,4);
- glVertex3f(4,20,5);
- glVertex3f(0,0,1);
- glVertex3f(1,0,0);
- glColor3d(0,1,0);
- glVertex3f(4,20,4);
- glVertex3f(5,20,4);
- glVertex3f(1,0,0);
- glVertex3f(0,0,0);
- glColor3d(0,0,1);
- glVertex3f(4,20,5);
- glVertex3f(4,20,4);
- glVertex3f(0,0,0);
- glVertex3f(0,0,1);
- glEnd();
- //up
- glBegin(GL_QUADS);
- glColor3d(1,0,0);
- glVertex3f(4,20,8);
- glVertex3f(6,20,8);
- glVertex3f(6,24,8);
- glVertex3f(4,24,8);
- glColor3d(0,1,0);
- glVertex3f(6,24,8);
- glVertex3f(6,20,8);
- glVertex3f(6,20,4);
- glVertex3f(6,24,4);
- glColor3d(0,0,1);
- glVertex3f(6,20,4);
- glVertex3f(4,20,4);
- glVertex3f(4,24,4);
- glVertex3f(6,24,4);
- glColor3d(1,0,1);
- glVertex3f(4,24,4);
- glVertex3f(4,20,4);
- glVertex3f(4,20,8);
- glVertex3f(4,24,8);
- glColor3d(1,1,0);
- glVertex3f(6,24,4);
- glVertex3f(4,24,4);
- glVertex3f(4,24,8);
- glVertex3f(6,24,8);
- glColor3d(0,1,1);
- glVertex3f(6,20,8);
- glVertex3f(4,20,8);
- glVertex3f(4,20,4);
- glVertex3f(6,20,4);
- glEnd();
- }
- static void display(void)
- {
- const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
- const double a = t*90.0;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glColor3d(1,0,0);
- glPushMatrix();
- glTranslated(-2,-4,-30);
- glRotatef(degree,0,1,0);
- glRotatef(deg,0,0,1);
- glRotatef(deg2,1,0,0);
- glScalef(.3, .3, .3);
- Cube();
- glPopMatrix();
- glutSwapBuffers();
- }
- static void key(unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 27 :
- case 'q':
- exit(0);
- break;
- case 'y' :
- degree += 3.5;
- break;
- case 'z' :
- deg += 3.5;
- break;
- case 'x' :
- deg2 += 3.5;
- break;
- case '+':
- slices++;
- stacks++;
- break;
- case '-':
- if (slices>3 && stacks>3)
- {
- slices--;
- stacks--;
- }
- break;
- }
- glutPostRedisplay();
- }
- static void idle(void)
- {
- glutPostRedisplay();
- }
- const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
- const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
- const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
- const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
- const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- const GLfloat high_shininess[] = { 100.0f };
- /* Program entry point */
- int main(int argc, char *argv[])
- {
- glutInit(&argc, argv);
- glutInitWindowSize(640,480);
- glutInitWindowPosition(10,10);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("GLUT Shapes");
- glutReshapeFunc(resize);
- glutDisplayFunc(display);
- glutKeyboardFunc(key);
- glutIdleFunc(idle);
- glClearColor(1,1,1,1);
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LESS);
- glutMainLoop();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement