Advertisement
marwanpro

skybox

Nov 28th, 2017
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. void Viewer::filler_skybox(Mesh& m, float startX, float startY)
  2. {
  3.     const float sizeX = 1 / 4.0;
  4.     const float sizeY = 1 / 3.0;
  5.    
  6.     m.normal(0, 0, 1);
  7.  
  8.     m.texcoord(startX, startY);
  9.     m.vertex(-1, -1, 0);
  10.  
  11.     m.texcoord(startX + sizeX, startY);
  12.     m.vertex(1, -1, 0);
  13.  
  14.     m.texcoord(startX, startY + sizeY);
  15.     m.vertex(-1, 1, 0);
  16.  
  17.     m.texcoord(startX + sizeX, startY + sizeY);
  18.     m.vertex(1, 1, 0);
  19. }
  20.  
  21. void Viewer::init_skybox()
  22. {
  23.     for (int i = 0; i < 6; i++)
  24.     {
  25.         m_skybox[i] = Mesh(GL_TRIANGLE_STRIP);
  26.         m_skybox[i].color(Color(1, 1, 1));
  27.     }
  28.  
  29.     m_skybox_texture = read_texture(0, "data/cubemap/skybox.png");
  30.  
  31.    
  32.     filler_skybox(m_skybox[0], 0, 1/3.0); // Gauche
  33.     filler_skybox(m_skybox[1], 1/4.0, 0); // Bas
  34.     filler_skybox(m_skybox[2], 1 / 2.0, 1 / 3.0); // Droite
  35.     filler_skybox(m_skybox[3], 1 / 4.0, 2 / 3.0); // Haut
  36.     filler_skybox(m_skybox[4], 1 / 4.0, 1 / 3.0); // Avant
  37.     filler_skybox(m_skybox[5], 3 / 4.0, 1 / 3.0); // Arrière
  38. }
  39.  
  40. void Viewer::render_skybox()
  41. {
  42.    
  43.     gl.lighting(true);
  44.     gl.texture(m_skybox_texture);
  45.     gl.model(Translation(0, 5, -10)*Scale(10, 10, 1));
  46.     gl.draw(m_skybox[4]); // Avant
  47.    
  48.     gl.texture(m_skybox_texture);
  49.     gl.model(Translation(10, 5, 0)*RotationY(270)*Scale(10, 10, 1));
  50.     gl.draw(m_skybox[2]); // Droite
  51.    
  52.     gl.texture(m_skybox_texture);
  53.     gl.model(Translation(-10, 5, 0)*RotationY(90)*Scale(10, 10, 1));
  54.     gl.draw(m_skybox[0]); // Gauche
  55.  
  56.     gl.texture(m_skybox_texture);
  57.     gl.model(Translation(0, -5, 0)*RotationX(270)*Scale(10, 10, 1));
  58.     gl.draw(m_skybox[1]); // Bas
  59.  
  60.     gl.lighting(false);
  61.     gl.texture(m_skybox_texture);
  62.     gl.model(Translation(0, 5, 10)*RotationY(180)*Scale(10, 10, 1));
  63.     gl.draw(m_skybox[5]); // Arriere
  64.  
  65.     gl.texture(m_skybox_texture);
  66.     gl.model(Translation(0, 15, 0)*RotationX(90)*Scale(10, 10, 1));
  67.     gl.draw(m_skybox[3]); // Haut
  68.  
  69. }
  70. /*
  71. Dans le render: render_skybox();
  72. Dans le header:
  73.     void filler_skybox(Mesh &m, float startX, float startY);
  74.     void init_skybox();
  75.     void render_skybox();
  76.     Mesh m_skybox[6];
  77.     GLuint m_skybox_texture;
  78.  
  79.  
  80. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement