void DrawLines() { GetAttributeLocations(); g_CurrentProgram->SetUniform("color", g_CurrentColor); if(!g_DrawVertices->empty()) { EnableVertexAttrib(g_VertexLocation, 3, GL_FLOAT, GL_FALSE, 0, g_DrawVertices->data()); g_CurrentProgram->SetUniform("useTexture", false); } else return; if(!g_DrawColor->empty()) { EnableVertexAttrib(g_ColorLocation, 4, GL_FLOAT, GL_FALSE, 0, g_DrawColor->data()); g_CurrentProgram->SetUniform("useVertColor", true); } else g_CurrentProgram->SetUniform("useVertColor", false); g_CurrentProgram->UseProgram(); glDrawArrays(GL_LINES, 0, g_DrawVertices->size() / 3); DisableVertexAttrib(g_VertexLocation); DisableVertexAttrib(g_ColorLocation); ResetAttributeLocations(); }
void Cuboid::Draw(GLProgram& glProgram) { glProgram.SetModelViewProjection(); glProgram.UseProgram(); glBindBuffer(GL_ARRAY_BUFFER, m_vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_); static const size_t STRIDE = sizeof(TangentSpaceVertex); const int vl = glProgram.GetAttributeLocation("vertex"); const int nl = glProgram.GetAttributeLocation("normal"); const int tl = glProgram.GetAttributeLocation("texCoord"); const int tanl = glProgram.GetAttributeLocation("tangent"); const int btanl = glProgram.GetAttributeLocation("bitangent"); EnableVertexAttrib(vl, 3, GL_FLOAT, GL_FALSE, STRIDE, 0); EnableVertexAttrib(nl, 3, GL_FLOAT, GL_FALSE, STRIDE, reinterpret_cast<const GLvoid* >(offsetof(TangentSpaceVertex, nx_))); EnableVertexAttrib(tl, 2, GL_FLOAT, GL_FALSE, STRIDE, reinterpret_cast<const GLvoid* >(offsetof(TangentSpaceVertex, u_))); EnableVertexAttrib(tanl, 3, GL_FLOAT, GL_FALSE, STRIDE, reinterpret_cast<const GLvoid* >(offsetof(TangentSpaceVertex, tstx_))); EnableVertexAttrib(btanl, 3, GL_FLOAT, GL_FALSE, STRIDE, reinterpret_cast<const GLvoid* >(offsetof(TangentSpaceVertex, tsbx_))); glDrawElements(GL_TRIANGLES, NUM_INDICES, GL_UNSIGNED_INT, 0); DisableVertexAttrib(vl); DisableVertexAttrib(nl); DisableVertexAttrib(tl); DisableVertexAttrib(tanl); DisableVertexAttrib(btanl); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }
void DrawTriangles(std::vector<float>& pos, std::vector<float>& texCoords, std::vector<float>& normals) { GetAttributeLocations(); if(!texCoords.empty() && texCoords.size() / 2 == pos.size() / 3) { EnableVertexAttrib(g_TexCoordLocation, 2, GL_FLOAT, GL_FALSE, 0, texCoords.data()); g_CurrentProgram->SetUniform("useTexture", true); } else { g_CurrentProgram->SetUniform("useTexture", false); } if(!normals.empty() && normals.size() / 3 == pos.size() / 3) { EnableVertexAttrib(g_NormalLocation, 3, GL_FLOAT, GL_FALSE, 0, normals.data()); } if(!pos.empty()) { EnableVertexAttrib(g_VertexLocation, 3, GL_FLOAT, GL_FALSE, 0, pos.data()); } g_CurrentProgram->UseProgram(); glDrawArrays(GL_TRIANGLES, 0, pos.size() / 3); DisableVertexAttrib(g_VertexLocation); DisableVertexAttrib(g_NormalLocation); DisableVertexAttrib(g_TexCoordLocation); DisableVertexAttrib(g_ColorLocation); ResetAttributeLocations(); }
void ModelNode::renderGeometry() { // Enable all needed texture units for (uint32 t = 0; t < _textures.size(); t++) { TextureMan.activeTexture(t); glEnable(GL_TEXTURE_2D); TextureMan.set(_textures[t]); } // Render the node's faces const VertexDecl &vertexDecl = _vertexBuffer.getVertexDecl(); for (uint32 i = 0; i < vertexDecl.size(); i++) EnableVertexAttrib(vertexDecl[i]); glDrawElements(GL_TRIANGLES, _indexBuffer.getCount(), _indexBuffer.getType(), _indexBuffer.getData()); for (uint32 i = 0; i < vertexDecl.size(); i++) DisableVertexAttrib(vertexDecl[i]); // Disable the texture units again for (uint32 i = 0; i < _textures.size(); i++) { TextureMan.activeTexture(i); glDisable(GL_TEXTURE_2D); } }