2#include "editor/camera/movable/EditorCamera.h"
3#include "editor/camera/movable/OrthoCamera.h"
5#include "confs/Config.h"
6#include "inputs/InputHandler.h"
8#include "imgui/imgui/backends/imgui_impl_glfw.h"
9#include "imgui/imgui/backends/imgui_impl_opengl3.h"
10#include "imgui/imgui/imgui.h"
11#include "core/renderer/Renderer.h"
12#include "editor/gui/DockUI.h"
13#include "editor/Application.h"
14#include "core/ecs/ECS.h"
15#include "gui/SceneUI.h"
17#include "imguizmo/ImGuizmo.h"
18#include "common/maths/Vec.h"
20Window::Window(
int width,
int height,
const char* title)
29 std::cout <<
"GLFW failed to initialize!" << std::endl;
33 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
34 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
35 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
36 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
38 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
40 m_Window = glfwCreateWindow(m_Width, m_Height, m_Title, NULL, NULL);
41 glfwSetInputMode(m_Window, GLFW_STICKY_KEYS, 1);
49 glfwMakeContextCurrent(m_Window);
54 std::cout << glsl_version <<
"\n";
55 ImGui::CreateContext();
56 ImGui_ImplGlfw_InitForOpenGL(m_Window,
true);
57 ImGui_ImplOpenGL3_Init(glsl_version);
58 ImGui::StyleColorsDark();
59 ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_DockingEnable;
61 VividGUI::ImGuiThemeSetup();
66 if (s_Instance == NULL)
67 s_Instance =
new Window(width, height, title);
72void Window::Clear()
const
74 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
79 m_RenderingInterface = renderingInterface;
80 m_RenderingInterface->
Setup();
82 glfwGetWindowSize(m_Window, &m_Width, &m_Height);
88 glfwGetWindowSize(m_Window, &m_Width, &m_Height);
89 m_FrameBuffer->RescaleFrameBuffer(m_Width, m_Height);
94 glfwMakeContextCurrent(m_Window);
95 glfwSwapBuffers(m_Window);
97 glClear(GL_DEPTH_BUFFER_BIT);
98 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
100 Vivid::Renderer::Clear();
102 ImGui_ImplGlfw_NewFrame();
103 ImGui_ImplOpenGL3_NewFrame();
108 ImGuizmo::BeginFrame();
110 if (ImGui::Begin(
"Viewport"))
113 Camera* camera = Application::GetInstance()->GetCamera();
114 if (ImGui::IsWindowFocused())
117 if (m_RenderingInterface !=
nullptr)
126 movableCamera->MoveForward();
130 movableCamera->MoveBackward();
134 movableCamera->MoveLeft();
138 movableCamera->MoveRight();
144 movableCamera->ProcessMouseMovement(mousePosition.x - m_PrevMousePosition->x,
145 mousePosition.y - m_PrevMousePosition->y);
146 m_PrevMousePosition->x = mousePosition.x;
147 m_PrevMousePosition->y = mousePosition.y;
151 m_PrevMousePosition->x = mousePosition.x;
152 m_PrevMousePosition->y = mousePosition.y;
160 m_FrameBuffer->Bind();
161 if (m_RenderingInterface !=
nullptr)
163 m_RenderingInterface->
Draw();
166 Vivid::ECS::Draw(camera);
167 m_FrameBuffer->Unbind();
169 m_ViewportWidth = ImGui::GetContentRegionAvail().x;
170 m_ViewportHeight = ImGui::GetContentRegionAvail().y;
172 m_ViewportPosition =
Vivid::Maths::Vec2(ImGui::GetCursorScreenPos().x, ImGui::GetCursorScreenPos().y);
174 Application::GetInstance()->GetCamera()->SetViewportSize(m_ViewportWidth, m_ViewportHeight);
177 (ImTextureID)m_FrameBuffer->getFrameTexture(),
178 ImVec2(m_ViewportWidth, m_ViewportHeight),
183 VividGUI::SceneUI::DrawGizmo(camera);
189 if (m_RenderingInterface !=
nullptr)
195 VividGUI::SceneUI::DrawSceneUI();
201 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
203 m_FrameBuffer->Bind();
204 Vivid::Renderer::Clear();
206 GLCall(glClear(GL_DEPTH_BUFFER_BIT));
207 GLCall(glClearColor(1.0f, 1.0f, 1.0f, 1.0f));
208 m_FrameBuffer->Unbind();
A class that represents the camera.
A class for the EditorCamera.
Handles the creation and management of a frame buffer.
A class for the MovableCamera's.
A class for the OrthoCamera's.
RenderingInterface class.
virtual void Draw()=0
Draw function.
virtual void ImGuiRender()=0
ImGuiRender function.
virtual void Setup()=0
Setup function.
A class that represents a window and is wrapper of GLFWwindow.
void SetRenderingInterface(RenderingInterface *renderingInterface)
Sets the rendering interface.
static Window * Init(int width, int height, const char *title)
Initializes the window.