Adding ImGui , fixing some minor framebuffer error
This commit is contained in:
parent
dc89cc6173
commit
3acc8525b0
26
CheckErrors.h
Normal file
26
CheckErrors.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "GLFW/glfw3.h"
|
||||
#include <string>
|
||||
#include <glad/glad.h>
|
||||
#include <iostream>
|
||||
GLenum glCheckError_(const char* file, int line) {
|
||||
GLenum errorCode;
|
||||
while ((errorCode = glGetError()) != GL_NO_ERROR)
|
||||
{
|
||||
std::string error;
|
||||
switch (errorCode) {
|
||||
case GL_INVALID_ENUM: error = "INVALID_ENUM"; break;
|
||||
case GL_INVALID_VALUE: error = "INVALID_VALUE"; break;
|
||||
case GL_INVALID_OPERATION: error = "INVALID_OPERATION"; break;
|
||||
case GL_STACK_OVERFLOW: error = "STACK_OVERFLOW"; break;
|
||||
case GL_STACK_UNDERFLOW: error = "STACK_UNDERFLOW"; break;
|
||||
case GL_OUT_OF_MEMORY: error = "OUT_OF_MEMORY"; break;
|
||||
case GL_INVALID_FRAMEBUFFER_OPERATION: error = "INVALID_FRAMEBUFFER_OPERATION"; break;
|
||||
}
|
||||
std::cout << error << " | " << file << "(" << line << ")" << std::endl;
|
||||
|
||||
}
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
#define glCheckError() glCheckError_(__FILE__, __LINE__)
|
12
premake5.lua
12
premake5.lua
@ -8,7 +8,14 @@ project "LearnOpenGL"
|
||||
targetdir "build/"
|
||||
targetname "LearnOpenGL"
|
||||
|
||||
files {"vendor/GLAD/src/glad.c","src/**.h", "src/**.cpp"}
|
||||
files {
|
||||
"vendor/GLAD/src/glad.c",
|
||||
"vendor/ImGui/imgui*.cpp",
|
||||
"vendor/ImGui/backends/imgui_impl_glfw.cpp",
|
||||
"vendor/ImGui/backends/imgui_impl_opengl3.cpp",
|
||||
"src/**.h",
|
||||
"src/**.cpp"
|
||||
}
|
||||
|
||||
includedirs {
|
||||
"vendor/GLAD/include",
|
||||
@ -16,7 +23,8 @@ project "LearnOpenGL"
|
||||
"vendor/assimp/include",
|
||||
"vendor/assimp/build/include",
|
||||
"vendor/glm",
|
||||
"vendor/stb"
|
||||
"vendor/stb",
|
||||
"vendor/ImGui"
|
||||
}
|
||||
|
||||
libdirs{
|
||||
|
@ -1,40 +1,59 @@
|
||||
#include "OutlinePass.h"
|
||||
#include "Renderer.h"
|
||||
#include "../../CheckErrors.h"
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
void OutlinePass::Create() {
|
||||
// Framebuffer outline effect
|
||||
std::cout << "Create Framebuffer" << std::endl;
|
||||
|
||||
m_outlineFrameBuffer = FrameBuffer();
|
||||
m_outlineFrameBuffer.Bind();
|
||||
m_outlineFrameBuffer = new FrameBuffer();
|
||||
glCheckError();
|
||||
|
||||
m_outlineFrameBuffer->Bind();
|
||||
glCheckError();
|
||||
|
||||
// Create a texture attachment (colour attachment)
|
||||
std::cout << "Create Texture" << std::endl;
|
||||
m_depthTexture = CreateTexture(800,600);
|
||||
m_colourTexture = CreateTexture(800, 600);
|
||||
glCheckError();
|
||||
|
||||
// attach texture to the frame buffer as a colour attachment
|
||||
m_outlineFrameBuffer.Attach(*m_depthTexture);
|
||||
m_outlineFrameBuffer->Attach(*m_colourTexture);
|
||||
glCheckError();
|
||||
|
||||
// Add depth buffer attachment
|
||||
std::cout << "Create RenderBuffer" << std::endl;
|
||||
m_outlineRenderBuffer = RenderBuffer();
|
||||
m_outlineRenderBuffer.Bind();
|
||||
m_outlineRenderBuffer.UseDepthAndStencil();
|
||||
m_outlineRenderBuffer.Unbind();
|
||||
m_outlineRenderBuffer = new RenderBuffer();
|
||||
glCheckError();
|
||||
|
||||
m_outlineRenderBuffer->Bind();
|
||||
glCheckError();
|
||||
|
||||
m_outlineRenderBuffer->UseDepthAndStencil();
|
||||
glCheckError();
|
||||
|
||||
m_outlineRenderBuffer->Unbind();
|
||||
glCheckError();
|
||||
|
||||
// attach depth buffer to our framebuffer
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_outlineRenderBuffer.id);
|
||||
m_outlineFrameBuffer.Unbind();
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_outlineRenderBuffer->id);
|
||||
glCheckError();
|
||||
|
||||
m_outlineFrameBuffer->Unbind();
|
||||
glCheckError();
|
||||
|
||||
std::cout << "Success!" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
OutlinePass::~OutlinePass(){
|
||||
|
||||
delete m_depthTexture;
|
||||
OutlinePass::~OutlinePass(){
|
||||
delete m_colourTexture;
|
||||
delete m_outlineRenderBuffer;
|
||||
}
|
||||
|
||||
void OutlinePass::Render()
|
||||
|
@ -13,12 +13,13 @@ public:
|
||||
void Render() override;
|
||||
|
||||
OutlinePass (Model& sceneObject, glm::mat4& model , glm::mat4& projection, Camera& camera) ;
|
||||
void Create();
|
||||
~OutlinePass();
|
||||
|
||||
private:
|
||||
FrameBuffer m_outlineFrameBuffer;
|
||||
RenderBuffer m_outlineRenderBuffer;
|
||||
Texture* m_depthTexture;
|
||||
FrameBuffer* m_outlineFrameBuffer;
|
||||
RenderBuffer* m_outlineRenderBuffer;
|
||||
Texture* m_colourTexture;
|
||||
|
||||
glm::mat4 model;
|
||||
glm::mat4 projection;
|
||||
|
@ -21,5 +21,5 @@ RenderBuffer::RenderBuffer()
|
||||
|
||||
RenderBuffer::~RenderBuffer()
|
||||
{
|
||||
glDeleteRenderbuffers(GL_RENDERBUFFER, &id);
|
||||
// glDeleteRenderbuffers(GL_RENDERBUFFER, &id);
|
||||
}
|
||||
|
@ -9,18 +9,23 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
void Renderer::Setup()
|
||||
{
|
||||
framebuffer.Bind();
|
||||
|
||||
|
||||
ColourBuffer = CreateTexture(800,600);
|
||||
|
||||
|
||||
framebuffer.Attach(*ColourBuffer);
|
||||
|
||||
renderbufferObject.Bind();
|
||||
|
||||
renderbufferObject.UseDepthAndStencil();
|
||||
|
||||
renderbufferObject.Unbind();
|
||||
|
||||
|
||||
framebuffer.Attach(renderbufferObject);
|
||||
|
||||
if(framebuffer.IsComplete() == false ){
|
||||
@ -33,6 +38,7 @@ void Renderer::Setup()
|
||||
void Renderer::Render( )
|
||||
{
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
|
||||
// Recalculate the Camera's view matrix
|
||||
@ -44,7 +50,6 @@ void Renderer::Render( )
|
||||
|
||||
// 1. Skybox pass
|
||||
skyboxpass.Render();
|
||||
|
||||
// 2. Scene pass
|
||||
scenepass.Render();
|
||||
|
||||
@ -70,6 +75,7 @@ void Renderer::Render( )
|
||||
glBindVertexArray(ScreenVAO);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, ColourBuffer->id);
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
|
||||
@ -91,6 +97,10 @@ Renderer::Renderer(Camera& camera, Model& scene) :
|
||||
m_shader("../Shaders/Framebuffers.vs", "../Shaders/Framebuffers.fs")
|
||||
{
|
||||
|
||||
|
||||
outlinepass.Create();
|
||||
|
||||
|
||||
std::vector<std::string> faces = {
|
||||
"../Textures/skybox/right.jpg",
|
||||
"../Textures/skybox/left.jpg",
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include "SkyboxPass.h"
|
||||
|
||||
SkyboxPass::SkyboxPass(Skybox& skybox, Camera& camera, glm::mat4& projection) : RenderPass("Render Pass - Skybox", "../Shaders/skybox.vs", "../Shaders/Cubemap.fs"),
|
||||
skybox(skybox),
|
||||
camera(camera),
|
||||
@ -15,14 +14,19 @@ void SkyboxPass::Render()
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
m_shader.use();
|
||||
m_shader.setMat4("projection", projection);
|
||||
|
||||
m_shader.setMat4("projection", projection);
|
||||
glm::mat4 centeredView = glm::mat4(glm::mat3(camera.GetViewMatrix()));
|
||||
m_shader.setMat4("view", centeredView);
|
||||
|
||||
|
||||
|
||||
skybox.Bind();
|
||||
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
|
||||
skybox.Unbind();
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
36
src/main.cpp
36
src/main.cpp
@ -6,10 +6,17 @@
|
||||
#include "Primitives/Skybox.h"
|
||||
#include "Primitives/shader.h"
|
||||
#include "Primitives/camera.h"
|
||||
#include "Application.h"
|
||||
#include <imgui.h>
|
||||
#include <backends/imgui_impl_glfw.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image.h>
|
||||
|
||||
#include "Application.h"
|
||||
|
||||
|
||||
|
||||
void processInput( GLFWwindow* window);
|
||||
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
|
||||
@ -30,6 +37,16 @@ public:
|
||||
// Create a window
|
||||
Window window(800,600, "LearnOpenGL");
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();(void)io;
|
||||
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(window.ptr(), true);
|
||||
ImGui_ImplOpenGL3_Init("#version 460");
|
||||
|
||||
stbi_set_flip_vertically_on_load(true);
|
||||
|
||||
Model backpack("../Models/backpack.obj");
|
||||
@ -37,6 +54,8 @@ public:
|
||||
Renderer renderer = Renderer(camera, backpack);
|
||||
renderer.Setup();
|
||||
|
||||
|
||||
|
||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
while(!window.shouldClose())
|
||||
{
|
||||
@ -46,12 +65,25 @@ public:
|
||||
|
||||
glfwPollEvents();
|
||||
processInput(window.ptr());
|
||||
|
||||
renderer.Render();
|
||||
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
ImGui::ShowDemoWindow(nullptr);
|
||||
|
||||
ImGui::Render();
|
||||
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
window.SwapBuffers();
|
||||
}
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user