mirror of
https://github.com/ConjureETS/LOG750-LAB2.git
synced 2026-03-24 11:31:20 +00:00
Beginnings of skybox
This commit is contained in:
parent
c5fbaac3fd
commit
99d5fb4e24
@ -52,7 +52,10 @@ HEADERS += QGLViewer/camera.h \
|
|||||||
src/glnodes/scenegroup.h
|
src/glnodes/scenegroup.h
|
||||||
|
|
||||||
DISTFILES += src/shaders/basicShader.vert \
|
DISTFILES += src/shaders/basicShader.vert \
|
||||||
src/shaders/basicShader.frag
|
src/shaders/basicShader.frag \
|
||||||
|
src/shaders/skyboxshader.frag \
|
||||||
|
src/shaders/skyboxshader.vert \
|
||||||
|
src/data/skybox.jpg
|
||||||
|
|
||||||
FORMS += QGLViewer/ImageInterface.ui mainwindow.ui
|
FORMS += QGLViewer/ImageInterface.ui mainwindow.ui
|
||||||
|
|
||||||
|
|||||||
BIN
src/data/skybox.jpg
Normal file
BIN
src/data/skybox.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 352 KiB |
10
src/shaders/skyboxshader.frag
Normal file
10
src/shaders/skyboxshader.frag
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#version 400 core
|
||||||
|
in vec2 texCoords;
|
||||||
|
out vec4 fColor;
|
||||||
|
|
||||||
|
uniform sampler2D skybox;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
fColor = textureCube(skybox, texCoords);
|
||||||
|
}
|
||||||
15
src/shaders/skyboxshader.vert
Normal file
15
src/shaders/skyboxshader.vert
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#version 400 core
|
||||||
|
layout (location = 0) in vec3 position;
|
||||||
|
|
||||||
|
uniform mat4 mvMatrix;
|
||||||
|
uniform mat4 projMatrix;
|
||||||
|
out vec3 texCoords;
|
||||||
|
in vec4 vPosition;
|
||||||
|
|
||||||
|
void
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
gl_Position = projMatrix * mvMatrix * vPosition;
|
||||||
|
texCoords = position;
|
||||||
|
}
|
||||||
|
|
||||||
@ -74,8 +74,38 @@ void Viewer::cleanup()
|
|||||||
doneCurrent();
|
doneCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Viewer::drawSkybox()
|
||||||
|
{
|
||||||
|
// Use the Skybox Shaders
|
||||||
|
skyboxRenderShaderProgram->bind();
|
||||||
|
s_texture->bind();
|
||||||
|
|
||||||
|
// Get projection and camera transformations
|
||||||
|
QMatrix4x4 projectionMatrix;
|
||||||
|
QMatrix4x4 modelViewMatrix;
|
||||||
|
camera()->getProjectionMatrix(projectionMatrix);
|
||||||
|
camera()->getModelViewMatrix(modelViewMatrix);
|
||||||
|
|
||||||
|
// Increase size of skybox
|
||||||
|
|
||||||
|
modelViewMatrix.scale(100);
|
||||||
|
|
||||||
|
skyboxRenderShaderProgram->setUniformValue(s_projMatrixLocation, projectionMatrix);
|
||||||
|
skyboxRenderShaderProgram->setUniformValue(s_mvMatrixLocation, modelViewMatrix);
|
||||||
|
// skyboxRenderShaderProgram->setAttributeValue(s_colorLocation, );
|
||||||
|
|
||||||
|
|
||||||
|
int faces = floor(numVerticesCube/6);
|
||||||
|
for(int i = 0; i < faces; i++){ // 6 vertexes par face
|
||||||
|
glBindVertexArray(m_VAOs[VAO_Cube]);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLES, i*6, 6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Viewer::draw()
|
void Viewer::draw()
|
||||||
{
|
{
|
||||||
|
drawSkybox();
|
||||||
// Bind our vertex/fragment shaders
|
// Bind our vertex/fragment shaders
|
||||||
m_program->bind();
|
m_program->bind();
|
||||||
|
|
||||||
@ -217,32 +247,60 @@ void Viewer::initShaders()
|
|||||||
qDebug() << "Unable to find shader location for " << "projMatrix";
|
qDebug() << "Unable to find shader location for " << "projMatrix";
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adding Texture Shader
|
* Adding Texture Shader
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
textureRenderShaderprogram = new QOpenGLShaderProgram;
|
textureRenderShaderprogram = new QOpenGLShaderProgram;
|
||||||
if (!textureRenderShaderprogram->addShaderFromSourceFile(QOpenGLShader::Vertex, "src/shaders/textureShader.vert")) {
|
if (!textureRenderShaderprogram->addShaderFromSourceFile(QOpenGLShader::Vertex, "src/shaders/textureShader.vert")) {
|
||||||
cerr << "Unable to load Shader" << endl
|
cerr << "Unable to load Shader" << endl
|
||||||
<< "Log file:" << endl;
|
<< "Log file:" << endl;
|
||||||
qDebug() << textureRenderShaderprogram->log();
|
qDebug() << textureRenderShaderprogram->log();
|
||||||
}
|
}
|
||||||
if (!textureRenderShaderprogram->addShaderFromSourceFile(QOpenGLShader::Fragment, "src/shaders/textureShader.frag")) {
|
if (!textureRenderShaderprogram->addShaderFromSourceFile(QOpenGLShader::Fragment, "src/shaders/textureShader.frag")) {
|
||||||
cerr << "Unable to load Shader" << endl
|
cerr << "Unable to load Shader" << endl
|
||||||
<< "Log file:" << endl;
|
<< "Log file:" << endl;
|
||||||
qDebug() << textureRenderShaderprogram->log();
|
qDebug() << textureRenderShaderprogram->log();
|
||||||
}
|
}
|
||||||
|
|
||||||
textureRenderShaderprogram->link();
|
textureRenderShaderprogram->link();
|
||||||
|
|
||||||
if ((m_vPositionLocation = m_program->attributeLocation("vPosition")) < 0)
|
/*
|
||||||
qDebug() << "Unable to find shader location for " << "vPosition";
|
* Adding Skybox Shaders
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
skyboxRenderShaderProgram = new QOpenGLShaderProgram;
|
||||||
|
if (!skyboxRenderShaderProgram->addShaderFromSourceFile(QOpenGLShader::Vertex, "src/shaders/skyboxshader.vert")) {
|
||||||
|
cerr << "Unable to load Shader" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
|
qDebug() << skyboxRenderShaderProgram->log();
|
||||||
|
}
|
||||||
|
if (!skyboxRenderShaderProgram->addShaderFromSourceFile(QOpenGLShader::Fragment, "src/shaders/skyboxshader.frag")) {
|
||||||
|
cerr << "Unable to load Shader" << endl
|
||||||
|
<< "Log file:" << endl;
|
||||||
|
qDebug() << skyboxRenderShaderProgram->log();
|
||||||
|
}
|
||||||
|
|
||||||
if ((m_mvMatrixLocation = m_program->uniformLocation("mvMatrix")) < 0)
|
skyboxRenderShaderProgram->link();
|
||||||
qDebug() << "Unable to find shader location for " << "mvMatrix";
|
|
||||||
|
|
||||||
if ((m_projMatrixLocation = m_program->uniformLocation("projMatrix")) < 0)
|
if ((s_texCoordsLocation = m_program->attributeLocation("texCoords")) < 0)
|
||||||
qDebug() << "Unable to find shader location for " << "projMatrix";
|
qDebug() << "Unable to find shader location for " << "vPosition";
|
||||||
|
|
||||||
|
if ((s_vPositionLocation = m_program->attributeLocation("vPosition")) < 0)
|
||||||
|
qDebug() << "Unable to find shader location for " << "vPosition";
|
||||||
|
|
||||||
|
if ((s_mvMatrixLocation = m_program->uniformLocation("mvMatrix")) < 0)
|
||||||
|
qDebug() << "Unable to find shader location for " << "mvMatrix";
|
||||||
|
|
||||||
|
if ((s_projMatrixLocation = m_program->uniformLocation("projMatrix")) < 0)
|
||||||
|
qDebug() << "Unable to find shader location for " << "projMatrix";
|
||||||
|
|
||||||
|
if ((s_skyboxCubemapLocation = m_program->uniformLocation("cubemap")) < 0)
|
||||||
|
qDebug() << "Unable to find shader location for " << "projMatrix";
|
||||||
|
|
||||||
|
s_texture = new QOpenGLTexture(QImage("../data/skybox.jpg").mirrored());
|
||||||
|
s_texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
|
||||||
|
s_texture->setMagnificationFilter(QOpenGLTexture::Linear);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates the basic shapes in memory. We only have 3, so we just prep them all in advance.
|
// Creates the basic shapes in memory. We only have 3, so we just prep them all in advance.
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include <QOpenGLFunctions_4_0_Core>
|
#include <QOpenGLFunctions_4_0_Core>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
#include <QOpenGLBuffer>
|
#include <QOpenGLBuffer>
|
||||||
|
#include <QOpenGLTexture>
|
||||||
#include <QMatrix4x4>
|
#include <QMatrix4x4>
|
||||||
#include <QGLViewer/qglviewer.h>
|
#include <QGLViewer/qglviewer.h>
|
||||||
#include "../interfaces/visitor.h"
|
#include "../interfaces/visitor.h"
|
||||||
@ -56,7 +57,8 @@ signals:
|
|||||||
int shapeSelected(int);
|
int shapeSelected(int);
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
virtual void draw();
|
virtual void draw();
|
||||||
|
virtual void drawSkybox();
|
||||||
virtual void init();
|
virtual void init();
|
||||||
|
|
||||||
virtual void mouseMoveEvent(QMouseEvent* e);
|
virtual void mouseMoveEvent(QMouseEvent* e);
|
||||||
@ -73,14 +75,24 @@ private:
|
|||||||
Shape* pickGeom(int, int);
|
Shape* pickGeom(int, int);
|
||||||
|
|
||||||
// shader switching variables and constants;
|
// shader switching variables and constants;
|
||||||
QOpenGLShaderProgram *colorPickerShaderProgram;
|
QOpenGLShaderProgram *colorPickerShaderProgram;
|
||||||
QOpenGLShaderProgram *textureRenderShaderprogram;
|
QOpenGLShaderProgram *textureRenderShaderprogram;
|
||||||
|
QOpenGLShaderProgram *skyboxRenderShaderProgram;
|
||||||
QOpenGLShaderProgram *m_program;
|
QOpenGLShaderProgram *m_program;
|
||||||
int m_vPositionLocation;
|
int m_vPositionLocation;
|
||||||
int m_colorLocation;
|
int m_colorLocation;
|
||||||
int m_projMatrixLocation;
|
int m_projMatrixLocation;
|
||||||
int m_mvMatrixLocation;
|
int m_mvMatrixLocation;
|
||||||
|
|
||||||
|
int s_texCoordsLocation;
|
||||||
|
int s_vPositionLocation;
|
||||||
|
int s_mvMatrixLocation;
|
||||||
|
int s_colorLocation;
|
||||||
|
int s_projMatrixLocation;
|
||||||
|
int s_skyboxCubemapLocation;
|
||||||
|
|
||||||
|
QOpenGLTexture *s_texture;
|
||||||
|
|
||||||
SceneGroup* activeCell;
|
SceneGroup* activeCell;
|
||||||
QColor* activeColor;
|
QColor* activeColor;
|
||||||
int activeShape;
|
int activeShape;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user