diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 03014c72..4f4d9d15 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) in vec4 position; // This will be the position of the vertex in model-space in vec4 normal; // The normal data may not have been set - in vec2 material; + in ivec2 material; uniform mat4 cameraToClipMatrix; uniform mat4 worldToCameraMatrix; @@ -103,14 +103,14 @@ int main(int argc, char *argv[]) out vec4 worldPosition; //This is being passed to the fragment shader to calculate the normals out vec4 worldNormal; - out vec2 outMaterial; + flat out ivec2 outMaterial; void main() { //material = vec2( worldPosition = modelToWorldMatrix * position; worldNormal = normal; - outMaterial = vec2(material.x, material.y); + outMaterial = ivec2(material.x, material.y); vec4 cameraPosition = worldToCameraMatrix * worldPosition; gl_Position = cameraToClipMatrix * cameraPosition; } @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) in vec4 worldPosition; //Passed in from the vertex shader in vec4 worldNormal; - in vec2 outMaterial; + flat in ivec2 outMaterial; out vec4 outputColor; @@ -135,15 +135,15 @@ int main(int argc, char *argv[]) vec3 normal = worldNormal.xyz; - if(outMaterial.x < 1.5) + if(outMaterial.x == 1) { outputColor = vec4(1.0, 0.0, 0.0, 1.0); } - else if(outMaterial.x < 2.5) + else if(outMaterial.x == 2) { outputColor = vec4(0.0, 1.0, 0.0, 1.0); } - else if(outMaterial.x < 3.5) + else if(outMaterial.x == 3) { outputColor = vec4(0.0, 0.0, 1.0, 1.0); } diff --git a/examples/common/OpenGLWidget.h b/examples/common/OpenGLWidget.h index 521f239e..a1c1c37c 100644 --- a/examples/common/OpenGLWidget.h +++ b/examples/common/OpenGLWidget.h @@ -92,7 +92,8 @@ public: glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(MeshType::VertexType), (GLvoid*)(offsetof(MeshType::VertexType, normal))); glEnableVertexAttribArray(2); //We're talking about shader attribute '2' - glVertexAttribPointer(2, 2, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(MeshType::VertexType), (GLvoid*)(offsetof(MeshType::VertexType, material))); + GLint size = (std::min)(sizeof(MeshType::VertexType::VoxelType), size_t(4)); + glVertexAttribIPointer(2, size, GL_UNSIGNED_BYTE, sizeof(MeshType::VertexType), (GLvoid*)(offsetof(MeshType::VertexType, material))); glBindVertexArray(0);