aboutsummaryrefslogtreecommitdiff
path: root/app/source/Cplt/Entrypoint/Backend_OpenGL2.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-06-30 23:47:26 -0700
committerrtk0c <[email protected]>2022-06-30 23:47:26 -0700
commitb01ed99a1cd0c863c8709930658513c04dd70f61 (patch)
tree37865c7683c3c39e69de3dd9798c5bcacb250d99 /app/source/Cplt/Entrypoint/Backend_OpenGL2.cpp
parent68b2695ee31504908122b48a5d36b77a9c983799 (diff)
Rename Entrypoint/ to ImGuiBackend/ for accuracy
Diffstat (limited to 'app/source/Cplt/Entrypoint/Backend_OpenGL2.cpp')
-rw-r--r--app/source/Cplt/Entrypoint/Backend_OpenGL2.cpp106
1 files changed, 0 insertions, 106 deletions
diff --git a/app/source/Cplt/Entrypoint/Backend_OpenGL2.cpp b/app/source/Cplt/Entrypoint/Backend_OpenGL2.cpp
deleted file mode 100644
index 0f20997..0000000
--- a/app/source/Cplt/Entrypoint/Backend_OpenGL2.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-#include <Cplt/Entrypoint/Backend.hpp>
-
-#if BUILD_CORE_WITH_OPENGL2_BACKEND
-# include <glad/glad.h>
-
-# include <GLFW/glfw3.h>
-# include <backend/imgui_impl_glfw.h>
-# include <backend/imgui_impl_opengl2.h>
-# include <imgui.h>
-# include <stdexcept>
-# include <iostream>
-
-# define IMGUI_IMPL_OPENGL_LOADER_CUSTOM
-# include <backend/imgui_impl_opengl2.cpp>
-
-class OpenGL2Backend : public RenderingBackend
-{
-private:
- GLFWwindow* mWindow;
-
-public:
- OpenGL2Backend()
- {
- glfwSetErrorCallback(&GlfwErrorCallback);
- if (!glfwInit()) {
- throw std::runtime_error("Failed to initialize GLFW.");
- }
-
- mWindow = glfwCreateWindow(1280, 720, "Cplt", nullptr, nullptr);
- if (mWindow == nullptr) {
- throw std::runtime_error("Failed to create GLFW window.");
- }
- glfwMakeContextCurrent(mWindow);
- glfwSwapInterval(1); // Enable vsync
-
- if (gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) == 0) {
- throw std::runtime_error("Failed to initialize OpenGL.");
- }
-
- IMGUI_CHECKVERSION();
- ImGui::CreateContext();
-
- ImGui_ImplGlfw_InitForOpenGL(mWindow, true);
- ImGui_ImplOpenGL2_Init();
- }
-
- virtual ~OpenGL2Backend()
- {
- ImGui_ImplOpenGL2_Shutdown();
- ImGui_ImplGlfw_Shutdown();
- ImGui::DestroyContext();
-
- glfwDestroyWindow(mWindow);
- glfwTerminate();
- }
-
- virtual void RunUntilWindowClose(void (*windowContent)())
- {
- while (!glfwWindowShouldClose(mWindow)) {
- glfwPollEvents();
-
- ImGui_ImplOpenGL2_NewFrame();
- ImGui_ImplGlfw_NewFrame();
- ImGui::NewFrame();
-
- windowContent();
-
- int displayWidth, displayHeight;
- glfwGetFramebufferSize(mWindow, &displayWidth, &displayHeight);
- glViewport(0, 0, displayWidth, displayHeight);
-
- const ImVec4 kClearColor = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
- glClearColor(kClearColor.x * kClearColor.w, kClearColor.y * kClearColor.w, kClearColor.z * kClearColor.w, kClearColor.w);
- glClear(GL_COLOR_BUFFER_BIT);
-
- ImGui::Render();
- ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
-
- glfwMakeContextCurrent(mWindow);
- glfwSwapBuffers(mWindow);
- }
- }
-
- static void GlfwErrorCallback(int errorCode, const char* message)
- {
- std::cerr << "GLFW Error " << errorCode << ": " << message << "\n";
- }
-};
-
-std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL2Backend()
-{
- try {
- return std::make_unique<OpenGL2Backend>();
- } catch (std::exception& e) {
- return nullptr;
- }
-}
-
-#else // ^^ BUILD_CORE_WITH_OPENGL2_BACKEND | !BUILD_CORE_WITH_OPENGL2_BACKEND vv
-
-std::unique_ptr<RenderingBackend> RenderingBackend::CreateOpenGL2Backend()
-{
- return nullptr;
-}
-
-#endif