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:
Nigel Barink 2023-02-03 16:33:02 +01:00
parent 4355a12b9a
commit 85263312cd
37 changed files with 405 additions and 8295 deletions

View File

@ -3,10 +3,14 @@ CFLAGS = -std=c++17 -O2 -g
LDFLAGS = -lglfw3 -lGL -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi -lz -lassimp
OUT_NAME = LearnOpenGL
build: src/*.cpp src/*.h
build: src/*.cpp src/*.h src/**/*.cpp src/**/*.h
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)
./build/$(OUT_NAME)
debug: build build/$(OUT_NAME)
gdb build/$(OUT_NAME)

View File

@ -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);
};

View File

@ -1,25 +1,53 @@
#include "Cubemap.h"
#include "Skybox.h"
Cubemap::Cubemap(){
glGenTextures(1,&id);
}
Cubemap::~Cubemap(){
// glDeleteTextures(id);
}
void Cubemap::Bind(){
Skybox::Skybox()
{
glGenTextures(1, &id);
// Create SkyboxVAO
glGenVertexArrays(1, &m_skyboxVAO);
glBindVertexArray(m_skyboxVAO);
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
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;
}
Skybox::~Skybox()
{
glDeleteTextures(1, &id);
std::cout << "Skybox destroyed!" << std::endl;
}
void Skybox::Bind()
{
glBindVertexArray(m_skyboxVAO);
glBindTexture(GL_TEXTURE_CUBE_MAP, id);
};
void Cubemap::Unbind(){
void Skybox::Unbind()
{
glBindVertexArray(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;
unsigned char* data;
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);
Unbind();
}

70
src/Primitives/Skybox.h Normal file
View 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
};
};

View File

@ -12,7 +12,11 @@ Shader::Shader(const char* vertextPath, const char* fragmentPath)
fShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try{
std::cout << "Opening VertexShader.. " << vertextPath << std::endl;
vShaderFile.open(vertextPath);
std::cout << "Opening FragmentShader.. " << fragmentPath << std::endl;
fShaderFile.open(fragmentPath);
std::stringstream vShaderStream,fShaderStream;
@ -20,20 +24,24 @@ Shader::Shader(const char* vertextPath, const char* fragmentPath)
vShaderStream << vShaderFile.rdbuf();
fShaderStream << fShaderFile.rdbuf();
vShaderFile.close();
fShaderFile.close();
vertexCode = vShaderStream.str();
fragmentCode = fShaderStream.str();
vShaderFile.close();
fShaderFile.close();
}
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* fShaderCode = fragmentCode.c_str();
// Compile Shaders
unsigned int vertex, fragment;
int success;

View File

@ -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;
};

View File

@ -1,5 +1,5 @@
#pragma once
#include "texture.h"
#include "../Primitives/texture.h"
#include "RenderBuffer.h"

View File

@ -1,8 +1,35 @@
#include "OutlinePass.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(){
@ -10,33 +37,9 @@ OutlinePass::~OutlinePass(){
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()
{
std::cout << "Start outline render" << std::endl;
glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
glStencilMask(0x00);
glDisable(GL_DEPTH_TEST);
@ -49,10 +52,14 @@ void OutlinePass::Render()
model = glm::scale(model, glm::vec3(1.05f,1.05f, 1.05f));
m_shader.setMat4("model", model);
std::cout << "Drawing model" << std::endl;
m_model.Draw(m_shader);
glStencilFunc(GL_ALWAYS, 1, 0xff);
glStencilMask(0xFF);
std::cout << "Finished outline render" << std::endl;
}

View File

@ -3,17 +3,16 @@
#include "RenderPass.h"
#include "FrameBuffer.h"
#include "RenderBuffer.h"
#include "texture.h"
#include "model.h"
#include "camera.h"
#include "../model.h"
#include "../Primitives/texture.h"
#include "../Primitives/camera.h"
class OutlinePass : RenderPass {
public:
void Setup() 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();
private:

View File

@ -5,7 +5,7 @@
class RenderBuffer
{
public:
unsigned int id;
GLuint id;
void Bind();
void Unbind();

19
src/Renderer/RenderPass.h Normal file
View 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;
};

View File

@ -1,34 +1,37 @@
#include "Renderer.h"
#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()
{
framebuffer = new FrameBuffer();
framebuffer->Bind();
framebuffer.Bind();
ColourBuffer = CreateTexture(800,600);
framebuffer->Attach(*ColourBuffer);
framebuffer.Attach(*ColourBuffer);
renderbufferObject = new RenderBuffer();
renderbufferObject->Bind();
renderbufferObject->UseDepthAndStencil();
renderbufferObject->Unbind();
renderbufferObject.Bind();
renderbufferObject.UseDepthAndStencil();
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;
}
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);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
@ -37,19 +40,21 @@ void Renderer::Render()
// Reset the model matrix to an identity matrix
model = glm::mat4(1.0f);
framebuffer->Bind();
std::cout << "Starting Render passes :" << std::endl;
// Outline of render steps
framebuffer.Bind();
// 1. Skybox pass
skyboxpass.Render();
// 2. Scene pass
scenepass.Render();
// 3. outline pass
// SKIP for now!
outlinepass.Render();
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// 4. draw result to screen
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -60,9 +65,10 @@ void Renderer::Render()
glClear(GL_COLOR_BUFFER_BIT);
m_shader->use();
m_shader->setInt("screenTexture",0);
m_shader.use();
m_shader.setInt("screenTexture",0);
glBindVertexArray(ScreenVAO);
glBindTexture(GL_TEXTURE_2D, ColourBuffer->id);
glDrawArrays(GL_TRIANGLES, 0, 6);
@ -74,15 +80,29 @@ void Renderer::Render()
}
Renderer::Renderer(Camera& camera)
: camera(camera)
Renderer::Renderer(Camera& camera, Model& scene) :
camera(camera),
renderbufferObject(),
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
glGenVertexArrays(1, &ScreenVAO);
glBindVertexArray(ScreenVAO);
@ -99,18 +119,15 @@ Renderer::Renderer(Camera& camera)
glBindVertexArray(0);
// Enable features
glEnable(GL_DEPTH_TEST);
glEnable(GL_STENCIL_TEST);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glEnable(GL_MULTISAMPLE);
}
Renderer::~Renderer()
{
delete framebuffer;
delete renderbufferObject;
delete m_shader;
delete ColourBuffer;
}

View File

@ -1,22 +1,14 @@
#pragma once
#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>
#include "camera.h"
#include "shader.h"
#include "model.h"
#include "../model.h"
#include "../Primitives/camera.h"
#include "../Primitives/shader.h"
#include "FrameBuffer.h"
#include "RenderBuffer.h"
#include "Cubemap.h"
#include "SkyboxPass.h"
#include "ScenePass.h"
#include "OutlinePass.h"
#include "SkyboxPass.h"
class Renderer
{
@ -24,19 +16,23 @@ class Renderer
void Render();
void Setup();
Renderer(Camera& camera);
Renderer(Camera& camera,Model& scene);
~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;
ScenePass scenepass;
SkyboxPass skyboxpass;
OutlinePass outlinepass;
Shader* m_shader;
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 view;
@ -55,6 +51,4 @@ class Renderer
1.0f, 1.0f, 1.0f, 1.0f,
};
};

View File

@ -5,14 +5,13 @@ void ScenePass::Render()
m_shader.use();
m_shader.setVec3("cameraPos", camera.Position);
if (m_skybox)
{
glActiveTexture(GL_TEXTURE11);
m_skybox->Bind();
glActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE11);
m_skybox.Bind(); // Segmentation Fault HERE!!
glActiveTexture(GL_TEXTURE0);
m_shader.setInt("skybox",11);
m_shader.setInt("skybox",11);
}
m_shader.setMat4("model", model);
m_shader.setMat4("view", camera.GetViewMatrix());
@ -20,13 +19,16 @@ void ScenePass::Render()
m_scene.Draw(m_shader);
}
void ScenePass::Setup()
{
m_skybox.Unbind();
}
void ScenePass::SetSkybox(Skybox& skybox)
{
m_skybox = &skybox;
m_skybox = skybox;
}

33
src/Renderer/ScenePass.h Normal file
View 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;
};

View File

@ -1,13 +1,14 @@
#include "SkyboxPass.h"
SkyboxPass::~SkyboxPass()
SkyboxPass::SkyboxPass(Skybox& skybox, Camera& camera, glm::mat4& projection) : RenderPass("Render Pass - Skybox", "../Shaders/skybox.vs", "../Shaders/Cubemap.fs"),
skybox(skybox),
camera(camera),
projection(projection)
{
}
void SkyboxPass::Setup()
{
}
void SkyboxPass::Render()
{
@ -19,8 +20,9 @@ void SkyboxPass::Render()
glm::mat4 centeredView = glm::mat4(glm::mat3(camera.GetViewMatrix()));
m_shader.setMat4("view", centeredView);
glBindVertexArray(skybox.m_skyboxVAO);
skybox.Bind();
glDrawArrays(GL_TRIANGLES, 0, 36);
skybox.Unbind();
glDepthMask(GL_TRUE);
}

20
src/Renderer/SkyboxPass.h Normal file
View 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;
};

View File

@ -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;
};

View File

@ -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(){}

View File

@ -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
};
};

View File

@ -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;
};

View File

@ -1,9 +1,5 @@
#include "Window.h"
bool firstMouse = true;
float lastx = 400, lasty = 300;
Window::Window(int initialWidth, int initialHeight, const std::string& 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
glfwSetFramebufferSizeCallback(m_window, framebuffer_size_callback);
//glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glfwSetCursorPosCallback(m_window, mouse_callback);
//glfwSetCursorPosCallback(m_window, mouse_callback);
glfwSetScrollCallback(m_window, scroll_callback);
}
@ -48,30 +44,3 @@ Window::~Window()
glfwDestroyWindow(m_window);
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);
}

View File

@ -18,8 +18,8 @@ class Window
double getRatio(){return (this->m_width / this->m_height);}
bool shouldClose(){ return glfwWindowShouldClose(m_window);}
//void GetInput(){ processInput(m_window);}
void SwapBuffers(){ glfwSwapBuffers(m_window);}
GLFWwindow* ptr () { return m_window; }
private:
int m_width, m_height;
const std::string& m_WindowName;

View File

@ -2,82 +2,100 @@
#include <vector>
#include <string>
#include "Window.h"
#include "Renderer.h"
#include "Skybox.h"
#include "shader.h"
#include "camera.h"
#include "Renderer/Renderer.h"
#include "Primitives/Skybox.h"
#include "Primitives/shader.h"
#include "Primitives/camera.h"
#include "Application.h"
#include <stb_image.h>
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);
float deltaTime = 0.0f; ; // Time between current frame and last frame
float lastFrame = 0.0f; // Time of last frame
bool firstMouse = true;
float lastx = 400, lasty = 300;
Camera camera(glm::vec3(0.0f,0.0f,8.0f));
class LearnOpenGL : Application
{
public:
void Run () override{
void Run () override
{
// Create a window
Window window(800,600, "LearnOpenGL");
Camera camera(glm::vec3(0.0f,0.0f,8.0f));
Renderer renderer = Renderer(camera);
renderer.Setup();
stbi_set_flip_vertically_on_load(true);
// Load scene resources
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");
Model backpack("Models/backpack.obj");
int bullshit = 0;
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();
Renderer renderer = Renderer(camera, backpack);
renderer.Setup();
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
while(!window.shouldClose())
{
//window.GetInput();
float currentFrame = glfwGetTime();
deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;
glfwPollEvents();
processInput(window.ptr());
renderer.Render();
window.SwapBuffers();
glfwPollEvents();
}
}
};
/*
void processInput( GLFWwindow* window){
void processInput( GLFWwindow* window)
{
if(glfwGetKey(window,GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
const float CameraSpeed = 2.5f * Renderer::deltaTime;
const float CameraSpeed = 0.5f * deltaTime;
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)
Renderer::camera.ProcessKeyboard(BACKWARD, Renderer::deltaTime);
camera.ProcessKeyboard(BACKWARD,CameraSpeed);
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)
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()
{

View File

@ -1,5 +1,8 @@
#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){
loadModel(path);
@ -11,7 +14,7 @@ void Model::Draw(Shader& shader)
meshes[i].Draw(shader);
}
void Model::loadModel(std::string path)
void Model::loadModel(std::string const& path)
{
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);

View File

@ -2,29 +2,21 @@
#include <string>
#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/postprocess.h> // Post Processing flags
#include "Primitives/mesh.h"
#include "Primitives/shader.h"
class Model {
public:
Model(std::string const& path);
void Draw(Shader& shader);
private:
// model data
private:
std::vector<Texture> textures_loaded;
std::vector<Mesh> meshes;
std::string directory;
void loadModel(std::string path);
void loadModel(std::string const& path);
void processNode(aiNode* node, const aiScene* scene );
Mesh processMesh(aiMesh* mesh, const aiScene* scene);
std::vector<Texture> loadMaterialTextures(aiMaterial* mat, aiTextureType type, std::string typeName );

View File

@ -1,3 +0,0 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

File diff suppressed because it is too large Load Diff