This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

scene2d.cpp

By: a guest on Oct 29th, 2012  |  syntax: C++  |  size: 3.14 KB  |  views: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "scene2d.h"
  2. #include "iecrenderer.h"
  3.  
  4. #include "common.h"
  5.  
  6. ITexture* g_texture;
  7. IShaderProgram* g_shader;
  8.  
  9. Scene2D::Scene2D(IECRenderer* parentRenderer) : ISceneManager(parentRenderer)
  10. {
  11.  
  12. }
  13.  
  14. void Scene2D::fillIndexBuffer(CJB_USHORT numQuads)
  15. {
  16.  
  17. }
  18.  
  19. void Scene2D::init()
  20. {
  21.         m_parentRenderer->setClearColor(0.4f, 0.6f, 0.9f, 0.0f);
  22.  
  23.         g_texture = m_parentRenderer->createTextureWithImage("textures/twitter-bird.png");
  24.  
  25.  
  26.         m_pVAO = m_parentRenderer->generateVAO();
  27.         m_parentRenderer->bindVAO(m_pVAO);
  28.  
  29.         m_verticiesVBO = m_parentRenderer->generateVBO();
  30.         m_indicesVBO = m_parentRenderer->generateVBO();
  31.  
  32.         m_numQuads = 0;
  33.         m_indices = NULL;
  34.         m_verticies = NULL;
  35.  
  36.         AddTexturedScreenQuad(0.0f,0.0f,1.0f,1.0f,g_texture);
  37. }
  38.  
  39. void Scene2D::preRender(CJB_UINT64 dt)
  40. {
  41.  
  42. }
  43.  
  44. void Scene2D::render(CJB_UINT64 dt)
  45. {
  46.         m_parentRenderer->clearBuffers(CJB_COLOR_BUFFER|CJB_DEPTH_BUFFER|CJB_STENCIL_BUFFER);
  47.  
  48.         m_parentRenderer->bindTexture(g_texture);
  49.  
  50.         m_parentRenderer->bindVAO(m_pVAO);
  51.         m_parentRenderer->bindVBO(VBO_INDICES,m_indicesVBO);
  52.  
  53.         m_parentRenderer->drawElements(DRAW_MODE_TRIANGLES,m_numQuads*2,ET_USHORT,(void*)0);
  54.  
  55.         m_parentRenderer->unbindVAO();
  56. }
  57.  
  58. void Scene2D::postRender(CJB_UINT64 dt)
  59. {
  60.  
  61. }
  62.  
  63. void Scene2D::AddTexturedScreenQuad(float x, float y, float w, float h, ITexture* texture)
  64. {
  65.         ++m_numQuads;
  66.  
  67.         m_indices = new CJB_USHORT[6];
  68.         m_verticies = new s_texturedScreenQuadVertex[4];
  69.  
  70.         //Test values
  71.  
  72.         m_indices[0] = 0;
  73.         m_indices[1] = 1;
  74.         m_indices[2] = 2;
  75.         m_indices[3] = 3;
  76.         m_indices[4] = 2;
  77.         m_indices[5] = 1;
  78.  
  79.         m_verticies[0].x = -1.0f; m_verticies[1].y = 1.0f; m_verticies[1].z = 0.0f;
  80.         m_verticies[0].u = 0.0f; m_verticies[1].v = 0.0f;
  81.  
  82.         m_verticies[1].x = -1.0f; m_verticies[0].y = -1.0f; m_verticies[0].z = 0.0f;
  83.         m_verticies[1].u = 0.0f; m_verticies[0].v = 1.0f;
  84.  
  85.         m_verticies[2].x = 1.0f; m_verticies[3].y = -1.0f; m_verticies[3].z = 0.0f;
  86.         m_verticies[2].u = 1.0f; m_verticies[3].v = 1.0f;
  87.  
  88.         m_verticies[3].x = 1.0f; m_verticies[2].y = 1.0f; m_verticies[2].z = 0.0f;
  89.         m_verticies[3].u = 1.0f; m_verticies[2].v = 0.0f;
  90.  
  91.         //<END>Test values
  92.  
  93.         m_parentRenderer->bindVAO(m_pVAO);
  94.  
  95.         m_parentRenderer->bindVBO(VBO_ARRAY,m_verticiesVBO);
  96.         m_parentRenderer->setBufferData(VBO_ARRAY,sizeof(m_verticies[0])*4,m_verticies,VBO_DYNAMIC_DRAW);
  97.  
  98.         m_parentRenderer->enableVertexAttributeArray(0);
  99.         m_parentRenderer->setVertexAttributePointer(0,3,ET_FLOAT,true,sizeof(m_verticies[0]),(void*)offsetof(s_texturedScreenQuadVertex,x));
  100.         m_parentRenderer->enableVertexAttributeArray(1);
  101.         m_parentRenderer->setVertexAttributePointer(1,2,ET_FLOAT,true,sizeof(m_verticies[0]),(void*)offsetof(s_texturedScreenQuadVertex,u));
  102.  
  103.         m_parentRenderer->bindVBO(VBO_INDICES,m_indicesVBO);
  104.         m_parentRenderer->setBufferData(VBO_INDICES,sizeof(m_indices[0])*6,m_indices,VBO_STATIC_DRAW);
  105.  
  106.         m_parentRenderer->unbindVAO();
  107.         m_parentRenderer->unbindVBO(VBO_ARRAY);
  108.         m_parentRenderer->unbindVBO(VBO_INDICES);
  109. }
  110.  
  111. void Scene2D::shutdown()
  112. {
  113.         if (m_indices != NULL)
  114.         {
  115.                 delete m_indices;
  116.                 m_indices = NULL;
  117.         }
  118.  
  119.         if (m_verticies != NULL)
  120.         {
  121.                 delete m_verticies;
  122.                 m_verticies = NULL;
  123.         }
  124.  
  125.         ISceneManager::shutdown();
  126. }
clone this paste RAW Paste Data