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.
- */
- #ifdef __APPLE__
- #include <GLUT/glut.h>
- #else
- #include <GL/glut.h>
- #endif
- #include <stdlib.h>
- float counter = 0.0;
- void square(float r, float g, float b){
- glColor3f(r, g, b);
- glBegin(GL_TRIANGLE_FAN);
- glVertex3f(-0.5, -0.5, 0.5);
- glVertex3f(0.5, -0.5, 0.5);
- glVertex3f(0.5, 0.5, 0.5);
- glVertex3f(-0.5, 0.5, 0.5);
- glEnd();
- }
- void cube(float size){
- glPushMatrix();
- glScalef(size, size, size);
- square(1, 0, 0);
- glPushMatrix();
- glRotatef(90, 0, 1, 0);
- square(0, 1, 0);
- glPopMatrix();
- glPushMatrix();
- glRotatef(-90, 1, 0, 0);
- square(0, 0, 1);
- glPopMatrix();
- glPushMatrix();
- glRotatef(180, 0, 1, 0);
- square(0, 1, 1);
- glPopMatrix();
- }
- void circle(){
- }
- void display (){
- glClear(GL_COLOR_BUFFER_BIT); //restart clear color
- glLoadIdentity();
- glPushMatrix();
- glTranslatef(0.5, 0.5, 0.0);
- circle();
- glPopMatrix();
- glRotatef(counter, 1.0, 1.0, 1.0);
- counter += 0.01;
- cube(0.5);
- glutSwapBuffers(); //interchange memory buffers
- }
- void reshape(int width, int high){
- glViewport(0,0,width,high); //define where to draw the object
- }
- void initOpenGL(){
- glClearColor(1.0, 0.0, 0.0, 1.0); //background color RGB black
- }
- int main (int argc, char **argv){
- glutInit(&argc, argv);// initialize GLUT
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); //double buffer, color RGB + alpha channel, & use depth for 3D
- glutInitWindowSize(500, 500); //windows size
- glutCreateWindow("Transformations"); //windows name
- glutDisplayFunc(display);
- glutIdleFunc(display);
- glutReshapeFunc(reshape);
- initOpenGL();
- glutMainLoop();//activate infinite loop
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement