Advertisement
Benjamin_Loison

TerraCraft cube

May 1st, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. #include <SDL.h>
  2. #include <GL/gl.h>
  3. #include <GL/glu.h>
  4. #include <cstdlib>
  5. #include <iostream>
  6. #include <string>
  7. using namespace std;
  8.  
  9. void Dessiner();
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13.     char* name = "TerraCraft";
  14.     SDL_Event event;
  15.     int const WIDTH_SCREEN = 800, HEIGHT_SCREEN = 600;
  16.     SDL_Init(SDL_INIT_VIDEO);
  17.     atexit(SDL_Quit);
  18.     SDL_Window *screen = SDL_CreateWindow(name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_OPENGL);
  19.     SDL_GLContext glcontext = SDL_GL_CreateContext(screen);
  20.  
  21.     bool continuer = true;
  22.  
  23.     while(continuer)
  24.     {
  25.             glMatrixMode( GL_PROJECTION );
  26.     glLoadIdentity();
  27.     gluPerspective(70,(double)640/480,1,1000);
  28.  
  29.     glEnable(GL_DEPTH_TEST);
  30.     Dessiner();
  31.     SDL_GL_SwapWindow(screen);
  32.         SDL_WaitEvent(&event);
  33.         switch(event.type)
  34.         {
  35.             case SDL_QUIT:
  36.                 continuer = false;
  37.         }
  38.     }
  39.  
  40.     SDL_Quit();
  41.  
  42.     return 0;
  43. }
  44.  
  45. void Dessiner()
  46. {
  47.     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  48.  
  49.     glMatrixMode( GL_MODELVIEW );
  50.     glLoadIdentity( );
  51.  
  52.     gluLookAt(3,4,2,0,0,0,0,0,1);
  53.  
  54.  
  55.     glBegin(GL_QUADS);
  56.  
  57.     glColor3ub(255,0,0); //face rouge
  58.     glVertex3d(1,1,1);
  59.     glVertex3d(1,1,-1);
  60.     glVertex3d(-1,1,-1);
  61.     glVertex3d(-1,1,1);
  62.  
  63.     glColor3ub(0,255,0); //face verte
  64.     glVertex3d(1,-1,1);
  65.     glVertex3d(1,-1,-1);
  66.     glVertex3d(1,1,-1);
  67.     glVertex3d(1,1,1);
  68.  
  69.     glColor3ub(0,0,255); //face bleue
  70.     glVertex3d(-1,-1,1);
  71.     glVertex3d(-1,-1,-1);
  72.     glVertex3d(1,-1,-1);
  73.     glVertex3d(1,-1,1);
  74.  
  75.     glColor3ub(255,255,0); //face jaune
  76.     glVertex3d(-1,1,1);
  77.     glVertex3d(-1,1,-1);
  78.     glVertex3d(-1,-1,-1);
  79.     glVertex3d(-1,-1,1);
  80.  
  81.     glColor3ub(0,255,255); //face cyan
  82.     glVertex3d(1,1,-1);
  83.     glVertex3d(1,-1,-1);
  84.     glVertex3d(-1,-1,-1);
  85.     glVertex3d(-1,1,-1);
  86.  
  87.     glColor3ub(255,0,255); //face magenta
  88.     glVertex3d(1,-1,1);
  89.     glVertex3d(1,1,1);
  90.     glVertex3d(-1,1,1);
  91.     glVertex3d(-1,-1,1);
  92.  
  93.     glEnd();
  94.  
  95.     glFlush();
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement