mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Cleanup Window.h and Timestep.h
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class Timestep {
|
||||
class Timestep
|
||||
{
|
||||
private:
|
||||
float m_Time;
|
||||
|
||||
|
||||
@@ -1,49 +1,42 @@
|
||||
|
||||
#include <GL\glew.h>
|
||||
|
||||
#include "Window.h"
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "Rendering/Shaders/Shader.h"
|
||||
#include <imgui\imgui.h>
|
||||
#include "Rendering/Renderer.h"
|
||||
#include "Scene/Entities/Entity.h"
|
||||
#include <imgui\imgui_impl_glfw.h>
|
||||
#include <imgui\imgui_impl_opengl3.h>
|
||||
#include "Scene/Entities/ImGuiHelper.h"
|
||||
#include "Core/Physics/PhysicsManager.h"
|
||||
#include "imgui/ImGuizmo.h"
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "Engine.h"
|
||||
#include "src/Core/Maths.h"
|
||||
#include "src/Rendering/Renderer.h"
|
||||
#include "src/Rendering/Buffers/Framebuffer.h"
|
||||
#include "src/Scene/Scene.h"
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtx/matrix_decompose.hpp>
|
||||
#include "Resource/FontAwesome5.h"
|
||||
#include "Engine.h"
|
||||
#include <src/Scene/Components/InterfaceComponent.h>
|
||||
|
||||
namespace Nuake {
|
||||
Ref<Window> Window::s_Instance;
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_impl_glfw.h>
|
||||
#include <imgui/imgui_impl_opengl3.h>
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
Window::Window()
|
||||
{
|
||||
m_Title = DEFAULT_TITLE;
|
||||
m_Width = DEFAULT_WIDTH;
|
||||
m_Height = DEFAULT_HEIGHT;
|
||||
|
||||
Init();
|
||||
Renderer::Init();
|
||||
}
|
||||
|
||||
Window::~Window() { }
|
||||
|
||||
Ref<Window> Window::Get()
|
||||
{
|
||||
if (s_Instance == nullptr)
|
||||
s_Instance = CreateRef<Window>();
|
||||
static Ref<Window> instance;
|
||||
if (instance == nullptr)
|
||||
{
|
||||
instance = CreateRef<Window>();
|
||||
}
|
||||
|
||||
return s_Instance;
|
||||
}
|
||||
|
||||
bool Window::ShouldClose()
|
||||
{
|
||||
return glfwWindowShouldClose(m_Window);
|
||||
return instance;
|
||||
}
|
||||
|
||||
GLFWwindow* Window::GetHandle()
|
||||
@@ -51,26 +44,118 @@ namespace Nuake {
|
||||
return m_Window;
|
||||
}
|
||||
|
||||
bool Window::SetScene(Ref<Scene> scene)
|
||||
bool Window::ShouldClose()
|
||||
{
|
||||
m_Scene = scene;
|
||||
return true;
|
||||
return glfwWindowShouldClose(m_Window);
|
||||
}
|
||||
|
||||
Ref<Scene> Window::GetScene()
|
||||
int Window::Init()
|
||||
{
|
||||
return m_Scene;
|
||||
if (!glfwInit())
|
||||
{
|
||||
Logger::Log("glfw initialization failed.", CRITICAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
m_Window = glfwCreateWindow(m_Width, m_Height, m_Title.c_str(), NULL, NULL);
|
||||
if (!m_Window)
|
||||
{
|
||||
Logger::Log("Window creation failed.", CRITICAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SetWindowIcon("resources/Images/nuake-logo.png");
|
||||
|
||||
glfwMakeContextCurrent(m_Window);
|
||||
SetVSync(0);
|
||||
|
||||
Logger::Log((char*)glGetString(GL_VERSION));
|
||||
|
||||
if (glewInit() != GLEW_OK)
|
||||
{
|
||||
Logger::Log("GLEW initialization failed!", CRITICAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO: Move this to renderer init. The window shouldnt have to do gl calls.
|
||||
glfwWindowHint(GLFW_SAMPLES, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
// TODO: have clear color in environnement.
|
||||
glClearColor(0.f, 0.f, 0.f, 1.0f);
|
||||
|
||||
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glEnable(GL_CULL_FACE);
|
||||
|
||||
// Create viewports
|
||||
m_Framebuffer = CreateRef<FrameBuffer>(true, glm::vec2(1920, 1080));
|
||||
m_Framebuffer->SetTexture(CreateRef<Texture>(glm::vec2(1920, 1080), GL_RGB));
|
||||
|
||||
InitImgui();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Window::SetTitle(const std::string& title)
|
||||
void Window::Update(Timestep ts)
|
||||
{
|
||||
m_Title = title;
|
||||
glfwSetWindowTitle(m_Window, m_Title.c_str());
|
||||
m_Scene->Update(ts);
|
||||
}
|
||||
|
||||
std::string Window::GetTitle()
|
||||
void Window::FixedUpdate(Timestep ts)
|
||||
{
|
||||
return m_Title;
|
||||
m_Scene->FixedUpdate(ts);
|
||||
}
|
||||
|
||||
void Window::Draw()
|
||||
{
|
||||
// Dont render if no scene is loaded.
|
||||
if (!m_Scene)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Dont render if no cam is found.
|
||||
Ref<Camera> cam = m_Scene->GetCurrentCamera();
|
||||
if (!cam)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// We cannot render to a framebuffer that is smaller than 1x1.
|
||||
Vector2 size = m_Framebuffer->GetSize();
|
||||
size.x = std::max(size.x, 1.0f);
|
||||
size.y = std::max(size.y, 1.0f);
|
||||
|
||||
cam->AspectRatio = size.x / size.y;
|
||||
|
||||
m_Scene->m_EditorCamera->OnWindowResize(size.x, size.y);
|
||||
|
||||
if (Engine::IsPlayMode())
|
||||
{
|
||||
m_Scene->Draw(*m_Framebuffer.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Scene->Draw(*m_Framebuffer.get(), m_Scene->m_EditorCamera->GetPerspective(), m_Scene->m_EditorCamera->GetTransform());
|
||||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
Renderer::EndDraw();
|
||||
}
|
||||
|
||||
void Window::EndDraw()
|
||||
{
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
glfwSwapBuffers(m_Window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
Ref<FrameBuffer> Window::GetFrameBuffer() const
|
||||
@@ -105,206 +190,128 @@ namespace Nuake {
|
||||
}
|
||||
}
|
||||
|
||||
int Window::Init()
|
||||
Ref<Scene> Window::GetScene()
|
||||
{
|
||||
if (!glfwInit())
|
||||
{
|
||||
Logger::Log("glfw initialization failed.", CRITICAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
{ // Create window
|
||||
m_Window = glfwCreateWindow(m_Width, m_Height, m_Title.c_str(), NULL, NULL);
|
||||
|
||||
if (!m_Window)
|
||||
{
|
||||
Logger::Log("Window creation failed.", CRITICAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
GLFWimage images[1];
|
||||
images[0].pixels = stbi_load("resources/Images/nuake-logo.png", &images[0].width, &images[0].height, 0, 4); //rgba channels
|
||||
glfwSetWindowIcon(m_Window, 1, images);
|
||||
stbi_image_free(images[0].pixels);
|
||||
|
||||
glfwMakeContextCurrent(m_Window);
|
||||
|
||||
glfwSwapInterval(1);
|
||||
|
||||
Logger::Log((char*)glGetString(GL_VERSION));
|
||||
|
||||
if (glewInit() != GLEW_OK)
|
||||
{
|
||||
Logger::Log("GLEW initialization failed!", CRITICAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO: Move this to renderer init. The window shouldnt have to do gl calls.
|
||||
glfwWindowHint(GLFW_SAMPLES, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
// TODO: have clear color in environnement.
|
||||
glClearColor(0.f, 0.f, 0.f, 1.0f);
|
||||
|
||||
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
// Create viewports
|
||||
m_Framebuffer = CreateRef<FrameBuffer>(true, glm::vec2(1920, 1080));
|
||||
m_Framebuffer->SetTexture(CreateRef<Texture>(glm::vec2(1920, 1080), GL_RGB));
|
||||
|
||||
// ImGui init
|
||||
{
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
//io.Fonts->AddFontDefault();
|
||||
io.Fonts->AddFontFromFileTTF("resources/Fonts/OpenSans-Regular.ttf", 16.0);
|
||||
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGuiStyle& s = ImGui::GetStyle();
|
||||
s.FrameRounding = 2.0f;
|
||||
s.GrabRounding = 2.0f;
|
||||
s.CellPadding = ImVec2(8, 8);
|
||||
s.WindowPadding = ImVec2(8, 8);
|
||||
s.ScrollbarRounding = 9.0f;
|
||||
s.TabRounding = 0;
|
||||
s.WindowRounding = 0;
|
||||
s.ChildRounding = 0;
|
||||
s.FrameRounding = 0;
|
||||
s.GrabRounding = 0;
|
||||
s.FramePadding = ImVec2(8, 4);
|
||||
s.ItemSpacing = ImVec2(8, 4);
|
||||
s.ItemInnerSpacing = ImVec2(4, 4);
|
||||
s.TabRounding = 4.0f;
|
||||
s.WindowBorderSize = 0.0f;
|
||||
s.ChildBorderSize = 0.0f;
|
||||
|
||||
ImVec4* colors = ImGui::GetStyle().Colors;
|
||||
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
|
||||
colors[ImGuiCol_WindowBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_ChildBg] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
|
||||
colors[ImGuiCol_Border] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
|
||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_FrameBg] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.09f, 0.09f, 0.09f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f);
|
||||
colors[ImGuiCol_TitleBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
|
||||
colors[ImGuiCol_MenuBarBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.34f, 0.34f, 0.34f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.29f, 0.29f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
|
||||
colors[ImGuiCol_CheckMark] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrab] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_Button] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
|
||||
colors[ImGuiCol_ButtonHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
|
||||
colors[ImGuiCol_ButtonActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
|
||||
colors[ImGuiCol_Header] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f);
|
||||
colors[ImGuiCol_HeaderHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
|
||||
colors[ImGuiCol_HeaderActive] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
|
||||
colors[ImGuiCol_Separator] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.10f, 0.10f, 0.78f);
|
||||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
|
||||
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
|
||||
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
|
||||
colors[ImGuiCol_Tab] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_TabHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
|
||||
colors[ImGuiCol_TabActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocused] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_DockingPreview] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
|
||||
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
|
||||
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
|
||||
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
|
||||
colors[ImGuiCol_TableBorderLight] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
|
||||
colors[ImGuiCol_TableRowBg] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
|
||||
colors[ImGuiCol_TableRowBgAlt] = ImVec4(0.93f, 0.27f, 0.27f, 0.00f);
|
||||
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.08f, 0.49f, 0.97f, 0.28f);
|
||||
colors[ImGuiCol_DragDropTarget] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
|
||||
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
|
||||
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
|
||||
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(m_Window, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 330");
|
||||
}
|
||||
|
||||
return 0;
|
||||
return m_Scene;
|
||||
}
|
||||
|
||||
void Window::Update(Timestep ts)
|
||||
bool Window::SetScene(Ref<Scene> scene)
|
||||
{
|
||||
m_Scene->Update(ts);
|
||||
m_Scene = scene;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Window::FixedUpdate(Timestep ts)
|
||||
void Window::SetTitle(const std::string& title)
|
||||
{
|
||||
m_Scene->FixedUpdate(ts);
|
||||
m_Title = title;
|
||||
glfwSetWindowTitle(m_Window, m_Title.c_str());
|
||||
}
|
||||
|
||||
void Window::Draw()
|
||||
std::string Window::GetTitle()
|
||||
{
|
||||
// Dont render if no scene is loaded.
|
||||
if (!m_Scene)
|
||||
return;
|
||||
|
||||
// Dont render if no cam is found.
|
||||
Ref<Camera> cam = m_Scene->GetCurrentCamera();
|
||||
if (!cam)
|
||||
return;
|
||||
|
||||
Vector2 size = m_Framebuffer->GetSize();
|
||||
|
||||
if (size.x < 1 || size.y < 1)
|
||||
{
|
||||
size.x = 1.0;
|
||||
size.y = 1.0;
|
||||
}
|
||||
|
||||
cam->AspectRatio = size.x / size.y;
|
||||
m_Scene->m_EditorCamera->OnWindowResize(size.x, size.y);
|
||||
|
||||
if (Engine::IsPlayMode)
|
||||
{
|
||||
m_Scene->Draw(*m_Framebuffer.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Scene->Draw(*m_Framebuffer.get(), m_Scene->m_EditorCamera->GetPerspective(), m_Scene->m_EditorCamera->GetTransform());
|
||||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
Renderer::EndDraw();
|
||||
return m_Title;
|
||||
}
|
||||
|
||||
void Window::SetWindowIcon(const std::string& path)
|
||||
{
|
||||
GLFWimage images[1];
|
||||
images[0].pixels = stbi_load("resources/Images/nuake-logo.png", &images[0].width, &images[0].height, 0, 4); //rgba channels
|
||||
glfwSetWindowIcon(m_Window, 1, images);
|
||||
stbi_image_free(images[0].pixels);
|
||||
}
|
||||
|
||||
void Window::EndDraw()
|
||||
void Window::SetVSync(bool enabled)
|
||||
{
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
glfwSwapBuffers(m_Window);
|
||||
glfwPollEvents();
|
||||
glfwSwapInterval(enabled ? 0 : 1);
|
||||
}
|
||||
|
||||
void Window::InitImgui()
|
||||
{
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
//io.Fonts->AddFontDefault();
|
||||
io.Fonts->AddFontFromFileTTF("resources/Fonts/OpenSans-Regular.ttf", 16.0);
|
||||
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGuiStyle& s = ImGui::GetStyle();
|
||||
s.FrameRounding = 2.0f;
|
||||
s.GrabRounding = 2.0f;
|
||||
s.CellPadding = ImVec2(8, 8);
|
||||
s.WindowPadding = ImVec2(8, 8);
|
||||
s.ScrollbarRounding = 9.0f;
|
||||
s.TabRounding = 0;
|
||||
s.WindowRounding = 0;
|
||||
s.ChildRounding = 0;
|
||||
s.FrameRounding = 0;
|
||||
s.GrabRounding = 0;
|
||||
s.FramePadding = ImVec2(8, 4);
|
||||
s.ItemSpacing = ImVec2(8, 4);
|
||||
s.ItemInnerSpacing = ImVec2(4, 4);
|
||||
s.TabRounding = 4.0f;
|
||||
s.WindowBorderSize = 0.0f;
|
||||
s.ChildBorderSize = 0.0f;
|
||||
|
||||
ImVec4* colors = ImGui::GetStyle().Colors;
|
||||
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
|
||||
colors[ImGuiCol_WindowBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_ChildBg] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
|
||||
colors[ImGuiCol_Border] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
|
||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[ImGuiCol_FrameBg] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.09f, 0.09f, 0.09f, 1.00f);
|
||||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.13f, 0.13f, 0.13f, 1.00f);
|
||||
colors[ImGuiCol_TitleBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
|
||||
colors[ImGuiCol_MenuBarBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.34f, 0.34f, 0.34f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.29f, 0.29f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
|
||||
colors[ImGuiCol_CheckMark] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrab] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_Button] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
|
||||
colors[ImGuiCol_ButtonHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
|
||||
colors[ImGuiCol_ButtonActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
|
||||
colors[ImGuiCol_Header] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f);
|
||||
colors[ImGuiCol_HeaderHovered] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f);
|
||||
colors[ImGuiCol_HeaderActive] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
|
||||
colors[ImGuiCol_Separator] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.10f, 0.10f, 0.78f);
|
||||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
|
||||
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
|
||||
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.00f);
|
||||
colors[ImGuiCol_Tab] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_TabHovered] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
|
||||
colors[ImGuiCol_TabActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocused] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
|
||||
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
||||
colors[ImGuiCol_DockingPreview] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
|
||||
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
|
||||
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
||||
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.19f, 1.00f);
|
||||
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
|
||||
colors[ImGuiCol_TableBorderLight] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
|
||||
colors[ImGuiCol_TableRowBg] = ImVec4(0.11f, 0.11f, 0.11f, 1.00f);
|
||||
colors[ImGuiCol_TableRowBgAlt] = ImVec4(0.93f, 0.27f, 0.27f, 0.00f);
|
||||
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.08f, 0.49f, 0.97f, 0.28f);
|
||||
colors[ImGuiCol_DragDropTarget] = ImVec4(0.55f, 0.76f, 0.29f, 1.00f);
|
||||
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
|
||||
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
|
||||
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(m_Window, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 330");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
#pragma once
|
||||
#include "Core/Timestep.h"
|
||||
#include "Rendering/Buffers/Framebuffer.h"
|
||||
#include "Scene/Scene.h"
|
||||
#include "Core/Core.h"
|
||||
#include "Core/Timestep.h"
|
||||
#include "Core/Maths.h"
|
||||
|
||||
struct GLFWwindow;
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class Scene;
|
||||
class FrameBuffer;
|
||||
|
||||
class Window
|
||||
{
|
||||
private:
|
||||
const std::string DEFAULT_TITLE = "Untitled Window";
|
||||
|
||||
static Ref<Window> s_Instance;
|
||||
|
||||
std::string m_Title;
|
||||
int m_Width = 1280;
|
||||
int m_Height = 720;
|
||||
const uint32_t DEFAULT_WIDTH = 1280;
|
||||
const uint32_t DEFAULT_HEIGHT = 720;
|
||||
|
||||
GLFWwindow* m_Window;
|
||||
|
||||
std::string m_Title;
|
||||
uint32_t m_Width;
|
||||
uint32_t m_Height;
|
||||
|
||||
Ref<FrameBuffer> m_Framebuffer;
|
||||
|
||||
Ref<Scene> m_Scene;
|
||||
Vector2 m_FramebufferOffset;
|
||||
|
||||
|
||||
public:
|
||||
Window();
|
||||
~Window();
|
||||
~Window() = default;
|
||||
|
||||
static Ref<Window> Get(); // Get the window instance
|
||||
GLFWwindow* GetHandle();
|
||||
@@ -36,12 +36,15 @@ namespace Nuake
|
||||
bool ShouldClose();
|
||||
|
||||
int Init();
|
||||
|
||||
void Update(Timestep ts);
|
||||
void FixedUpdate(Timestep ts);
|
||||
|
||||
void Draw();
|
||||
void EndDraw();
|
||||
|
||||
Ref<FrameBuffer> GetFrameBuffer() const;
|
||||
|
||||
Vector2 GetSize() const;
|
||||
void SetSize(const Vector2& size);
|
||||
|
||||
@@ -52,6 +55,11 @@ namespace Nuake
|
||||
|
||||
void SetTitle(const std::string& title);
|
||||
std::string GetTitle();
|
||||
|
||||
void SetWindowIcon(const std::string& path);
|
||||
void SetVSync(bool enabled);
|
||||
|
||||
private:
|
||||
void InitImgui();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user