Advertisement
Thiagofsr

Untitled

May 14th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <GL/glut.h>
  4. #include <math.h>
  5.  
  6. #define PI 3.14159265359
  7.  
  8.  
  9. GLuint draw;
  10. void init3D(float r, float g, float b)
  11. {
  12.  
  13.  
  14.     glClearColor(r,g,b,1.0);
  15.     glMatrixMode (GL_PROJECTION);
  16.     glLoadIdentity();
  17.     glOrtho(-100.0,100.0,-100.0,100.0,0.1,80);
  18. }
  19.  
  20. void initList(){
  21.     draw = glGenLists(1);
  22.     glNewList(draw,GL_COMPILE);
  23.  
  24.         glColorMask(1,0,0,1);
  25.         glutSolidTeapot(50);
  26.  
  27.     //glutSolidTorus(10, 50, 50, 50);
  28.  
  29.         glTranslated(0, 0, -10);
  30. // /glTranslatef(-4.0f,0.0f,0.f);
  31.         float traslation[16] = {1,0,0,0,0,1,0,0,0,0,1,0,-40.0f,0,0,1};
  32.         float rotation [16] = {cos(90*PI/180),sin(90*PI/180),0,0,-(sin(90*PI/180)),cos(90*PI/180),0,0,0,0,1,0,0,0,0,1};
  33.     glMultMatrixf(traslation);
  34.         glMultMatrixf(rotation);
  35.  
  36.         glColorMask(0,0,1,1);
  37.         glutSolidTeapot(50);
  38.  
  39.     glEndList();
  40.  
  41. }
  42.  
  43.  
  44. void display(){
  45.  
  46.  
  47.  
  48.  
  49.  
  50.   glColorMask(1,1, 1, 1);
  51.   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  52.   ///glColor3d(1, 0,1);
  53.   glMatrixMode(GL_MODELVIEW);
  54.     glLoadIdentity();
  55.  
  56.     glPushMatrix();
  57.         glCallList(draw);
  58.     glPopMatrix();
  59.  
  60. //glutSolidTorus(10, 50, 50, 50);
  61.   glutSwapBuffers();
  62.   }
  63.  
  64. void createWindow(char *windowName)
  65. {
  66.   glutInitWindowPosition(300,100);
  67.     glutInitWindowSize(800, 800);
  68.     glutCreateWindow(windowName);
  69.     initList();
  70.     init3D(0.0,0.0,0.0);
  71.     glutDisplayFunc(display);
  72. }
  73.  
  74. void KEYBOARD(unsigned char key, int xx, int yy){
  75.     switch(key){
  76.         case 'e':
  77.             glEnable(GL_DEPTH_TEST);
  78.             break;
  79.         case 'd':
  80.             glDisable(GL_DEPTH_TEST);
  81.             break;
  82.     }
  83.     glutPostRedisplay();
  84. }
  85.  
  86. int main(int argc, char ** argv)
  87. {
  88.  
  89.   glutInit(&argc, argv);
  90.     glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
  91.     createWindow("3D Stereo");
  92.     glutKeyboardFunc(KEYBOARD);
  93.     // glutSpecialFunc(ESPECIAL);
  94.  
  95.     glutMainLoop(); //Start the main loop
  96.  
  97.     return 0;
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement