1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-26 12:18:51 -05:00

Added very barebones renderer to facilitate clearing and setting the background. Added ImPlot for the desired plotting functionality.

This commit is contained in:
Gordon McCann 2021-12-20 15:23:17 -05:00
parent e7ae9301e4
commit 7001ef21a4
14 changed files with 136 additions and 3 deletions

3
.gitmodules vendored
View File

@ -8,3 +8,6 @@
[submodule "Navigator/vendor/glfw"] [submodule "Navigator/vendor/glfw"]
path = Navigator/vendor/glfw path = Navigator/vendor/glfw
url = https://github.com/gwm17/glfw.git url = https://github.com/gwm17/glfw.git
[submodule "Navigator/vendor/implot"]
path = Navigator/vendor/implot
url = https://github.com/gwm17/implot.git

View File

@ -1,4 +1,6 @@
#include "Application.h" #include "Application.h"
#include "Renderer/Renderer.h"
#include "Renderer/RenderCommand.h"
namespace Navigator { namespace Navigator {
@ -57,6 +59,9 @@ namespace Navigator {
while(m_runFlag) while(m_runFlag)
{ {
RenderCommand::SetClearColor(m_bckgnd_color);
RenderCommand::Clear();
for(auto layer : m_stack) for(auto layer : m_stack)
layer->OnUpdate(); layer->OnUpdate();

View File

@ -35,6 +35,8 @@ namespace Navigator {
ImGuiLayer* m_imgui_layer; ImGuiLayer* m_imgui_layer;
bool m_runFlag; bool m_runFlag;
float m_bckgnd_color[4] = {0.1, 0.1, 0.1, 1.0};
static Application* s_instance; static Application* s_instance;
}; };

View File

@ -3,6 +3,7 @@
#include "Navigator/NavCore.h" #include "Navigator/NavCore.h"
#include "imgui.h" #include "imgui.h"
#include "implot.h"
#include "backends/imgui_impl_opengl3.h" #include "backends/imgui_impl_opengl3.h"
#include "backends/imgui_impl_glfw.h" #include "backends/imgui_impl_glfw.h"
@ -23,7 +24,11 @@ namespace Navigator {
void ImGuiLayer::OnAttach() void ImGuiLayer::OnAttach()
{ {
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
NAV_INFO("Creating ImGui Context...");
ImGui::CreateContext(); ImGui::CreateContext();
ImPlot::CreateContext();
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
@ -45,12 +50,15 @@ namespace Navigator {
ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 410"); ImGui_ImplOpenGL3_Init("#version 410");
NAV_INFO("ImGui Finished initializing.");
} }
void ImGuiLayer::OnDetach() void ImGuiLayer::OnDetach()
{ {
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown(); ImGui_ImplGlfw_Shutdown();
ImPlot::DestroyContext();
ImGui::DestroyContext(); ImGui::DestroyContext();
} }
@ -86,5 +94,6 @@ namespace Navigator {
{ {
static bool show = true; static bool show = true;
ImGui::ShowDemoWindow(&show); ImGui::ShowDemoWindow(&show);
ImPlot::ShowDemoWindow();
} }
} }

View File

@ -0,0 +1,6 @@
#include "RenderCommand.h"
#include "Platform/OpenGL/OpenGLRendererAPI.h"
namespace Navigator {
RendererAPI* RenderCommand::s_api = new OpenGLRendererAPI();
}

View File

@ -0,0 +1,19 @@
#ifndef RENDER_COMMAND_H
#define RENDER_COMMAND_H
#include "RendererAPI.h"
namespace Navigator {
class RenderCommand
{
public:
inline static void SetClearColor(const float* color_array) { s_api->SetClearColor(color_array); }
inline static void Clear() { s_api->Clear(); }
private:
static RendererAPI* s_api;
};
}
#endif

View File

@ -0,0 +1,18 @@
#ifndef RENDERER_H
#define RENDERER_H
#include "RendererAPI.h"
#include "RenderCommand.h"
namespace Navigator {
class Renderer
{
public:
static inline RendererAPI::API GetAPI() { return RendererAPI::GetAPI(); }
};
}
#endif

View File

@ -0,0 +1,5 @@
#include "RendererAPI.h"
namespace Navigator {
RendererAPI::API RendererAPI::s_api = RendererAPI::API::OpenGL;
}

View File

@ -0,0 +1,26 @@
#ifndef RENDERER_API_H
#define RENDERER_API_H
namespace Navigator {
class RendererAPI
{
public:
enum class API
{
None = 0,
OpenGL = 1
};
virtual void Clear() = 0;
virtual void SetClearColor(const float* color_array) = 0;
inline static API GetAPI() { return s_api; }
private:
static API s_api;
};
}
#endif

View File

@ -0,0 +1,17 @@
#include "OpenGLRendererAPI.h"
#include "glad/glad.h"
namespace Navigator {
void OpenGLRendererAPI::Clear()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void OpenGLRendererAPI::SetClearColor(const float* color_array)
{
glClearColor(color_array[0], color_array[1], color_array[2], color_array[3]);
}
}

View File

@ -0,0 +1,17 @@
#ifndef OPENGL_RENDERER_API_H
#define OPENGL_RENDERER_API_H
#include "Navigator/Renderer/RendererAPI.h"
namespace Navigator {
class OpenGLRendererAPI : public RendererAPI
{
public:
virtual void Clear() override;
virtual void SetClearColor(const float* color_array) override;
};
}
#endif

1
Navigator/vendor/implot vendored Submodule

@ -0,0 +1 @@
Subproject commit 4fcc6e01aca406ef17d5a2dabdcbc9e1bd962c0d

View File

@ -7,6 +7,6 @@
], ],
"settings": "settings":
{ {
"SublimeLinter.linters.g++.args": ["-c","-Wall","-fsyntax-only","-std=c++17","-include${folder}/Navigator/src/navpch.h","-INavigator/src/", "-INavigator/src/Navigator/","-INavigator/vendor/spdlog/include", "-INavigator/vendor/glfw/include/","-INavigator/vendor/glad/include","-INavigator/vendor/imgui"] "SublimeLinter.linters.g++.args": ["-c","-Wall","-fsyntax-only","-std=c++17","-include${folder}/Navigator/src/navpch.h","-INavigator/src/", "-INavigator/src/Navigator/","-INavigator/vendor/spdlog/include", "-INavigator/vendor/glfw/include/","-INavigator/vendor/glad/include","-INavigator/vendor/imgui","-INavigator/vendor/implot"]
} }
} }

View File

@ -14,6 +14,7 @@ IncludeDirs ={}
IncludeDirs["glfw"] = "Navigator/vendor/glfw/include" IncludeDirs["glfw"] = "Navigator/vendor/glfw/include"
IncludeDirs["ImGui"] = "Navigator/vendor/imgui" IncludeDirs["ImGui"] = "Navigator/vendor/imgui"
IncludeDirs["glad"] = "Navigator/vendor/glad/include" IncludeDirs["glad"] = "Navigator/vendor/glad/include"
IncludeDirs["ImPlot"] = "Navigator/vendor/implot"
include "Navigator/vendor/glfw" include "Navigator/vendor/glfw"
include "Navigator/vendor/imgui" include "Navigator/vendor/imgui"
@ -41,14 +42,17 @@ project "Navigator"
"%{prj.name}/vendor/spdlog/include/", "%{prj.name}/vendor/spdlog/include/",
"%{IncludeDirs.glfw}", "%{IncludeDirs.glfw}",
"%{IncludeDirs.ImGui}", "%{IncludeDirs.ImGui}",
"%{IncludeDirs.glad}" "%{IncludeDirs.glad}",
"%{IncludeDirs.ImPlot}"
} }
filter {} filter {}
files { files {
"%{prj.name}/src/**.h", "%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp" "%{prj.name}/vendor/implot/*.h",
"%{prj.name}/src/**.cpp",
"%{prj.name}/vendor/implot/*.cpp"
} }
defines { defines {
@ -116,6 +120,7 @@ project "NavProject"
"Navigator/src", "Navigator/src",
"Navigator/src/Navigator", "Navigator/src/Navigator",
"Navigator/vendor/spdlog/include/", "Navigator/vendor/spdlog/include/",
"Navigator/vendor/implot/",
"Navigator/vendor" "Navigator/vendor"
} }