Advertisement
Guest User

Untitled

a guest
Dec 31st, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. // Constructor
  2. Image2d::Image2d(...){
  3.     /* ... */
  4.     // Define texture coords
  5.     std::vector<float> vTextureCoords;
  6.     vTextureCoords.push_back(0.0f);
  7.     vTextureCoords.push_back(1.0f);
  8.  
  9.     vTextureCoords.push_back(0.0f);
  10.     vTextureCoords.push_back(0.0f);
  11.  
  12.     vTextureCoords.push_back(1.0f);
  13.     vTextureCoords.push_back(1.0f);
  14.  
  15.     vTextureCoords.push_back(1.0f);
  16.     vTextureCoords.push_back(0.0f);
  17.  
  18.     /* ... */
  19.  
  20.     glGenVertexArrays(1, &_vao);
  21.     glBindVertexArray(_vao);
  22.  
  23.     _pShaderManager->SetAttribute(A_COLOR, COLOR_WHITE);
  24.  
  25.     glGenBuffers(1, &_vboPosition);
  26.     glBindBuffer(GL_ARRAY_BUFFER, _vboPosition);
  27.     glBufferData(GL_ARRAY_BUFFER, vVertexPos.size()*sizeof(vVertexPos[0]), &vVertexPos[0], GL_STATIC_DRAW);
  28.     _pShaderManager->EnableAttribute(A_POSITION);
  29.  
  30.     glGenBuffers(1, &_vboTexture);
  31.     glBindBuffer(GL_ARRAY_BUFFER, _vboTexture);
  32.     glBufferData(GL_ARRAY_BUFFER, vTextureCoords.size()*sizeof(vTextureCoords[0]), &vTextureCoords[0], GL_STATIC_DRAW);
  33.     _pShaderManager->EnableAttribute(A_TEXTURE_COORD0);
  34.  
  35.     glGenBuffers(1, &_vboIndices);
  36.     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndices);
  37.     glBufferData(GL_ELEMENT_ARRAY_BUFFER, vIndices.size()*sizeof(vIndices[0]), &vIndices[0], GL_STATIC_DRAW);
  38.  
  39.     glBindVertexArray(0);
  40.  
  41.     _pShaderManager->DisableAttribute(A_POSITION);
  42.     _pShaderManager->DisableAttribute(A_TEXTURE_COORD0);
  43.  
  44.     // After array is unbound
  45.     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  46.     glBindBuffer(GL_ARRAY_BUFFER, 0);
  47. }
  48.  
  49. void Image2d::Render(){
  50.     if (_version == 1){
  51.         _pShaderManager->SetTexture(0, U_TEXTURE0_SAMPLER_2D, _textureInfo.uTextureId);
  52.  
  53.         glBindVertexArray(_vao);
  54.         glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, nullptr);
  55.         glBindVertexArray(0);
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement