Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.87 KB | None | 0 0
  1. /*
  2.  * GLUT Shapes Demo
  3.  *
  4.  * Written by Nigel Stewart November 2003
  5.  *
  6.  * This program is test harness for the sphere, cone
  7.  * and torus shapes in GLUT.
  8.  *
  9.  * Spinning wireframe and smooth shaded shapes are
  10.  * displayed until the ESC or q key is pressed.  The
  11.  * number of geometry stacks and slices can be adjusted
  12.  * using the + and - keys.
  13.  */
  14.  
  15. #ifdef __APPLE__
  16. #include <GLUT/glut.h>
  17. #else
  18. #include <GL/glut.h>
  19. #endif
  20.  
  21. #include <stdlib.h>
  22.  
  23. GLfloat angle = 0.0f;
  24.  
  25. void initGL()
  26. {
  27.     glClearColor(0.0f,0.0f,0.0f,1.0f);
  28. }
  29. void display()
  30. {
  31.     glClear(GL_COLOR_BUFFER_BIT);
  32.     glMatrixMode(GL_MODELVIEW);
  33.     glLoadIdentity();
  34.  
  35.     glPushMatrix();
  36.         glTranslatef(-0.0f,-0.0f, 0.0f);
  37.         glRotatef(angle,0.0f,1.0f,0.0f);
  38.         glBegin(GL_QUADS);
  39.             glColor3f(0.0f,1.0f,0.0f);
  40.             glVertex2f(-0.3f,-0.3f);
  41.             glVertex2f(0.3f,-0.3f);
  42.             glVertex2f(0.3f,0.3f);
  43.             glVertex2f(-0.3f,0.3f);
  44.         glEnd();
  45.     glPopMatrix();
  46.  
  47.    /* glPushMatrix();
  48.         glTranslatef(-0.4f,-0.3f,0.0f);
  49.         glRotatef(angle,0.0f,0.0f,1.0f);
  50.         glBegin(GL_QUADS);
  51.             glColor3f(0.0f,1.0f,0.0f);
  52.             glVertex2f(-0.3f,-0.3f);
  53.             glVertex2f(0.3f,-0.3f);
  54.             glVertex2f(0.3f,0.3f);
  55.             glVertex2f(-0.3f,0.3f);
  56.         glEnd();
  57.     glPopMatrix();
  58.  
  59.     glPushMatrix();
  60.         glTranslatef(-0.7f,-0.5f,0.0f);
  61.         glRotatef(angle,0.0f,0.0f,1.0f);
  62.         glBegin(GL_QUADS);
  63.             glColor3f(0.2f,0.2f,0.2f);
  64.             glVertex2f(-0.2f,-0.2f);
  65.             glColor3f(1.0f,1.0f,1.0f);
  66.             glVertex2f(0.2f,-0.2f);
  67.             glColor3f(0.2f,0.2f,0.2f);
  68.             glVertex2f(0.2f,0.2f);
  69.             glColor3f(1.0f,1.0f,1.0f);
  70.             glVertex2f(-0.2f,0.2f);
  71.         glEnd();
  72.     glPopMatrix();
  73.  
  74.     glPushMatrix();
  75.         glTranslatef(0.4f,-0.3f,0.0f);
  76.         glRotatef(angle,0.0f,0.0f,1.0f);
  77.         glBegin(GL_TRIANGLES);
  78.             glColor3f(0.0f,0.0f,1.0f);
  79.             glVertex2f(-0.3f, -0.2f);
  80.             glVertex2f(0.3f, -0.2f);
  81.             glVertex2f(0.0f, 0.3f);
  82.         glEnd();
  83.     glPopMatrix();
  84.  
  85.     glPushMatrix();
  86.         glTranslatef(0.6f,-0.6f,0.0f);
  87.         glRotatef(180.0f + angle,0.0f,0.0f,1.0f);
  88.         glBegin(GL_TRIANGLES);
  89.             glColor3f(1.0f,0.0f,0.0f);
  90.             glVertex2f(-0.3f, -0.2f);
  91.             glColor3f(0.0f,1.0f,0.0f);
  92.             glVertex2f(0.3f, -0.2f);
  93.             glColor3f(0.0f,0.0f,1.0f);
  94.             glVertex2f(0.0f, 0.3f);
  95.         glEnd();
  96.     glPopMatrix();
  97.  
  98.     glPushMatrix();
  99.         glTranslatef(0.5f,0.4f,0.0f);
  100.         glRotatef(angle,0.0f,0.0f,1.0f);
  101.         glBegin(GL_POLYGON);
  102.             glColor3f(1.0f,1.0f,0.0f);
  103.             glVertex2f(-0.1f, -0.2f);
  104.             glVertex2f(0.1f, -0.2f);
  105.             glVertex2f(0.2f, 0.0f);
  106.             glVertex2f(0.1f, 0.2f);
  107.             glVertex2f(-0.1f, 0.2f);
  108.             glVertex2f(-0.2f, 0.0f);
  109.         glEnd();
  110.     glPopMatrix();
  111.     */
  112.  
  113.  
  114.     glutSwapBuffers();
  115.     angle +=0.2f;
  116. }
  117.  
  118. void reshape(GLsizei width, GLsizei height)
  119. {
  120.     if(height == 0) height =1;
  121.     GLfloat aspect = (GLfloat)width/(GLfloat) height;
  122.     glViewport(0,0,width,height);
  123.     glMatrixMode(GL_PROJECTION);
  124.     glLoadIdentity();
  125.     if(width>=height)
  126.     {
  127.         gluOrtho2D(-1.0 * aspect, 1.0 * aspect, -1.0, 1.0);
  128.     }
  129.     else
  130.     {
  131.         gluOrtho2D(-1.0,1.0,-1.0/aspect,1.0/aspect);
  132.     }
  133. }
  134.  
  135.  
  136.  
  137. static void idle(void)
  138. {
  139.     glutPostRedisplay();
  140. }
  141.  
  142. /* Program entry point */
  143.  
  144. int main(int argc, char* argv[])
  145. {
  146.     glutInit(&argc, argv);
  147.     glutInitDisplayMode(GLUT_DOUBLE);
  148.     glutInitWindowSize(640,600);
  149.     glutInitWindowPosition(50,50);
  150.     glutCreateWindow("Animacja");
  151.  
  152.     glutDisplayFunc(display);
  153.     glutReshapeFunc(reshape);
  154.     glutIdleFunc(idle);
  155.     initGL();
  156.     glutMainLoop();
  157.     return 0;
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement