Create the Vertex Buffer Objects used to render to box with OpenGL. We create two VBOs (one for vertices and one for indices) to render the box
| 157 | // Create the Vertex Buffer Objects used to render to box with OpenGL. |
| 158 | /// We create two VBOs (one for vertices and one for indices) to render the box |
| 159 | void Box::createVBOAndVAO() { |
| 160 | |
| 161 | // Create the VBO for the vertices data |
| 162 | mVBOVertices.create(); |
| 163 | mVBOVertices.bind(); |
| 164 | size_t sizeVertices = mVertices.size() * sizeof(openglframework::Vector3); |
| 165 | mVBOVertices.copyDataIntoVBO(sizeVertices, getVerticesPointer(), GL_STATIC_DRAW); |
| 166 | mVBOVertices.unbind(); |
| 167 | |
| 168 | // Create the VBO for the normals data |
| 169 | mVBONormals.create(); |
| 170 | mVBONormals.bind(); |
| 171 | size_t sizeNormals = mNormals.size() * sizeof(openglframework::Vector3); |
| 172 | mVBONormals.copyDataIntoVBO(sizeNormals, getNormalsPointer(), GL_STATIC_DRAW); |
| 173 | mVBONormals.unbind(); |
| 174 | |
| 175 | if (hasTexture()) { |
| 176 | // Create the VBO for the texture co data |
| 177 | mVBOTextureCoords.create(); |
| 178 | mVBOTextureCoords.bind(); |
| 179 | size_t sizeTextureCoords = mUVs.size() * sizeof(openglframework::Vector2); |
| 180 | mVBOTextureCoords.copyDataIntoVBO(sizeTextureCoords, getUVTextureCoordinatesPointer(), GL_STATIC_DRAW); |
| 181 | mVBOTextureCoords.unbind(); |
| 182 | } |
| 183 | |
| 184 | // Create the VBO for the indices data |
| 185 | mVBOIndices.create(); |
| 186 | mVBOIndices.bind(); |
| 187 | size_t sizeIndices = mIndices[0].size() * sizeof(unsigned int); |
| 188 | mVBOIndices.copyDataIntoVBO(sizeIndices, getIndicesPointer(), GL_STATIC_DRAW); |
| 189 | mVBOIndices.unbind(); |
| 190 | |
| 191 | // Create the VAO for both VBOs |
| 192 | mVAO.create(); |
| 193 | mVAO.bind(); |
| 194 | |
| 195 | // Bind the VBO of vertices |
| 196 | mVBOVertices.bind(); |
| 197 | |
| 198 | // Bind the VBO of normals |
| 199 | mVBONormals.bind(); |
| 200 | |
| 201 | if (hasTexture()) { |
| 202 | // Bind the VBO of texture coords |
| 203 | mVBOTextureCoords.bind(); |
| 204 | } |
| 205 | |
| 206 | // Bind the VBO of indices |
| 207 | mVBOIndices.bind(); |
| 208 | |
| 209 | // Unbind the VAO |
| 210 | mVAO.unbind(); |
| 211 | } |
nothing calls this directly
no test coverage detected