mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 03:21:19 +00:00
Skybox, but only without scale
This commit is contained in:
parent
b1a838d170
commit
36208f6f26
@ -1,10 +1,11 @@
|
|||||||
#version 400 core
|
#version 400 core
|
||||||
in vec3 texCoords;
|
in vec2 texCoords;
|
||||||
out vec4 fColor;
|
out vec4 fColor;
|
||||||
|
|
||||||
uniform sampler2D skybox;
|
uniform sampler2D skybox;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
fColor = texture(skybox, texCoords.xy);
|
//fColor = texture(skybox, texCoords);
|
||||||
|
fColor = vec4(1.0, 0, 1.0, 1.0);// * texture(skybox, texCoords);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
#version 400 core
|
#version 400 core
|
||||||
layout (location = 0) in vec3 position;
|
|
||||||
|
|
||||||
uniform mat4 mvMatrix;
|
uniform mat4 mvMatrix;
|
||||||
uniform mat4 projMatrix;
|
uniform mat4 projMatrix;
|
||||||
out vec3 texCoords;
|
out vec2 texCoords;
|
||||||
in vec4 vPosition;
|
in vec4 vPosition;
|
||||||
|
in vec2 vUv;
|
||||||
|
|
||||||
void
|
void
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
gl_Position = projMatrix * mvMatrix * vPosition;
|
gl_Position = projMatrix * mvMatrix * vPosition;
|
||||||
texCoords = position;
|
texCoords = vUv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
#version 400 core
|
#version 400 core
|
||||||
in vec3 texCoords;
|
in vec2 texCoords;
|
||||||
out vec4 fColor;
|
out vec4 fColor;
|
||||||
|
|
||||||
uniform sampler2D skybox;
|
uniform sampler2D skybox;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
fColor = texture(skybox, texCoords.xy);
|
//fColor = texture(skybox, texCoords);
|
||||||
|
fColor = vec4(1.0, 0, 1.0, 1.0);// * texture(skybox, texCoords);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
#version 400 core
|
#version 400 core
|
||||||
layout (location = 0) in vec3 position;
|
|
||||||
|
|
||||||
uniform mat4 mvMatrix;
|
uniform mat4 mvMatrix;
|
||||||
uniform mat4 projMatrix;
|
uniform mat4 projMatrix;
|
||||||
out vec3 texCoords;
|
out vec2 texCoords;
|
||||||
in vec4 vPosition;
|
in vec4 vPosition;
|
||||||
|
in vec2 vUv;
|
||||||
|
|
||||||
void
|
void
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
gl_Position = projMatrix * mvMatrix * vPosition;
|
gl_Position = projMatrix * mvMatrix * vPosition;
|
||||||
texCoords = position;
|
texCoords = vUv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,6 +45,11 @@ namespace
|
|||||||
const double frame_limit = 5;
|
const double frame_limit = 5;
|
||||||
const double inc_mult = 5;
|
const double inc_mult = 5;
|
||||||
const double inc_offset = 1.05;
|
const double inc_offset = 1.05;
|
||||||
|
|
||||||
|
enum Buffer_IDs { ArrayBuffer, NumBuffers };
|
||||||
|
int vUVLocation;
|
||||||
|
|
||||||
|
GLuint Buffers[NumBuffers];
|
||||||
}
|
}
|
||||||
|
|
||||||
Viewer::Viewer()
|
Viewer::Viewer()
|
||||||
@ -88,7 +93,7 @@ void Viewer::drawSkybox()
|
|||||||
|
|
||||||
// Increase size of skybox
|
// Increase size of skybox
|
||||||
|
|
||||||
//modelViewMatrix.scale(3);
|
modelViewMatrix.scale(300);
|
||||||
|
|
||||||
skyboxRenderShaderProgram->setUniformValue(s_projMatrixLocation, projectionMatrix);
|
skyboxRenderShaderProgram->setUniformValue(s_projMatrixLocation, projectionMatrix);
|
||||||
skyboxRenderShaderProgram->setUniformValue(s_mvMatrixLocation, modelViewMatrix);
|
skyboxRenderShaderProgram->setUniformValue(s_mvMatrixLocation, modelViewMatrix);
|
||||||
@ -286,15 +291,15 @@ void Viewer::initShaders()
|
|||||||
// if ((s_texCoordsLocation = m_program->attributeLocation("texCoords")) < 0)
|
// if ((s_texCoordsLocation = m_program->attributeLocation("texCoords")) < 0)
|
||||||
// qDebug() << "Unable to find shader location for " << "vPosition";
|
// 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";
|
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";
|
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";
|
qDebug() << "Unable to find shader location for " << "mvMatrix";
|
||||||
|
|
||||||
s_texture = new QOpenGLTexture(QImage("src/data/skybox.jpg").mirrored());
|
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);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
glEnable( GL_BLEND );
|
glEnable( GL_BLEND );
|
||||||
glEnable( GL_CULL_FACE );
|
//glEnable( GL_CULL_FACE );
|
||||||
glFrontFace( GL_CCW );
|
glFrontFace( GL_CCW );
|
||||||
glCullFace( GL_BACK );
|
//glCullFace( GL_BACK );
|
||||||
glClearColor(0.0,0.0,0.0,0.0);
|
glClearColor(0.0,0.0,0.0,0.0);
|
||||||
|
|
||||||
// Create our VertexArrays Objects and VertexBuffer Objects
|
// 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 }
|
{ 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]);
|
GLfloat uvs[numVerticesCube][2] = {
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(verticesCube), verticesCube, GL_STATIC_DRAW);
|
{ 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));
|
glVertexAttribPointer(m_vPositionLocation, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
|
||||||
glEnableVertexAttribArray(m_vPositionLocation);
|
glEnableVertexAttribArray(m_vPositionLocation);
|
||||||
|
|||||||
@ -90,6 +90,7 @@ private:
|
|||||||
int s_colorLocation;
|
int s_colorLocation;
|
||||||
int s_projMatrixLocation;
|
int s_projMatrixLocation;
|
||||||
int s_skyboxCubemapLocation;
|
int s_skyboxCubemapLocation;
|
||||||
|
int s_vUv;
|
||||||
|
|
||||||
QOpenGLTexture *s_texture;
|
QOpenGLTexture *s_texture;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user