-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
194 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
set(ImGUI_LIB libimgui) | ||
file(GLOB_RECURSE HINA_GUI_SRC *.h *.cpp) | ||
add_library(HinaGUI ${HINA_GUI_SRC}) | ||
target_include_directories(HinaGUI PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) | ||
target_link_libraries(HinaGUI PRIVATE ${ImGUI_LIB}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef HINAGUI_DEFINES_H | ||
#define HINAGUI_DEFINES_H | ||
|
||
#define HINA_INLINE | ||
|
||
#endif //HINAGUI_DEFINES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include "Window.h" | ||
|
||
#include <utility> | ||
|
||
void Window::init(const std::string &window_name, int width, int height, int pos_x, int pos_y) | ||
{ | ||
init_opengl(window_name, width, height, pos_x, pos_y); | ||
init_imgui(); | ||
} | ||
|
||
void Window::kill() | ||
{ | ||
kill_imgui(); | ||
kill_opengl(); | ||
window_ = nullptr; | ||
} | ||
|
||
void Window::render() | ||
{ | ||
while (!glfwWindowShouldClose(window_)) | ||
{ | ||
if (glfwGetKey(window_, GLFW_KEY_ESCAPE) == GLFW_PRESS) | ||
glfwSetWindowShouldClose(window_, true); | ||
|
||
ImGui_ImplOpenGL3_NewFrame(); | ||
ImGui_ImplGlfw_NewFrame(); | ||
ImGui::NewFrame(); | ||
|
||
{ | ||
static float f = 0.0f; | ||
static int counter = 0; | ||
|
||
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. | ||
|
||
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) | ||
|
||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f | ||
|
||
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) | ||
counter++; | ||
ImGui::SameLine(); | ||
ImGui::Text("counter = %d", counter); | ||
|
||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); | ||
ImGui::End(); | ||
} | ||
|
||
ImGui::Render(); | ||
|
||
glClearColor(1.f, 1.f, 1.f, 1.f); | ||
glClear(GL_COLOR_BUFFER_BIT); | ||
|
||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); | ||
|
||
glfwSwapBuffers(window_); | ||
glfwPollEvents(); | ||
} | ||
} | ||
|
||
void Window::init_opengl(const std::string &window_name, int width, int height, int pos_x, int pos_y) | ||
{ | ||
glfwInit(); | ||
glfwWindowHint(GLFW_SAMPLES, 8); // MSAA samples | ||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | ||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); | ||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | ||
#ifdef __APPLE__ | ||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); | ||
#endif | ||
|
||
window_ = glfwCreateWindow(width, height, window_name.c_str(), nullptr, nullptr); | ||
glfwSetWindowPos(window_, pos_x, pos_y); | ||
glfwMakeContextCurrent(window_); | ||
|
||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress); | ||
} | ||
|
||
void Window::init_imgui() | ||
{ | ||
ImGui::CreateContext(); | ||
ImGuiIO &io = ImGui::GetIO(); | ||
(void) io; | ||
|
||
// Setup Dear ImGui style | ||
ImGui::StyleColorsLight(); | ||
ImGui_ImplGlfw_InitForOpenGL(window_, true); | ||
ImGui_ImplOpenGL3_Init("#version 330 core"); | ||
|
||
// TODO: Load Fonts | ||
} | ||
|
||
void Window::kill_opengl() | ||
{ | ||
glfwDestroyWindow(window_); | ||
glfwTerminate(); | ||
} | ||
|
||
void Window::kill_imgui() | ||
{ | ||
ImGui_ImplOpenGL3_Shutdown(); | ||
ImGui_ImplGlfw_Shutdown(); | ||
ImGui::DestroyContext(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef HINAGUI_WINDOW_H | ||
#define HINAGUI_WINDOW_H | ||
|
||
#include "glad/glad.h" | ||
#include "GLFW/glfw3.h" | ||
#include "imgui.h" | ||
#include "imgui_impl_glfw.h" | ||
#include "imgui_impl_opengl3.h" | ||
#include "implot.h" | ||
|
||
#include "../base/defines.h" | ||
|
||
#include <string> | ||
|
||
// default OpenGL backend window, TODO: support multi-backend | ||
class Window | ||
{ | ||
public: | ||
void init(const std::string &window_name, int width, int height, int pos_x = 0, int pos_y = 0); | ||
void render(); | ||
void kill(); | ||
|
||
protected: | ||
void init_opengl(const std::string &window_name, int width, int height, int pos_x = 0, int pos_y = 0); | ||
void init_imgui(); | ||
void kill_opengl(); | ||
void kill_imgui(); | ||
|
||
protected: | ||
GLFWwindow *window_ = nullptr; | ||
}; | ||
|
||
#endif //HINAGUI_WINDOW_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"pos_x": 1, | ||
"pos_y": 2, | ||
"width": 3, | ||
"height": 4 | ||
"name": "Hina Window", | ||
"width": 1024, | ||
"height": 768, | ||
"pos_x": 0, | ||
"pos_y": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters