diff --git a/src/shaders/basicShader.frag b/src/shaders/basicShader.frag index 108bdb0..7b19083 100644 --- a/src/shaders/basicShader.frag +++ b/src/shaders/basicShader.frag @@ -4,6 +4,7 @@ uniform bool isSky; uniform bool isPhong; uniform sampler2D tex; uniform float skyMult; +uniform bool drawTextures; in vec3 fNormal; in vec3 fPosition; @@ -15,7 +16,12 @@ out vec4 fColor; void main() { - vec4 texColor = texture(tex, texCoords); + vec4 texColor; + if(drawTextures) { + texColor = texture(tex, texCoords); + } else { + texColor = ifColor; + } if(isSky) { fColor = skyMult * normalize(texColor*texColor*texColor*2/1.41)*2; } else if(isPhong) { diff --git a/src/viewer/simpleViewer.cpp b/src/viewer/simpleViewer.cpp index b8168b5..64a70c0 100644 --- a/src/viewer/simpleViewer.cpp +++ b/src/viewer/simpleViewer.cpp @@ -57,6 +57,8 @@ namespace QVector3D sun = QVector3D(0,-1,0); QMatrix4x4 sunRotate; + + SceneGroup* selection; } class SkyboxCamera : public qglviewer::Camera @@ -114,6 +116,7 @@ void Viewer::drawSkybox() m_program->setUniformValue(m_skyMultLoc, colorMult); m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); m_program->setUniformValue(m_isSkyLoc, true); + m_program->setUniformValue(m_drawTextLoc, true); int faces = floor(numVerticesCube/6); for(int i = 0; i < faces; i++){ // 6 vertexes par face @@ -150,6 +153,16 @@ void Viewer::draw() modelViewMatrix.rotate(30,0,1,0); + + glBindVertexArray(m_VAOs[VAO_Sphere]); + m_program->setUniformValue(m_isSkyLoc, false); + m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); + m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix()); + m_program->setUniformValue(m_colorLocation, QColor(255, 255, 255, 255)); + m_program->setUniformValue(m_drawTextLoc, false); + + glDrawElements(GL_TRIANGLES, numTriSphere * 3, GL_UNSIGNED_INT, 0); + m_program->setUniformValue(m_projMatrixLocation, projectionMatrix); m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); @@ -242,12 +255,29 @@ void Viewer::init() Shape* cube = new Cube(); cube->setColor(*activeColor); + Shape* s1 = new Sphere(); + Shape* s2 = new Sphere(); + Shape* s3 = new Sphere(); + + s1->transform.rotate(360 * 1/3,0,1,0); + s1->transform.translate(1.5,0,0); + s2->transform.rotate(360 * 2/3,0,1,0); + s2->transform.translate(1.5,0,0); + s3->transform.rotate(360 * 3/3,0,1,0); + s3->transform.translate(1.5,0,0); + // uncomment this and the quaternion transformation in draw() // to see the cube rotate. This is how we can easily make the sun. // cube->transform.translate(3, 0, 0); + selection = new SceneGroup(); + selection->addChild(s1);; + selection->addChild(s2);; + selection->addChild(s3); + SceneGroup *c = new SceneGroup(); c->addChild(cube); + //c->addChild(selection); root.addChild(c); } } @@ -310,7 +340,12 @@ void Viewer::initShaders() if ((m_skyMultLoc = m_program->uniformLocation("skyMult")) < 0) qDebug() << "Unable to find m_shader location for" << "skyMult"; + if ((m_drawTextLoc = m_program->uniformLocation("drawTextures")) < 0) + qDebug() << "Unable to find m_shader location for" << "drawTextures"; + + m_program->setUniformValue(m_isPhongLoc, true); + m_program->setUniformValue(m_drawTextLoc, true); /* * Adding Texture Shader */ @@ -584,16 +619,17 @@ void Viewer::initGeometries() void Viewer::visit(Cube &s) { + return; QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform); int faces = floor(numVerticesCube/6); for(int i = 0; i < faces; i++){ // 6 vertexes par face glBindVertexArray(m_VAOs[VAO_Cube]); m_program->setUniformValue(m_isSkyLoc, false); - m_program->setUniformValue(m_isPhongLoc, true); m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix()); m_program->setUniformValue(m_colorLocation, s.getColor()); + m_program->setUniformValue(m_drawTextLoc, true); glDrawArrays(GL_TRIANGLES, i*6, 6); } @@ -602,14 +638,15 @@ void Viewer::visit(Cube &s) void Viewer::visit(Sphere &s) { + // std::cout << "Sphere found"; QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform); glBindVertexArray(m_VAOs[VAO_Sphere]); m_program->setUniformValue(m_isSkyLoc, false); - m_program->setUniformValue(m_isPhongLoc, true); m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix()); - m_program->setUniformValue(m_colorLocation, s.getColor()); + m_program->setUniformValue(m_colorLocation, QColor(255, 255, 255, 255)); + m_program->setUniformValue(m_drawTextLoc, false); glDrawElements(GL_TRIANGLES, numTriSphere * 3, GL_UNSIGNED_INT, 0); } diff --git a/src/viewer/simpleViewer.h b/src/viewer/simpleViewer.h index 9d9c058..46f5152 100644 --- a/src/viewer/simpleViewer.h +++ b/src/viewer/simpleViewer.h @@ -99,6 +99,7 @@ private: int m_isSkyLoc; int m_lDirLoc; int m_skyMultLoc; + int m_drawTextLoc; float angle_mult;