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>
- #include <GL/glut.h>
- #include<GL/gl.h>
- //#include<windows.h>
- #include <stdlib.h>
- #include <stdio.h>
- double Txval=0,Tyval=0,sval=0,rotat=0;
- bool flagScale=true;
- int windowWidth=1000,windowHeight=1000;
- void rectangle()
- {
- glBegin(GL_POLYGON);//Denotes the beginning of a group of vertices that define one or more primitives.
- glColor3f(0.0,1.0,0.0);
- glVertex2f(0.0,1.0);
- glColor3f(0.0,1.0,0.0);
- glVertex2f(2.0,1.0);
- glColor3f(1.0,0.0,0.0);
- glVertex2f(2.0,0.0);
- glColor3f(1.0,0.0,0.0);
- glVertex2f(0.0,0.0);
- glEnd(); //Terminates a list of vertices that specify a primitive initiated by glBegin.
- }
- void cube()
- {
- glBegin(GL_QUADS); // Begin drawing the color cube with 6 quads
- // Top face (y = 1.0f)
- // Define vertices in counter-clockwise (CCW) order with normal pointing out
- glColor3f(0.0f, 1.0f, 0.0f); // Green
- glVertex3f( 1.0f, 1.0f, -1.0f);
- glVertex3f(-1.0f, 1.0f, -1.0f);
- glVertex3f(-1.0f, 1.0f, 1.0f);
- glVertex3f( 1.0f, 1.0f, 1.0f);
- // Bottom face (y = -1.0f)
- glColor3f(1.0f, 0.5f, 0.0f); // Orange
- glVertex3f( 1.0f, -1.0f, 1.0f);
- glVertex3f(-1.0f, -1.0f, 1.0f);
- glVertex3f(-1.0f, -1.0f, -1.0f);
- glVertex3f( 1.0f, -1.0f, -1.0f);
- // Front face (z = 1.0f)
- glColor3f(1.0f, 0.0f, 0.0f); // Red
- glVertex3f( 1.0f, 1.0f, 1.0f);
- glVertex3f(-1.0f, 1.0f, 1.0f);
- glVertex3f(-1.0f, -1.0f, 1.0f);
- glVertex3f( 1.0f, -1.0f, 1.0f);
- // Back face (z = -1.0f)
- glColor3f(1.0f, 1.0f, 0.0f); // Yellow
- glVertex3f( 1.0f, -1.0f, -1.0f);
- glVertex3f(-1.0f, -1.0f, -1.0f);
- glVertex3f(-1.0f, 1.0f, -1.0f);
- glVertex3f( 1.0f, 1.0f, -1.0f);
- // Left face (x = -1.0f)
- glColor3f(0.0f, 0.0f, 1.0f); // Blue
- glVertex3f(-1.0f, 1.0f, 1.0f);
- glVertex3f(-1.0f, 1.0f, -1.0f);
- glVertex3f(-1.0f, -1.0f, -1.0f);
- glVertex3f(-1.0f, -1.0f, 1.0f);
- // Right face (x = 1.0f)
- glColor3f(1.0f, 0.0f, 1.0f); // Magenta
- glVertex3f(1.0f, 1.0f, -1.0f);
- glVertex3f(1.0f, 1.0f, 1.0f);
- glVertex3f(1.0f, -1.0f, 1.0f);
- glVertex3f(1.0f, -1.0f, -1.0f);
- glEnd();
- }
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- glOrtho(-8, 8, -8, 8,-8,8);
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- glRotated(45,0,1,0);
- glRotated(45,1,0,0);
- glRotatef(rotat,1,0,1);
- cube();
- glFlush();
- glutSwapBuffers();
- }
- void myKeyboardFunc( unsigned char key, int x, int y )
- {
- switch ( key )
- {
- case 'r':
- Txval+=0.2;
- break;
- case 'l':
- Txval-=0.2;
- break;
- case 'u':
- Tyval+=0.2;
- break;
- case 'd':
- Tyval-=0.2;
- break;
- case 's':
- flagScale=true;
- break;
- case 'a':
- flagScale=false;
- break;
- case 27: // Escape key
- exit(1);
- }
- glutPostRedisplay();
- }
- void animate()
- {
- if (flagScale == true)
- {
- rotat+=1;
- if(rotat > 360)
- rotat = 0;
- }
- glutPostRedisplay();
- }
- int main (int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowPosition(0,0);
- glutInitWindowSize(windowWidth,windowHeight);
- glutCreateWindow("Traingle-Demo");
- glShadeModel( GL_SMOOTH );
- glEnable( GL_DEPTH_TEST );
- glutDisplayFunc(display);
- glutKeyboardFunc(myKeyboardFunc);
- glutIdleFunc(animate);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement