From 124ef6ec2e91820c29fd9c8633741cce403704fd Mon Sep 17 00:00:00 2001 From: Anselme Date: Tue, 13 Oct 2015 17:38:49 +0200 Subject: [PATCH] little fix --- phongentity.cpp | 2 +- phongmaterial.cpp | 46 +++++++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/phongentity.cpp b/phongentity.cpp index f927043..0e1820d 100644 --- a/phongentity.cpp +++ b/phongentity.cpp @@ -114,7 +114,7 @@ void PhongEntity::crappyInit() for(int i=0; iindiceGroups.size(); ++i) { PhongMaterial* mat = (PhongMaterial*)(mesh->indiceGroups[i].material); - mat->crappyBindAttributes(); + mat->bindAttributes(); glAssert(glBegin(GL_TRIANGLES)); for(int j=0; jindiceGroups[i].indices.size(); ++j) { diff --git a/phongmaterial.cpp b/phongmaterial.cpp index 3226aea..f62b728 100644 --- a/phongmaterial.cpp +++ b/phongmaterial.cpp @@ -1,6 +1,8 @@ #include "phongmaterial.h" #include "texture.h" #include "phongmodule.h" +#include "sparrowrenderer.h" +#include "glassert.h" #include #define TEX_ID 0 @@ -12,31 +14,33 @@ void PhongMaterial::updateShader() void PhongMaterial::bindAttributes() { - shader->bind(); - shader->bindVec3(shader->getLocation("materialAmbient"), emission); - shader->bindVec3(shader->getLocation("materialKd"), diffuse); - shader->bindVec3(shader->getLocation("materialKs"), specular); - shader->bindFloat(shader->getLocation("materialNs"), shininess); - if(diffuse_texture != NULL) + if(SparrowRenderer::isModernOpenGLAvailable()) { - diffuse_texture->bind(TEX_ID); - shader->bindInteger(shader->getLocation("baseTexture"), TEX_ID); + shader->bind(); + shader->bindVec3(shader->getLocation("materialAmbient"), emission); + shader->bindVec3(shader->getLocation("materialKd"), diffuse); + shader->bindVec3(shader->getLocation("materialKs"), specular); + shader->bindFloat(shader->getLocation("materialNs"), shininess); + if(diffuse_texture != NULL) + { + diffuse_texture->bind(TEX_ID); + shader->bindInteger(shader->getLocation("baseTexture"), TEX_ID); + } } -} - -void PhongMaterial::crappyBindAttributes() -{ - glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, glm::value_ptr(glm::vec4(emission, 1))); - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, glm::value_ptr(glm::vec4(diffuse, 1))); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, glm::value_ptr(glm::vec4(specular, 1))); - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess); - if(diffuse_texture != NULL) - diffuse_texture->bind(TEX_ID); else { - GLenum texSlot = GL_TEXTURE0+TEX_ID; - glActiveTexture(texSlot); - glBindTexture(GL_TEXTURE_2D, 0); + glAssert(glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, glm::value_ptr(glm::vec4(emission, 1)))); + glAssert(glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, glm::value_ptr(glm::vec4(diffuse, 1)))); + glAssert(glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, glm::value_ptr(glm::vec4(specular, 1)))); + glAssert(glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess)); + if(diffuse_texture != NULL) + diffuse_texture->bind(TEX_ID); + else + { + GLenum texSlot = GL_TEXTURE0+TEX_ID; + glAssert(glActiveTexture(texSlot)); + glAssert(glBindTexture(GL_TEXTURE_2D, 0)); + } } }