From 1dcec5bd3b2d39bd09090872f0ed889e15b6618b Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 18 Mar 2009 23:13:34 +0000 Subject: [PATCH] Small fixes and some comments. --- examples/OpenGL/OpenGLSupport.cpp | 34 +++++++++++-------- .../OpenGLVertexBufferObjectSupport.cpp | 21 ++++++++---- .../OpenGL/OpenGLVertexBufferObjectSupport.h | 2 +- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/examples/OpenGL/OpenGLSupport.cpp b/examples/OpenGL/OpenGLSupport.cpp index 8801ae93..2c3595dd 100644 --- a/examples/OpenGL/OpenGLSupport.cpp +++ b/examples/OpenGL/OpenGLSupport.cpp @@ -9,30 +9,34 @@ OpenGLColour convertMaterialIDToColour(PolyVox::uint8 materialID) switch(materialID) { case 1: - colour.red = 1.0; - colour.green = 0.0; - colour.blue = 0.0; + colour.red = 1.0f; + colour.green = 0.0f; + colour.blue = 0.0f; break; case 2: - colour.red = 0.0; - colour.green = 1.0; - colour.blue = 0.0; + colour.red = 0.0f; + colour.green = 1.0f; + colour.blue = 0.0f; break; case 3: - colour.red = 0.0; - colour.green = 0.0; - colour.blue = 1.0; + colour.red = 0.0f; + colour.green = 0.0f; + colour.blue = 1.0f; break; case 4: - colour.red = 1.0; - colour.green = 1.0; - colour.blue = 0.0; + colour.red = 1.0f; + colour.green = 1.0f; + colour.blue = 0.0f; break; case 5: - colour.red = 1.0; - colour.green = 0.0; - colour.blue = 1.0; + colour.red = 1.0f; + colour.green = 0.0f; + colour.blue = 1.0f; break; + default: + colour.red = 1.0f; + colour.green = 1.0f; + colour.blue = 1.0f; } return colour; diff --git a/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp b/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp index 4a76c295..62695430 100644 --- a/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp +++ b/examples/OpenGL/OpenGLVertexBufferObjectSupport.cpp @@ -6,20 +6,27 @@ using namespace PolyVox; using namespace std; -OpenGLSurfacePatch BuildOpenGLSurfacePatch(IndexedSurfacePatch& isp) +OpenGLSurfacePatch BuildOpenGLSurfacePatch(const IndexedSurfacePatch& isp) { + //Represents our filled in OpenGL vertex and index buffer objects. OpenGLSurfacePatch result; + //Convienient access to the vertices and indices const vector& vecVertices = isp.getVertices(); const vector& vecIndices = isp.getIndices(); - glGenBuffers(1, &result.indexBuffer); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, result.indexBuffer); - int s = vecIndices.size() * sizeof(GLint); - if(s != 0) + //If we have any indices... + if(!vecIndices.empty()) { - GLvoid* blah = (GLvoid*)(&(vecIndices[0])); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, s, blah, GL_STATIC_DRAW); + //Create an OpenGL index buffer + glGenBuffers(1, &result.indexBuffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, result.indexBuffer); + + //Get a pointer to the first index + GLvoid* pIndices = (GLvoid*)(&(vecIndices[0])); + + //Fill the OpenGL index buffer with our data. + glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32), pIndices, GL_STATIC_DRAW); } result.noOfIndices = vecIndices.size(); diff --git a/examples/OpenGL/OpenGLVertexBufferObjectSupport.h b/examples/OpenGL/OpenGLVertexBufferObjectSupport.h index 8a46523a..1c380a84 100644 --- a/examples/OpenGL/OpenGLVertexBufferObjectSupport.h +++ b/examples/OpenGL/OpenGLVertexBufferObjectSupport.h @@ -12,7 +12,7 @@ struct OpenGLSurfacePatch GLuint vertexBuffer; }; -OpenGLSurfacePatch BuildOpenGLSurfacePatch(PolyVox::IndexedSurfacePatch& isp); +OpenGLSurfacePatch BuildOpenGLSurfacePatch(const PolyVox::IndexedSurfacePatch& isp); void renderRegionVertexBufferObject(const OpenGLSurfacePatch& openGLSurfacePatch); #endif //__OpenGLExample_OpenGLVertexBufferObjectSupport_H__