From 7b9685c3812afb74d1dfbfd111d751b210ef6ca9 Mon Sep 17 00:00:00 2001 From: nigel Date: Fri, 10 Jun 2022 21:06:20 +0200 Subject: [PATCH] Externalized ImGUI compilation and fixed white screen issue --- BarinkEngine/BarinkEngine.cpp | 4 +++ BarinkEngine/graphics/ModelImporter.cpp | 2 +- BarinkEngine/graphics/Renderable.cpp | 2 +- BarinkEngine/graphics/Shader.cpp | 8 ++--- BarinkEngine/graphics/shaders/fragment.shader | 5 +-- BarinkEngine/premake5.lua | 36 ++++++++++++------- ImGui/premake5.lua | 18 ++++++++++ SandboxApplication/Sandbox.cpp | 2 +- 8 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 ImGui/premake5.lua diff --git a/BarinkEngine/BarinkEngine.cpp b/BarinkEngine/BarinkEngine.cpp index 9c67a48..6fc3be5 100644 --- a/BarinkEngine/BarinkEngine.cpp +++ b/BarinkEngine/BarinkEngine.cpp @@ -19,10 +19,14 @@ int main(int argc, char* argv[]) { GUIManager GUISystem = GUIManager(&MainWindow); + glEnable(GL_DEPTH_TEST); + + // First call to setup game Start(); + // Runtime loop while (!MainWindow.WindowShouldClose()) { diff --git a/BarinkEngine/graphics/ModelImporter.cpp b/BarinkEngine/graphics/ModelImporter.cpp index 32c4306..e66528e 100644 --- a/BarinkEngine/graphics/ModelImporter.cpp +++ b/BarinkEngine/graphics/ModelImporter.cpp @@ -54,7 +54,7 @@ std::vector ModelImporter::Test() { //spdlog::info("======= Assimp ======"); Assimp::Importer importer; - const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs); + const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Models/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs); aiNode* currentNode = scene->mRootNode; diff --git a/BarinkEngine/graphics/Renderable.cpp b/BarinkEngine/graphics/Renderable.cpp index 3c1f4ce..5109edf 100644 --- a/BarinkEngine/graphics/Renderable.cpp +++ b/BarinkEngine/graphics/Renderable.cpp @@ -30,7 +30,7 @@ Renderable::Renderable() VAO.AttachAttribute(0, 3, sizeof(BarinkEngine::Vertex)); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void*) offsetof(BarinkEngine::Vertex, vertices)); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(BarinkEngine::Vertex),(void* )offsetof(BarinkEngine::Vertex, vertices)); glEnableVertexAttribArray(1); vertexBuffer.Unbind(false); diff --git a/BarinkEngine/graphics/Shader.cpp b/BarinkEngine/graphics/Shader.cpp index 4af6cff..3dff123 100644 --- a/BarinkEngine/graphics/Shader.cpp +++ b/BarinkEngine/graphics/Shader.cpp @@ -1,5 +1,5 @@ #include "Graphics/Shader.h" - +#include "spdlog/spdlog.h" Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath) { char infoLog[512]; @@ -15,7 +15,7 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha glGetShaderiv(vertId, GL_COMPILE_STATUS, &succes); if(!succes){ glGetShaderInfoLog(vertId, 512, NULL, infoLog); - //spdlog::error( "Vertex shader has compile error {}", infoLog); + spdlog::error( "Vertex shader has compile error {}", infoLog); return; } @@ -33,7 +33,7 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha glGetShaderiv(fragId, GL_COMPILE_STATUS, &succes); if(!succes){ glGetShaderInfoLog(fragId, 512, NULL, infoLog); - //spdlog::error("Fragment shader has compile error {}", infoLog); + spdlog::error("Fragment shader has compile error {}", infoLog); return; } @@ -63,7 +63,7 @@ char* Shader::readFile (const char* filePath){ file.open(filePath); if(file.is_open() == false){ - //spdlog::info("File not found."); + spdlog::info("File not found."); return nullptr; } diff --git a/BarinkEngine/graphics/shaders/fragment.shader b/BarinkEngine/graphics/shaders/fragment.shader index cbc28b1..8ffc39b 100644 --- a/BarinkEngine/graphics/shaders/fragment.shader +++ b/BarinkEngine/graphics/shaders/fragment.shader @@ -1,14 +1,11 @@ #version 440 core out vec4 FragColor; - uniform vec3 Color; - in vec2 TexCoord; - uniform sampler2D Texture; void main(){ - FragColor = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f)); + FragColor = mix ( texture(Texture, TexCoord), vec4(Color, 1.0f), 0.5f); } \ No newline at end of file diff --git a/BarinkEngine/premake5.lua b/BarinkEngine/premake5.lua index fb65dc6..45c6dc6 100644 --- a/BarinkEngine/premake5.lua +++ b/BarinkEngine/premake5.lua @@ -13,29 +13,43 @@ project "BarinkEngine" "../libs/physx/physx/include", "../libs/steam-audio/include", + "../libs/assimp/include", + + "../libs/glad/include", + "../libs/glfw/include", - -- "../libs/tinygltf", "../libs/glew/include", "../libs/glm", + "../libs/ImGui", + } + + links { + -- This needs to fall under the filter as the names can differ on different platforms + "phonon", + "lua54", + "spdlog", + "assimp-vc143-mtd", + "glfw3", + + "ImGUI_Opengl3", + + } + libdirs { "../libs/steam-audio/lib/windows-x64", "../libs/lua", "../libs/spdlog/build/Release", "../libs/assimp/lib/Debug", "../libs/glfw/build/src/Debug", - "../libs/ImGui" } files { - "../libs/ImGui/*.cpp", - "../libs/ImGui/backends/imgui_impl_glfw.cpp", - "../libs/ImGui/backends/imgui_impl_Opengl3.cpp", "../libs/glad/src/glad.c", "./*.cpp", @@ -45,6 +59,7 @@ project "BarinkEngine" } + filter { "system:windows"} prebuildcommands { -- Copy shaders @@ -54,14 +69,7 @@ project "BarinkEngine" "copy graphics\\shaders\\RenderSurfaceVert.shader ..\\build\\SandboxApplication\\Debug\\RenderSurface.vs" } - links { - -- This needs to fall under the filter as the names can differ on different platforms - "phonon", - "lua54", - "spdlog", - "assimp-vc143-mtd", - "glfw3" - } + filter { "system:linux" } prebuildcommands { @@ -71,3 +79,5 @@ project "BarinkEngine" "cp graphics/shaders/RenderSurfaceFrag.shader ../build/SandboxApplication/Debug/RenderSurface.fs", "cp graphics/shaders/RenderSurfaceVert.shader ../build/SandboxApplication/Debug/RenderSurface.vs" } + +include('../ImGui') diff --git a/ImGui/premake5.lua b/ImGui/premake5.lua new file mode 100644 index 0000000..e38530f --- /dev/null +++ b/ImGui/premake5.lua @@ -0,0 +1,18 @@ +project "ImGUI_Opengl3" + kind "StaticLib" + + includedirs { + "../libs/glfw/include", + "../libs/ImGui" + } + + files { + "../libs/ImGui/*.cpp", + "../libs/ImGui/backends/imgui_impl_glfw.cpp", + "../libs/ImGui/backends/imgui_impl_Opengl3.cpp", + } + + libdirs{ + "../libs/ImGui", + "../libs/glad" + } \ No newline at end of file diff --git a/SandboxApplication/Sandbox.cpp b/SandboxApplication/Sandbox.cpp index d116b8c..b52438f 100644 --- a/SandboxApplication/Sandbox.cpp +++ b/SandboxApplication/Sandbox.cpp @@ -58,7 +58,7 @@ void Start() { shader = new Shader(vertexShaderSource, fragmentShaderSource); - textureCube = new Texture("build/SandboxApplication/Debug/die.jpg"); + textureCube = new Texture("build/SandboxApplication/Debug/Textures/wall.jpg"); matCube = new Material(*shader); matCube->Color = glm::vec3(1.0, 0.0, 0.0);