Refactor
Refactoring the render engine to feel a little better organized. One major issue remains with the model not rendering at the time. Possibly this is solved after fixing the outline render pass
This commit is contained in:
parent
4355a12b9a
commit
85263312cd
8
Makefile
8
Makefile
@ -3,10 +3,14 @@ CFLAGS = -std=c++17 -O2 -g
|
|||||||
LDFLAGS = -lglfw3 -lGL -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi -lz -lassimp
|
LDFLAGS = -lglfw3 -lGL -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi -lz -lassimp
|
||||||
OUT_NAME = LearnOpenGL
|
OUT_NAME = LearnOpenGL
|
||||||
|
|
||||||
build: src/*.cpp src/*.h
|
build: src/*.cpp src/*.h src/**/*.cpp src/**/*.h
|
||||||
mkdir -p build/
|
mkdir -p build/
|
||||||
$(CC) $(CFLAGS) -Ilib/GLAD/include -Ilib/glfw/include -o build/$(OUT_NAME) lib/GLAD/src/glad.c src/*.cpp $(LDFLAGS)
|
$(CC) $(CFLAGS) -Ilib/GLAD/include -Ilib/glfw/include -Ilib/stb -o build/$(OUT_NAME) lib/GLAD/src/glad.c lib/stb/stb_image.cpp src/**.cpp src/**/*.cpp $(LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
run: build build/$(OUT_NAME)
|
run: build build/$(OUT_NAME)
|
||||||
./build/$(OUT_NAME)
|
./build/$(OUT_NAME)
|
||||||
|
|
||||||
|
|
||||||
|
debug: build build/$(OUT_NAME)
|
||||||
|
gdb build/$(OUT_NAME)
|
@ -1,27 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <glad/glad.h>
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "stb_image.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Cubemap {
|
|
||||||
public:
|
|
||||||
|
|
||||||
unsigned int id;
|
|
||||||
|
|
||||||
Cubemap();
|
|
||||||
~Cubemap();
|
|
||||||
|
|
||||||
void Bind();
|
|
||||||
void Unbind();
|
|
||||||
|
|
||||||
void loadCubeTextures(const std::vector<std::string>& texture_faces);
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
@ -1,25 +1,53 @@
|
|||||||
#include "Cubemap.h"
|
#include "Skybox.h"
|
||||||
|
|
||||||
|
|
||||||
Cubemap::Cubemap(){
|
|
||||||
|
Skybox::Skybox()
|
||||||
|
{
|
||||||
glGenTextures(1, &id);
|
glGenTextures(1, &id);
|
||||||
|
|
||||||
|
// Create SkyboxVAO
|
||||||
|
|
||||||
|
glGenVertexArrays(1, &m_skyboxVAO);
|
||||||
|
glBindVertexArray(m_skyboxVAO);
|
||||||
|
|
||||||
|
glGenBuffers(1, &m_skyboxVBO);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, m_skyboxVBO);
|
||||||
|
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, m_skyboxVertices.size() * sizeof(float), &m_skyboxVertices[0], GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribPointer(0,3, GL_FLOAT,GL_FALSE, 3 * sizeof(float),(void*) 0);
|
||||||
|
|
||||||
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
std::cout << "Skybox Created" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Cubemap::~Cubemap(){
|
Skybox::~Skybox()
|
||||||
// glDeleteTextures(id);
|
{
|
||||||
|
glDeleteTextures(1, &id);
|
||||||
|
std::cout << "Skybox destroyed!" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cubemap::Bind(){
|
|
||||||
|
|
||||||
|
|
||||||
|
void Skybox::Bind()
|
||||||
|
{
|
||||||
|
glBindVertexArray(m_skyboxVAO);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void Cubemap::Unbind(){
|
void Skybox::Unbind()
|
||||||
|
{
|
||||||
|
glBindVertexArray(0);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cubemap::loadCubeTextures(const std::vector<std::string>& texture_faces){
|
void Skybox::loadCubeTextures(const std::vector<std::string>& texture_faces)
|
||||||
|
{
|
||||||
|
Bind();
|
||||||
int width, height, nrChannels;
|
int width, height, nrChannels;
|
||||||
unsigned char* data;
|
unsigned char* data;
|
||||||
stbi_set_flip_vertically_on_load(false);
|
stbi_set_flip_vertically_on_load(false);
|
||||||
@ -42,5 +70,6 @@ void Cubemap::loadCubeTextures(const std::vector<std::string>& texture_faces){
|
|||||||
|
|
||||||
|
|
||||||
stbi_set_flip_vertically_on_load(true);
|
stbi_set_flip_vertically_on_load(true);
|
||||||
|
Unbind();
|
||||||
|
|
||||||
}
|
}
|
70
src/Primitives/Skybox.h
Normal file
70
src/Primitives/Skybox.h
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <glad/glad.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "stb_image.h"
|
||||||
|
|
||||||
|
class Skybox {
|
||||||
|
public:
|
||||||
|
Skybox ();
|
||||||
|
~Skybox ();
|
||||||
|
GLuint m_skyboxVAO;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Bind();
|
||||||
|
void Unbind();
|
||||||
|
void loadCubeTextures(const std::vector<std::string>& texture_faces);
|
||||||
|
|
||||||
|
private:
|
||||||
|
GLuint m_skyboxVBO;
|
||||||
|
GLuint id;
|
||||||
|
std::vector<float> m_skyboxVertices ={
|
||||||
|
// positions
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
-1.0f, -1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
1.0f, 1.0f, -1.0f,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
-1.0f, -1.0f, -1.0f,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
-1.0f, 1.0f, 1.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
-1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, -1.0f, 1.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
1.0f, 1.0f, -1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
-1.0f, 1.0f, 1.0f,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
|
||||||
|
-1.0f, -1.0f, -1.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
1.0f, -1.0f, 1.0f
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
@ -12,7 +12,11 @@ Shader::Shader(const char* vertextPath, const char* fragmentPath)
|
|||||||
fShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
fShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
|
std::cout << "Opening VertexShader.. " << vertextPath << std::endl;
|
||||||
vShaderFile.open(vertextPath);
|
vShaderFile.open(vertextPath);
|
||||||
|
|
||||||
|
std::cout << "Opening FragmentShader.. " << fragmentPath << std::endl;
|
||||||
fShaderFile.open(fragmentPath);
|
fShaderFile.open(fragmentPath);
|
||||||
|
|
||||||
std::stringstream vShaderStream,fShaderStream;
|
std::stringstream vShaderStream,fShaderStream;
|
||||||
@ -20,20 +24,24 @@ Shader::Shader(const char* vertextPath, const char* fragmentPath)
|
|||||||
vShaderStream << vShaderFile.rdbuf();
|
vShaderStream << vShaderFile.rdbuf();
|
||||||
fShaderStream << fShaderFile.rdbuf();
|
fShaderStream << fShaderFile.rdbuf();
|
||||||
|
|
||||||
vShaderFile.close();
|
|
||||||
fShaderFile.close();
|
|
||||||
|
|
||||||
vertexCode = vShaderStream.str();
|
vertexCode = vShaderStream.str();
|
||||||
fragmentCode = fShaderStream.str();
|
fragmentCode = fShaderStream.str();
|
||||||
|
|
||||||
|
|
||||||
|
vShaderFile.close();
|
||||||
|
fShaderFile.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch(std::ifstream::failure e){
|
catch(std::ifstream::failure e){
|
||||||
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl << e.what() << std::endl ;
|
std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl;
|
||||||
|
std::cout << e.what() << "| IO error code: " << e.code() << std::endl ;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* vShaderCode = vertexCode.c_str();
|
const char* vShaderCode = vertexCode.c_str();
|
||||||
const char* fShaderCode = fragmentCode.c_str();
|
const char* fShaderCode = fragmentCode.c_str();
|
||||||
|
|
||||||
|
|
||||||
// Compile Shaders
|
// Compile Shaders
|
||||||
unsigned int vertex, fragment;
|
unsigned int vertex, fragment;
|
||||||
int success;
|
int success;
|
@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
#include "shader.h"
|
|
||||||
|
|
||||||
class RenderPass {
|
|
||||||
public :
|
|
||||||
virtual void Render() = 0;
|
|
||||||
virtual void Setup() = 0;
|
|
||||||
|
|
||||||
RenderPass(const std::string& name, Shader& shader) : m_name(name), m_shader(shader) {}
|
|
||||||
~RenderPass(){}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
const std::string& m_name;
|
|
||||||
Shader& m_shader;
|
|
||||||
};
|
|
@ -1,5 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "texture.h"
|
#include "../Primitives/texture.h"
|
||||||
#include "RenderBuffer.h"
|
#include "RenderBuffer.h"
|
||||||
|
|
||||||
|
|
@ -1,8 +1,35 @@
|
|||||||
#include "OutlinePass.h"
|
#include "OutlinePass.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
OutlinePass::OutlinePass(Shader& shader, Model& sceneObject, glm::mat4& model, glm::mat4& projection, Camera& camera)
|
|
||||||
: RenderPass("Renderpass - Outline", shader ) , m_model(sceneObject), model(model), projection(projection), camera(camera)
|
OutlinePass::OutlinePass(Model& sceneObject, glm::mat4& model, glm::mat4& projection, Camera& camera)
|
||||||
|
: RenderPass("Renderpass - Outline", "../Shaders/shader.vs", "../Shaders/outlineshader.fs" ) , m_model(sceneObject), camera(camera), projection(projection), model(model)
|
||||||
{
|
{
|
||||||
|
// Framebuffer outline effect
|
||||||
|
std::cout << "Create Framebuffer" << std::endl;
|
||||||
|
|
||||||
|
m_outlineFrameBuffer = FrameBuffer();
|
||||||
|
m_outlineFrameBuffer.Bind();
|
||||||
|
|
||||||
|
// Create a texture attachment (colour attachment)
|
||||||
|
std::cout << "Create Texture" << std::endl;
|
||||||
|
m_depthTexture = CreateTexture(800,600);
|
||||||
|
|
||||||
|
// attach texture to the frame buffer as a colour attachment
|
||||||
|
m_outlineFrameBuffer.Attach(*m_depthTexture);
|
||||||
|
|
||||||
|
// Add depth buffer attachment
|
||||||
|
std::cout << "Create RenderBuffer" << std::endl;
|
||||||
|
m_outlineRenderBuffer = RenderBuffer();
|
||||||
|
m_outlineRenderBuffer.Bind();
|
||||||
|
m_outlineRenderBuffer.UseDepthAndStencil();
|
||||||
|
m_outlineRenderBuffer.Unbind();
|
||||||
|
|
||||||
|
// attach depth buffer to our framebuffer
|
||||||
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_outlineRenderBuffer.id);
|
||||||
|
m_outlineFrameBuffer.Unbind();
|
||||||
|
|
||||||
|
std::cout << "Success!" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OutlinePass::~OutlinePass(){
|
OutlinePass::~OutlinePass(){
|
||||||
@ -10,33 +37,9 @@ OutlinePass::~OutlinePass(){
|
|||||||
delete m_depthTexture;
|
delete m_depthTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutlinePass::Setup()
|
|
||||||
{
|
|
||||||
// Framebuffer outline effect
|
|
||||||
m_outlineFrameBuffer = FrameBuffer();
|
|
||||||
m_outlineFrameBuffer.Bind();
|
|
||||||
|
|
||||||
// Create a texture attachment (colour attachment)
|
|
||||||
m_depthTexture = CreateTexture(800,600);
|
|
||||||
|
|
||||||
// attach texture to the frame buffer as a colour attachment
|
|
||||||
m_outlineFrameBuffer.Attach(*m_depthTexture);
|
|
||||||
|
|
||||||
// Add depth buffer attachment
|
|
||||||
m_outlineRenderBuffer = RenderBuffer();
|
|
||||||
m_outlineRenderBuffer.Bind();
|
|
||||||
|
|
||||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800, 600);
|
|
||||||
m_outlineRenderBuffer.Unbind();
|
|
||||||
|
|
||||||
// attach depth buffer to our framebuffer
|
|
||||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_outlineRenderBuffer.id);
|
|
||||||
m_outlineFrameBuffer.Unbind();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void OutlinePass::Render()
|
void OutlinePass::Render()
|
||||||
{
|
{
|
||||||
|
std::cout << "Start outline render" << std::endl;
|
||||||
glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
|
glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
|
||||||
glStencilMask(0x00);
|
glStencilMask(0x00);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
@ -50,9 +53,13 @@ void OutlinePass::Render()
|
|||||||
model = glm::scale(model, glm::vec3(1.05f,1.05f, 1.05f));
|
model = glm::scale(model, glm::vec3(1.05f,1.05f, 1.05f));
|
||||||
m_shader.setMat4("model", model);
|
m_shader.setMat4("model", model);
|
||||||
|
|
||||||
|
std::cout << "Drawing model" << std::endl;
|
||||||
m_model.Draw(m_shader);
|
m_model.Draw(m_shader);
|
||||||
|
|
||||||
|
|
||||||
glStencilFunc(GL_ALWAYS, 1, 0xff);
|
glStencilFunc(GL_ALWAYS, 1, 0xff);
|
||||||
glStencilMask(0xFF);
|
glStencilMask(0xFF);
|
||||||
|
|
||||||
|
std::cout << "Finished outline render" << std::endl;
|
||||||
|
|
||||||
}
|
}
|
@ -3,17 +3,16 @@
|
|||||||
#include "RenderPass.h"
|
#include "RenderPass.h"
|
||||||
#include "FrameBuffer.h"
|
#include "FrameBuffer.h"
|
||||||
#include "RenderBuffer.h"
|
#include "RenderBuffer.h"
|
||||||
#include "texture.h"
|
#include "../model.h"
|
||||||
#include "model.h"
|
#include "../Primitives/texture.h"
|
||||||
#include "camera.h"
|
#include "../Primitives/camera.h"
|
||||||
|
|
||||||
class OutlinePass : RenderPass {
|
class OutlinePass : RenderPass {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Setup() override;
|
|
||||||
void Render() override;
|
void Render() override;
|
||||||
|
|
||||||
OutlinePass (Shader& shader, Model& sceneObject, glm::mat4& model , glm::mat4& projection, Camera& camera) ;
|
OutlinePass (Model& sceneObject, glm::mat4& model , glm::mat4& projection, Camera& camera) ;
|
||||||
~OutlinePass();
|
~OutlinePass();
|
||||||
|
|
||||||
private:
|
private:
|
@ -5,7 +5,7 @@
|
|||||||
class RenderBuffer
|
class RenderBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
unsigned int id;
|
GLuint id;
|
||||||
|
|
||||||
void Bind();
|
void Bind();
|
||||||
void Unbind();
|
void Unbind();
|
19
src/Renderer/RenderPass.h
Normal file
19
src/Renderer/RenderPass.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include "../Primitives/shader.h"
|
||||||
|
|
||||||
|
class RenderPass {
|
||||||
|
public :
|
||||||
|
virtual void Render() = 0;
|
||||||
|
|
||||||
|
RenderPass(const std::string& name,const std::string& VertexShaderFile, const std::string& FragmentShaderFile) : m_shader(VertexShaderFile.c_str(), FragmentShaderFile.c_str())
|
||||||
|
{
|
||||||
|
std::cout << "Created " << name << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
~RenderPass(){}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Shader m_shader;
|
||||||
|
|
||||||
|
};
|
@ -1,34 +1,37 @@
|
|||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <glad/glad.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <cmath>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
void Renderer::Setup()
|
void Renderer::Setup()
|
||||||
{
|
{
|
||||||
framebuffer = new FrameBuffer();
|
framebuffer.Bind();
|
||||||
framebuffer->Bind();
|
|
||||||
|
|
||||||
ColourBuffer = CreateTexture(800,600);
|
ColourBuffer = CreateTexture(800,600);
|
||||||
framebuffer->Attach(*ColourBuffer);
|
framebuffer.Attach(*ColourBuffer);
|
||||||
|
|
||||||
renderbufferObject = new RenderBuffer();
|
renderbufferObject.Bind();
|
||||||
renderbufferObject->Bind();
|
renderbufferObject.UseDepthAndStencil();
|
||||||
renderbufferObject->UseDepthAndStencil();
|
renderbufferObject.Unbind();
|
||||||
renderbufferObject->Unbind();
|
|
||||||
|
|
||||||
framebuffer->Attach(*renderbufferObject);
|
framebuffer.Attach(renderbufferObject);
|
||||||
|
|
||||||
if(framebuffer->IsComplete() == false ){
|
if(framebuffer.IsComplete() == false ){
|
||||||
std::cout << "ERROR::FRAMEBUFFER::Framebuffer is not complete! " << std::endl;
|
std::cout << "ERROR::FRAMEBUFFER::Framebuffer is not complete! " << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
framebuffer->Unbind();
|
framebuffer.Unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Render( )
|
void Renderer::Render( )
|
||||||
{
|
{
|
||||||
float currentFrame = glfwGetTime();
|
|
||||||
deltaTime = currentFrame - lastFrame;
|
|
||||||
lastFrame = currentFrame;
|
|
||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
|
|
||||||
@ -37,20 +40,22 @@ void Renderer::Render()
|
|||||||
// Reset the model matrix to an identity matrix
|
// Reset the model matrix to an identity matrix
|
||||||
model = glm::mat4(1.0f);
|
model = glm::mat4(1.0f);
|
||||||
|
|
||||||
|
framebuffer.Bind();
|
||||||
framebuffer->Bind();
|
|
||||||
std::cout << "Starting Render passes :" << std::endl;
|
|
||||||
|
|
||||||
// Outline of render steps
|
|
||||||
|
|
||||||
// 1. Skybox pass
|
// 1. Skybox pass
|
||||||
|
skyboxpass.Render();
|
||||||
|
|
||||||
// 2. Scene pass
|
// 2. Scene pass
|
||||||
|
scenepass.Render();
|
||||||
|
|
||||||
// 3. outline pass
|
// 3. outline pass
|
||||||
// SKIP for now!
|
|
||||||
|
outlinepass.Render();
|
||||||
|
|
||||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
|
||||||
// 4. draw result to screen
|
// 4. draw result to screen
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
@ -60,9 +65,10 @@ void Renderer::Render()
|
|||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
|
||||||
m_shader->use();
|
m_shader.use();
|
||||||
m_shader->setInt("screenTexture",0);
|
m_shader.setInt("screenTexture",0);
|
||||||
glBindVertexArray(ScreenVAO);
|
glBindVertexArray(ScreenVAO);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, ColourBuffer->id);
|
glBindTexture(GL_TEXTURE_2D, ColourBuffer->id);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
|
|
||||||
@ -74,15 +80,29 @@ void Renderer::Render()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Renderer::Renderer(Camera& camera, Model& scene) :
|
||||||
|
camera(camera),
|
||||||
Renderer::Renderer(Camera& camera)
|
renderbufferObject(),
|
||||||
: camera(camera)
|
framebuffer(),
|
||||||
|
skybox(),
|
||||||
|
skyboxpass(skybox, camera, projection),
|
||||||
|
scenepass(skybox, scene,camera,projection, model),
|
||||||
|
outlinepass(scene, model, projection, camera),
|
||||||
|
m_shader("../Shaders/Framebuffers.vs", "../Shaders/Framebuffers.fs")
|
||||||
{
|
{
|
||||||
deltaTime = 0.0f;
|
|
||||||
/// Create and compile the screen shader
|
|
||||||
m_shader = new Shader ("Shaders/Framebuffers.vs", "Shaders/Framebuffers.fs" );
|
|
||||||
|
|
||||||
|
std::vector<std::string> faces = {
|
||||||
|
"../Textures/skybox/right.jpg",
|
||||||
|
"../Textures/skybox/left.jpg",
|
||||||
|
"../Textures/skybox/top.jpg",
|
||||||
|
"../Textures/skybox/bottom.jpg",
|
||||||
|
"../Textures/skybox/front.jpg",
|
||||||
|
"../Textures/skybox/back.jpg"
|
||||||
|
};
|
||||||
|
skybox.loadCubeTextures(faces);
|
||||||
|
|
||||||
|
|
||||||
|
// auto outlinepass = OutlinePass(scene , model, projection, camera);
|
||||||
// Create ScreenVAO
|
// Create ScreenVAO
|
||||||
glGenVertexArrays(1, &ScreenVAO);
|
glGenVertexArrays(1, &ScreenVAO);
|
||||||
glBindVertexArray(ScreenVAO);
|
glBindVertexArray(ScreenVAO);
|
||||||
@ -99,18 +119,15 @@ Renderer::Renderer(Camera& camera)
|
|||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
|
|
||||||
// Enable features
|
// Enable features
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_STENCIL_TEST);
|
glEnable(GL_STENCIL_TEST);
|
||||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||||
glEnable(GL_MULTISAMPLE);
|
glEnable(GL_MULTISAMPLE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::~Renderer()
|
Renderer::~Renderer()
|
||||||
{
|
{
|
||||||
delete framebuffer;
|
|
||||||
delete renderbufferObject;
|
|
||||||
delete m_shader;
|
|
||||||
delete ColourBuffer;
|
|
||||||
}
|
}
|
@ -1,22 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <glad/glad.h>
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <cmath>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include "../model.h"
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include "../Primitives/camera.h"
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include "../Primitives/shader.h"
|
||||||
|
|
||||||
#include "camera.h"
|
|
||||||
#include "shader.h"
|
|
||||||
#include "model.h"
|
|
||||||
#include "FrameBuffer.h"
|
#include "FrameBuffer.h"
|
||||||
#include "RenderBuffer.h"
|
#include "RenderBuffer.h"
|
||||||
#include "Cubemap.h"
|
|
||||||
#include "SkyboxPass.h"
|
|
||||||
#include "ScenePass.h"
|
#include "ScenePass.h"
|
||||||
|
#include "OutlinePass.h"
|
||||||
|
#include "SkyboxPass.h"
|
||||||
|
|
||||||
|
|
||||||
class Renderer
|
class Renderer
|
||||||
{
|
{
|
||||||
@ -24,19 +16,23 @@ class Renderer
|
|||||||
void Render();
|
void Render();
|
||||||
void Setup();
|
void Setup();
|
||||||
|
|
||||||
Renderer(Camera& camera);
|
Renderer(Camera& camera,Model& scene);
|
||||||
~Renderer();
|
~Renderer();
|
||||||
|
|
||||||
private:
|
|
||||||
Camera& camera;
|
|
||||||
float deltaTime; // Time between current frame and last frame
|
|
||||||
float lastFrame = 0.0f; // Time of last frame
|
|
||||||
GLuint ScreenVAO, VBO;
|
|
||||||
FrameBuffer* framebuffer;
|
|
||||||
RenderBuffer* renderbufferObject;
|
|
||||||
Texture* ColourBuffer;
|
|
||||||
|
|
||||||
Shader* m_shader;
|
private:
|
||||||
|
ScenePass scenepass;
|
||||||
|
SkyboxPass skyboxpass;
|
||||||
|
OutlinePass outlinepass;
|
||||||
|
|
||||||
|
Camera& camera;
|
||||||
|
GLuint ScreenVAO, VBO;
|
||||||
|
FrameBuffer framebuffer;
|
||||||
|
RenderBuffer renderbufferObject;
|
||||||
|
Texture* ColourBuffer;
|
||||||
|
Skybox skybox;
|
||||||
|
|
||||||
|
Shader m_shader;
|
||||||
|
|
||||||
glm::mat4 model = glm::mat4(1.0f);
|
glm::mat4 model = glm::mat4(1.0f);
|
||||||
glm::mat4 view;
|
glm::mat4 view;
|
||||||
@ -55,6 +51,4 @@ class Renderer
|
|||||||
1.0f, 1.0f, 1.0f, 1.0f,
|
1.0f, 1.0f, 1.0f, 1.0f,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
@ -5,14 +5,13 @@ void ScenePass::Render()
|
|||||||
m_shader.use();
|
m_shader.use();
|
||||||
m_shader.setVec3("cameraPos", camera.Position);
|
m_shader.setVec3("cameraPos", camera.Position);
|
||||||
|
|
||||||
if (m_skybox)
|
|
||||||
{
|
|
||||||
glActiveTexture(GL_TEXTURE11);
|
glActiveTexture(GL_TEXTURE11);
|
||||||
m_skybox->Bind();
|
m_skybox.Bind(); // Segmentation Fault HERE!!
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
m_shader.setInt("skybox",11);
|
m_shader.setInt("skybox",11);
|
||||||
}
|
|
||||||
|
|
||||||
m_shader.setMat4("model", model);
|
m_shader.setMat4("model", model);
|
||||||
m_shader.setMat4("view", camera.GetViewMatrix());
|
m_shader.setMat4("view", camera.GetViewMatrix());
|
||||||
@ -20,13 +19,16 @@ void ScenePass::Render()
|
|||||||
|
|
||||||
|
|
||||||
m_scene.Draw(m_shader);
|
m_scene.Draw(m_shader);
|
||||||
}
|
|
||||||
|
|
||||||
void ScenePass::Setup()
|
|
||||||
{
|
m_skybox.Unbind();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScenePass::SetSkybox(Skybox& skybox)
|
void ScenePass::SetSkybox(Skybox& skybox)
|
||||||
{
|
{
|
||||||
m_skybox = &skybox;
|
m_skybox = skybox;
|
||||||
}
|
}
|
33
src/Renderer/ScenePass.h
Normal file
33
src/Renderer/ScenePass.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "RenderPass.h"
|
||||||
|
#include "../Primitives/Skybox.h"
|
||||||
|
#include "../Primitives/shader.h"
|
||||||
|
#include "../Primitives/camera.h"
|
||||||
|
#include "../model.h"
|
||||||
|
|
||||||
|
class ScenePass : public RenderPass {
|
||||||
|
|
||||||
|
public:
|
||||||
|
void Render() override;
|
||||||
|
|
||||||
|
ScenePass(Skybox& skybox, Model& scene, Camera& camera, glm::mat4 projection , glm::mat4 model)
|
||||||
|
: RenderPass("RenderPass - Scene", "../Shaders/shader.vs", "../Shaders/shader.fs" ),
|
||||||
|
m_scene(scene), camera(camera), projection(projection), model(model), m_skybox(skybox)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
~ScenePass() = default;
|
||||||
|
|
||||||
|
void SetSkybox(Skybox& skybox);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Skybox& m_skybox;
|
||||||
|
Model& m_scene;
|
||||||
|
Camera& camera;
|
||||||
|
|
||||||
|
glm::mat4 projection;
|
||||||
|
glm::mat4 model;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
@ -1,13 +1,14 @@
|
|||||||
#include "SkyboxPass.h"
|
#include "SkyboxPass.h"
|
||||||
|
|
||||||
|
SkyboxPass::SkyboxPass(Skybox& skybox, Camera& camera, glm::mat4& projection) : RenderPass("Render Pass - Skybox", "../Shaders/skybox.vs", "../Shaders/Cubemap.fs"),
|
||||||
SkyboxPass::~SkyboxPass()
|
skybox(skybox),
|
||||||
|
camera(camera),
|
||||||
|
projection(projection)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkyboxPass::Setup()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkyboxPass::Render()
|
void SkyboxPass::Render()
|
||||||
{
|
{
|
||||||
@ -19,8 +20,9 @@ void SkyboxPass::Render()
|
|||||||
glm::mat4 centeredView = glm::mat4(glm::mat3(camera.GetViewMatrix()));
|
glm::mat4 centeredView = glm::mat4(glm::mat3(camera.GetViewMatrix()));
|
||||||
m_shader.setMat4("view", centeredView);
|
m_shader.setMat4("view", centeredView);
|
||||||
|
|
||||||
glBindVertexArray(skybox.m_skyboxVAO);
|
|
||||||
skybox.Bind();
|
skybox.Bind();
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||||
|
skybox.Unbind();
|
||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
}
|
}
|
20
src/Renderer/SkyboxPass.h
Normal file
20
src/Renderer/SkyboxPass.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "RenderPass.h"
|
||||||
|
#include "../Primitives/Skybox.h"
|
||||||
|
#include "../Primitives/shader.h"
|
||||||
|
#include "../Primitives/camera.h"
|
||||||
|
|
||||||
|
class SkyboxPass : public RenderPass {
|
||||||
|
public:
|
||||||
|
void Render() override;
|
||||||
|
|
||||||
|
SkyboxPass( Skybox& skybox, Camera& camera, glm::mat4& projection);
|
||||||
|
~SkyboxPass() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Skybox& skybox;
|
||||||
|
Camera& camera;
|
||||||
|
glm::mat4& projection;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
@ -1,28 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "RenderPass.h"
|
|
||||||
#include "Renderer.h"
|
|
||||||
#include "Skybox.h"
|
|
||||||
#include "shader.h"
|
|
||||||
#include "camera.h"
|
|
||||||
#include "model.h"
|
|
||||||
class ScenePass : RenderPass {
|
|
||||||
|
|
||||||
public:
|
|
||||||
void Setup() override;
|
|
||||||
void Render() override;
|
|
||||||
|
|
||||||
ScenePass(Shader& shader, Model& scene, glm::mat4& model, glm::mat4& projection, Camera& camera)
|
|
||||||
: RenderPass("RenderPass - Scene", shader), m_scene(scene), model(model), projection(projection), camera(camera) {}
|
|
||||||
~ScenePass();
|
|
||||||
|
|
||||||
void SetSkybox(Skybox& skybox);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Skybox* m_skybox;
|
|
||||||
Model& m_scene;
|
|
||||||
glm::mat4& model;
|
|
||||||
glm::mat4& projection;
|
|
||||||
Camera& camera;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
@ -1,25 +0,0 @@
|
|||||||
#include "Skybox.h"
|
|
||||||
|
|
||||||
void Skybox::BuildVAO(){
|
|
||||||
// Create SkyboxVAO
|
|
||||||
|
|
||||||
glGenVertexArrays(1, &m_skyboxVAO);
|
|
||||||
glBindVertexArray(m_skyboxVAO);
|
|
||||||
|
|
||||||
glGenBuffers(1, &m_skyboxVBO);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_skyboxVBO);
|
|
||||||
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, m_skyboxVertices.size() * sizeof(float), &m_skyboxVertices[0], GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribPointer(0,3, GL_FLOAT,GL_FALSE, 3 * sizeof(float),(void*) 0);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Skybox::Skybox() : Cubemap()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Skybox::~Skybox(){}
|
|
59
src/Skybox.h
59
src/Skybox.h
@ -1,59 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <vector>
|
|
||||||
#include "Cubemap.h"
|
|
||||||
|
|
||||||
|
|
||||||
class Skybox : public Cubemap {
|
|
||||||
public:
|
|
||||||
Skybox ();
|
|
||||||
~Skybox ();
|
|
||||||
|
|
||||||
void BuildVAO();
|
|
||||||
GLuint m_skyboxVAO;
|
|
||||||
private:
|
|
||||||
GLuint m_skyboxVBO;
|
|
||||||
std::vector<float> m_skyboxVertices = {
|
|
||||||
// positions
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, -1.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
1.0f, -1.0f, 1.0f
|
|
||||||
};
|
|
||||||
};
|
|
@ -1,21 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "RenderPass.h"
|
|
||||||
#include "Renderer.h"
|
|
||||||
#include "Skybox.h"
|
|
||||||
#include "shader.h"
|
|
||||||
|
|
||||||
class SkyboxPass : RenderPass {
|
|
||||||
public:
|
|
||||||
void Render() override;
|
|
||||||
void Setup() override;
|
|
||||||
|
|
||||||
SkyboxPass(Shader& shader, glm::mat4& projection, Skybox& skybox, Camera& camera)
|
|
||||||
: RenderPass("Render Pass - Skybox", shader), projection(projection), skybox(skybox), camera(camera){}
|
|
||||||
~SkyboxPass();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Skybox skybox;
|
|
||||||
glm::mat4& projection;
|
|
||||||
Camera& camera;
|
|
||||||
|
|
||||||
};
|
|
@ -1,9 +1,5 @@
|
|||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
|
||||||
bool firstMouse = true;
|
|
||||||
float lastx = 400, lasty = 300;
|
|
||||||
|
|
||||||
|
|
||||||
Window::Window(int initialWidth, int initialHeight, const std::string& WindowName)
|
Window::Window(int initialWidth, int initialHeight, const std::string& WindowName)
|
||||||
: m_width(initialWidth), m_height(initialHeight), m_WindowName(WindowName)
|
: m_width(initialWidth), m_height(initialHeight), m_WindowName(WindowName)
|
||||||
{
|
{
|
||||||
@ -38,7 +34,7 @@ Window::Window(int initialWidth, int initialHeight, const std::string& WindowNam
|
|||||||
// Setup Callbacks
|
// Setup Callbacks
|
||||||
glfwSetFramebufferSizeCallback(m_window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(m_window, framebuffer_size_callback);
|
||||||
//glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
//glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
glfwSetCursorPosCallback(m_window, mouse_callback);
|
//glfwSetCursorPosCallback(m_window, mouse_callback);
|
||||||
glfwSetScrollCallback(m_window, scroll_callback);
|
glfwSetScrollCallback(m_window, scroll_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,30 +44,3 @@ Window::~Window()
|
|||||||
glfwDestroyWindow(m_window);
|
glfwDestroyWindow(m_window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
|
||||||
{
|
|
||||||
if(firstMouse){
|
|
||||||
lastx = xpos;
|
|
||||||
lasty = ypos;
|
|
||||||
firstMouse = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
float xoffset = xpos - lastx;
|
|
||||||
float yoffset = ypos - lasty;
|
|
||||||
|
|
||||||
lastx = xpos;
|
|
||||||
lasty - ypos;
|
|
||||||
|
|
||||||
// camera.ProcessMouseMovement(xoffset, yoffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
|
||||||
{
|
|
||||||
glViewport(0,0, width,height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
|
||||||
{
|
|
||||||
// camera.ProcessMouseScroll(yoffset);
|
|
||||||
}
|
|
@ -18,8 +18,8 @@ class Window
|
|||||||
double getRatio(){return (this->m_width / this->m_height);}
|
double getRatio(){return (this->m_width / this->m_height);}
|
||||||
|
|
||||||
bool shouldClose(){ return glfwWindowShouldClose(m_window);}
|
bool shouldClose(){ return glfwWindowShouldClose(m_window);}
|
||||||
//void GetInput(){ processInput(m_window);}
|
|
||||||
void SwapBuffers(){ glfwSwapBuffers(m_window);}
|
void SwapBuffers(){ glfwSwapBuffers(m_window);}
|
||||||
|
GLFWwindow* ptr () { return m_window; }
|
||||||
private:
|
private:
|
||||||
int m_width, m_height;
|
int m_width, m_height;
|
||||||
const std::string& m_WindowName;
|
const std::string& m_WindowName;
|
||||||
|
104
src/main.cpp
104
src/main.cpp
@ -2,82 +2,100 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer/Renderer.h"
|
||||||
#include "Skybox.h"
|
#include "Primitives/Skybox.h"
|
||||||
#include "shader.h"
|
#include "Primitives/shader.h"
|
||||||
#include "camera.h"
|
#include "Primitives/camera.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include <stb_image.h>
|
||||||
|
|
||||||
class LearnOpenGL : Application
|
void processInput( GLFWwindow* window);
|
||||||
{
|
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||||
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||||
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
|
||||||
|
|
||||||
public:
|
float deltaTime = 0.0f; ; // Time between current frame and last frame
|
||||||
void Run () override{
|
float lastFrame = 0.0f; // Time of last frame
|
||||||
// Create a window
|
bool firstMouse = true;
|
||||||
Window window(800,600, "LearnOpenGL");
|
float lastx = 400, lasty = 300;
|
||||||
|
|
||||||
Camera camera(glm::vec3(0.0f,0.0f,8.0f));
|
Camera camera(glm::vec3(0.0f,0.0f,8.0f));
|
||||||
|
|
||||||
Renderer renderer = Renderer(camera);
|
class LearnOpenGL : Application
|
||||||
|
{
|
||||||
renderer.Setup();
|
public:
|
||||||
|
void Run () override
|
||||||
|
{
|
||||||
|
// Create a window
|
||||||
|
Window window(800,600, "LearnOpenGL");
|
||||||
|
|
||||||
stbi_set_flip_vertically_on_load(true);
|
stbi_set_flip_vertically_on_load(true);
|
||||||
|
|
||||||
// Load scene resources
|
Model backpack("../Models/backpack.obj");
|
||||||
Shader shader ("Shaders/shader.vs", "Shaders/shader.fs");
|
|
||||||
Shader outlineShader("Shaders/shader.vs","Shaders/outlineshader.fs");
|
|
||||||
Shader skyboxShader("Shaders/skybox.vs", "Shaders/Cubemap.fs");
|
|
||||||
|
|
||||||
Model backpack("Models/backpack.obj");
|
Renderer renderer = Renderer(camera, backpack);
|
||||||
int bullshit = 0;
|
renderer.Setup();
|
||||||
std::vector<std::string> faces = {
|
|
||||||
"Textures/skybox/right.jpg",
|
|
||||||
"Textures/skybox/left.jpg",
|
|
||||||
"Textures/skybox/top.jpg",
|
|
||||||
"Textures/skybox/bottom.jpg",
|
|
||||||
"Textures/skybox/front.jpg",
|
|
||||||
"Textures/skybox/back.jpg"
|
|
||||||
};
|
|
||||||
|
|
||||||
Skybox skybox= Skybox ();
|
|
||||||
skybox.Bind();
|
|
||||||
skybox.loadCubeTextures(faces);
|
|
||||||
skybox.BuildVAO();
|
|
||||||
|
|
||||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
while(!window.shouldClose())
|
while(!window.shouldClose())
|
||||||
{
|
{
|
||||||
//window.GetInput();
|
float currentFrame = glfwGetTime();
|
||||||
|
deltaTime = currentFrame - lastFrame;
|
||||||
|
lastFrame = currentFrame;
|
||||||
|
|
||||||
|
glfwPollEvents();
|
||||||
|
processInput(window.ptr());
|
||||||
|
|
||||||
renderer.Render();
|
renderer.Render();
|
||||||
|
|
||||||
window.SwapBuffers();
|
window.SwapBuffers();
|
||||||
glfwPollEvents();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
void processInput( GLFWwindow* window)
|
||||||
|
{
|
||||||
void processInput( GLFWwindow* window){
|
|
||||||
if(glfwGetKey(window,GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
if(glfwGetKey(window,GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, true);
|
glfwSetWindowShouldClose(window, true);
|
||||||
|
|
||||||
const float CameraSpeed = 2.5f * Renderer::deltaTime;
|
const float CameraSpeed = 0.5f * deltaTime;
|
||||||
if(glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if(glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
Renderer::camera.ProcessKeyboard(FORWARD, Renderer::deltaTime);
|
camera.ProcessKeyboard(FORWARD, CameraSpeed);
|
||||||
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if(glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
Renderer::camera.ProcessKeyboard(BACKWARD, Renderer::deltaTime);
|
camera.ProcessKeyboard(BACKWARD,CameraSpeed);
|
||||||
if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
if(glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||||
Renderer::camera.ProcessKeyboard(LEFT, Renderer::deltaTime);
|
camera.ProcessKeyboard(LEFT, CameraSpeed);
|
||||||
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
if(glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||||
Renderer::camera.ProcessKeyboard(RIGHT,Renderer::deltaTime);
|
camera.ProcessKeyboard(RIGHT,CameraSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
void mouse_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
|
{
|
||||||
|
if(firstMouse){
|
||||||
|
lastx = xpos;
|
||||||
|
lasty = ypos;
|
||||||
|
firstMouse = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float xoffset = xpos - lastx;
|
||||||
|
float yoffset = ypos - lasty;
|
||||||
|
|
||||||
|
lastx = xpos;
|
||||||
|
lasty - ypos;
|
||||||
|
|
||||||
|
camera.ProcessMouseMovement(xoffset, yoffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
|
||||||
|
{
|
||||||
|
glViewport(0,0, width,height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
|
||||||
|
{
|
||||||
|
camera.ProcessMouseScroll(yoffset);
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
#include <stb_image.h>
|
||||||
|
|
||||||
|
#include <assimp/Importer.hpp> // C++ importer interface
|
||||||
|
#include <assimp/postprocess.h> // Post Processing flags
|
||||||
|
|
||||||
Model::Model(std::string const& path){
|
Model::Model(std::string const& path){
|
||||||
loadModel(path);
|
loadModel(path);
|
||||||
@ -11,7 +14,7 @@ void Model::Draw(Shader& shader)
|
|||||||
meshes[i].Draw(shader);
|
meshes[i].Draw(shader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Model::loadModel(std::string path)
|
void Model::loadModel(std::string const& path)
|
||||||
{
|
{
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
|
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
|
||||||
|
18
src/model.h
18
src/model.h
@ -2,29 +2,21 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "mesh.h"
|
|
||||||
#include "shader.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include "stb_image.h"
|
|
||||||
|
|
||||||
#include <assimp/Importer.hpp> // C++ importer interface
|
|
||||||
#include <assimp/scene.h> // Output data structure
|
#include <assimp/scene.h> // Output data structure
|
||||||
#include <assimp/postprocess.h> // Post Processing flags
|
|
||||||
|
#include "Primitives/mesh.h"
|
||||||
|
#include "Primitives/shader.h"
|
||||||
class Model {
|
class Model {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
Model(std::string const& path);
|
Model(std::string const& path);
|
||||||
void Draw(Shader& shader);
|
void Draw(Shader& shader);
|
||||||
private:
|
|
||||||
// model data
|
|
||||||
|
|
||||||
|
private:
|
||||||
std::vector<Texture> textures_loaded;
|
std::vector<Texture> textures_loaded;
|
||||||
std::vector<Mesh> meshes;
|
std::vector<Mesh> meshes;
|
||||||
std::string directory;
|
std::string directory;
|
||||||
|
|
||||||
void loadModel(std::string path);
|
void loadModel(std::string const& path);
|
||||||
void processNode(aiNode* node, const aiScene* scene );
|
void processNode(aiNode* node, const aiScene* scene );
|
||||||
Mesh processMesh(aiMesh* mesh, const aiScene* scene);
|
Mesh processMesh(aiMesh* mesh, const aiScene* scene);
|
||||||
std::vector<Texture> loadMaterialTextures(aiMaterial* mat, aiTextureType type, std::string typeName );
|
std::vector<Texture> loadMaterialTextures(aiMaterial* mat, aiTextureType type, std::string typeName );
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
#define STB_IMAGE_IMPLEMENTATION
|
|
||||||
#include "stb_image.h"
|
|
||||||
|
|
7897
src/stb_image.h
7897
src/stb_image.h
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user