diff --git a/src/shaders/skyboxShader.frag b/src/shaders/skyboxShader.frag index ad7760d..f1b865c 100644 --- a/src/shaders/skyboxShader.frag +++ b/src/shaders/skyboxShader.frag @@ -1,10 +1,11 @@ #version 400 core -in vec3 texCoords; +in vec2 texCoords; out vec4 fColor; uniform sampler2D skybox; void main() { - fColor = texture(skybox, texCoords.xy); + //fColor = texture(skybox, texCoords); + fColor = vec4(1.0, 0, 1.0, 1.0);// * texture(skybox, texCoords); } diff --git a/src/shaders/skyboxShader.vert b/src/shaders/skyboxShader.vert index 50e7021..2c2603a 100644 --- a/src/shaders/skyboxShader.vert +++ b/src/shaders/skyboxShader.vert @@ -1,15 +1,15 @@ #version 400 core -layout (location = 0) in vec3 position; uniform mat4 mvMatrix; uniform mat4 projMatrix; -out vec3 texCoords; +out vec2 texCoords; in vec4 vPosition; +in vec2 vUv; void main() { gl_Position = projMatrix * mvMatrix * vPosition; - texCoords = position; + texCoords = vUv; } diff --git a/src/shaders/skyboxshader.frag b/src/shaders/skyboxshader.frag index ad7760d..f1b865c 100644 --- a/src/shaders/skyboxshader.frag +++ b/src/shaders/skyboxshader.frag @@ -1,10 +1,11 @@ #version 400 core -in vec3 texCoords; +in vec2 texCoords; out vec4 fColor; uniform sampler2D skybox; void main() { - fColor = texture(skybox, texCoords.xy); + //fColor = texture(skybox, texCoords); + fColor = vec4(1.0, 0, 1.0, 1.0);// * texture(skybox, texCoords); } diff --git a/src/shaders/skyboxshader.vert b/src/shaders/skyboxshader.vert index 50e7021..2c2603a 100644 --- a/src/shaders/skyboxshader.vert +++ b/src/shaders/skyboxshader.vert @@ -1,15 +1,15 @@ #version 400 core -layout (location = 0) in vec3 position; uniform mat4 mvMatrix; uniform mat4 projMatrix; -out vec3 texCoords; +out vec2 texCoords; in vec4 vPosition; +in vec2 vUv; void main() { gl_Position = projMatrix * mvMatrix * vPosition; - texCoords = position; + texCoords = vUv; } diff --git a/src/viewer/simpleViewer.cpp b/src/viewer/simpleViewer.cpp index 92c41c5..56de167 100644 --- a/src/viewer/simpleViewer.cpp +++ b/src/viewer/simpleViewer.cpp @@ -45,6 +45,11 @@ namespace const double frame_limit = 5; const double inc_mult = 5; const double inc_offset = 1.05; + + enum Buffer_IDs { ArrayBuffer, NumBuffers }; + int vUVLocation; + + GLuint Buffers[NumBuffers]; } Viewer::Viewer() @@ -88,7 +93,7 @@ void Viewer::drawSkybox() // Increase size of skybox - //modelViewMatrix.scale(3); + modelViewMatrix.scale(300); skyboxRenderShaderProgram->setUniformValue(s_projMatrixLocation, projectionMatrix); skyboxRenderShaderProgram->setUniformValue(s_mvMatrixLocation, modelViewMatrix); @@ -286,15 +291,15 @@ void Viewer::initShaders() // if ((s_texCoordsLocation = m_program->attributeLocation("texCoords")) < 0) // qDebug() << "Unable to find shader location for " << "vPosition"; - if ((s_vPositionLocation = m_program->attributeLocation("vPosition")) < 0) + if ((s_vPositionLocation = skyboxRenderShaderProgram->attributeLocation("vPosition")) < 0) qDebug() << "Unable to find shader location for " << "vPosition"; - if ((s_projMatrixLocation = m_program->uniformLocation("projMatrix")) < 0) + if ((s_projMatrixLocation = skyboxRenderShaderProgram->uniformLocation("projMatrix")) < 0) qDebug() << "Unable to find shader location for " << "projMatrix"; - if ((s_mvMatrixLocation = m_program->uniformLocation("mvMatrix")) < 0) + if ((s_mvMatrixLocation = skyboxRenderShaderProgram->uniformLocation("mvMatrix")) < 0) qDebug() << "Unable to find shader location for " << "mvMatrix"; s_texture = new QOpenGLTexture(QImage("src/data/skybox.jpg").mirrored()); @@ -307,9 +312,9 @@ void Viewer::initGeometries() { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable( GL_BLEND ); - glEnable( GL_CULL_FACE ); + //glEnable( GL_CULL_FACE ); glFrontFace( GL_CCW ); - glCullFace( GL_BACK ); + //glCullFace( GL_BACK ); glClearColor(0.0,0.0,0.0,0.0); // Create our VertexArrays Objects and VertexBuffer Objects @@ -339,9 +344,41 @@ void Viewer::initGeometries() { 0.5, -0.5, -0.5 }, { -0.5, -0.5, 0.5 }, { -0.5, -0.5, -0.5 } }; - glBindVertexArray(m_VAOs[VAO_Cube]); - glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[VBO_Cube]); - glBufferData(GL_ARRAY_BUFFER, sizeof(verticesCube), verticesCube, GL_STATIC_DRAW); + + GLfloat uvs[numVerticesCube][2] = { + { 0, 0 }, { 1, 0 }, { 0, 1 }, + { 1, 1 }, { 0, 0 }, { 1, 0 }, + + { 0, 0 }, { 1, 0 }, { 0, 1 }, + { 1, 1 }, { 0, 0 }, { 1, 0 }, + + { 0, 0 }, { 1, 0 }, { 0, 1 }, + { 1, 1 }, { 0, 0 }, { 1, 0 }, + + { 0, 0 }, { 1, 0 }, { 0, 1 }, + { 1, 1 }, { 0, 0 }, { 1, 0 }, + + { 0, 0 }, { 1, 0 }, { 0, 1 }, + { 1, 1 }, { 0, 0 }, { 1, 0 }, + + { 0, 0 }, { 1, 0 }, { 0, 1 }, + { 1, 1 }, { 0, 0 }, { 1, 0 }, + }; + + + glBindVertexArray(m_VAOs[VAO_Cube]); + glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[VBO_Cube]); + glGenBuffers(NumBuffers, Buffers); + glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]); + glBufferData(GL_ARRAY_BUFFER, sizeof(verticesCube) + sizeof(uvs)/* + sizeof(normals)*/, + NULL, GL_STATIC_DRAW); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(verticesCube), verticesCube); + glBufferSubData(GL_ARRAY_BUFFER, sizeof(verticesCube), sizeof(uvs), uvs); + //glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices)+sizeof(uvs), sizeof(normals), normals); + +// glBindVertexArray(m_VAOs[VAO_Cube]); +// glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[VBO_Cube]); +// glBufferData(GL_ARRAY_BUFFER, sizeof(verticesCube), verticesCube, GL_STATIC_DRAW); glVertexAttribPointer(m_vPositionLocation, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0)); glEnableVertexAttribArray(m_vPositionLocation); diff --git a/src/viewer/simpleViewer.h b/src/viewer/simpleViewer.h index a1c95dd..734c0ae 100644 --- a/src/viewer/simpleViewer.h +++ b/src/viewer/simpleViewer.h @@ -90,6 +90,7 @@ private: int s_colorLocation; int s_projMatrixLocation; int s_skyboxCubemapLocation; + int s_vUv; QOpenGLTexture *s_texture;