Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Constructor
- Image2d::Image2d(...){
- /* ... */
- // Define texture coords
- std::vector<float> vTextureCoords;
- vTextureCoords.push_back(0.0f);
- vTextureCoords.push_back(1.0f);
- vTextureCoords.push_back(0.0f);
- vTextureCoords.push_back(0.0f);
- vTextureCoords.push_back(1.0f);
- vTextureCoords.push_back(1.0f);
- vTextureCoords.push_back(1.0f);
- vTextureCoords.push_back(0.0f);
- /* ... */
- glGenVertexArrays(1, &_vao);
- glBindVertexArray(_vao);
- _pShaderManager->SetAttribute(A_COLOR, COLOR_WHITE);
- glGenBuffers(1, &_vboPosition);
- glBindBuffer(GL_ARRAY_BUFFER, _vboPosition);
- glBufferData(GL_ARRAY_BUFFER, vVertexPos.size()*sizeof(vVertexPos[0]), &vVertexPos[0], GL_STATIC_DRAW);
- _pShaderManager->EnableAttribute(A_POSITION);
- glGenBuffers(1, &_vboTexture);
- glBindBuffer(GL_ARRAY_BUFFER, _vboTexture);
- glBufferData(GL_ARRAY_BUFFER, vTextureCoords.size()*sizeof(vTextureCoords[0]), &vTextureCoords[0], GL_STATIC_DRAW);
- _pShaderManager->EnableAttribute(A_TEXTURE_COORD0);
- glGenBuffers(1, &_vboIndices);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _vboIndices);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, vIndices.size()*sizeof(vIndices[0]), &vIndices[0], GL_STATIC_DRAW);
- glBindVertexArray(0);
- _pShaderManager->DisableAttribute(A_POSITION);
- _pShaderManager->DisableAttribute(A_TEXTURE_COORD0);
- // After array is unbound
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- }
- void Image2d::Render(){
- if (_version == 1){
- _pShaderManager->SetTexture(0, U_TEXTURE0_SAMPLER_2D, _textureInfo.uTextureId);
- glBindVertexArray(_vao);
- glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, nullptr);
- glBindVertexArray(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement