Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
Window.cpp
Go to the documentation of this file.
2 #include "Engine/engine.hpp"
6 
7 #ifdef USING_VULKAN
9 #endif
10 
11 void error_callback(int error, const char* description)
12 {
13  eastl::string errorcallback = "Error: ";
14  errorcallback.append(description);
15 
16  debug_error("Window", "Error_callback", errorcallback);
17 }
18 
20  void operator()(GLFWwindow* ptr) const
21  {
22  glfwDestroyWindow(ptr);
23  }
24 };
25 
26 namespace Engine
27 {
28  //TODO -- Feiko | allow this callback to be virtual
29  void Window::OnWindowResized(GLFWwindow* window, int width, int height)
30  {
31  if (width == 0 || height == 0) return;
32 
33  Engine::GetEngine().lock()->GetWindow().lock()->SetWidth(width);
34  Engine::GetEngine().lock()->GetWindow().lock()->SetHeight(height);
35 
36  int display_w, display_h;
37  glfwGetFramebufferSize(Engine::GetEngine().lock()->GetWindow().lock()->GetGLFWWindow().lock().get(), &display_w, &display_h);
38  Engine::GetEngine().lock()->GetWindow().lock()->displayWidth = display_w;
39  Engine::GetEngine().lock()->GetWindow().lock()->displayHeight = display_h;
40 
41  // Update display size for gainput
42  Engine::GetEngine().lock()->GetInputManager().lock()->GetInputManager().SetDisplaySize(width, height);
43 
44  ImGuiIO& io = ImGui::GetIO();
45  io.DisplaySize = ImVec2(float(width), float(height));
46  io.DisplayFramebufferScale = ImVec2(width > 0 ? (float(display_w) / width) : 0, height > 0 ? (float(display_h) / height) : 0);
47 
48 #ifdef USING_VULKAN
49  Engine::GetEngine().lock()->GetRenderer<VulkanRenderer>().lock()->Resized();
50 #endif
51  }
52 
53  bool Window::ShouldClose() const noexcept
54  {
55  if (window != nullptr)
56  return glfwWindowShouldClose(window.get());
57  return true;
58  }
59 
60  void Window::SetShouldClose(bool value) const noexcept
61  {
62  if (window != nullptr)
63  glfwSetWindowShouldClose(window.get(), int(value));
64  }
65 
66  HWND Window::GetWindowHandle() const noexcept
67  {
68  return glfwGetWin32Window(window.get());
69  }
70 
71  eastl::weak_ptr<GLFWwindow> Window::GetGLFWWindow() const noexcept
72  {
73  return window;
74  }
75 
76  eastl::string Window::GetTitle() const
77  {
78  return title;
79  }
80 
81  int Window::GetWidth() const noexcept
82  {
83  return width;
84  }
85 
86  int Window::GetDisplayWidth() const noexcept
87  {
88  return displayWidth;
89  }
90 
91  int Window::GetHeight() const noexcept
92  {
93  return height;
94  }
95 
96  int Window::GetDisplayHeight() const noexcept
97  {
98  return displayHeight;
99  }
100 
101  Window::Window(int width, int height, const char* title) noexcept : width(width), height(height), title(title)
102  {
103  glfwSetErrorCallback(error_callback);
104  if (!glfwInit())
105  {
106  glfwTerminate();
107  exit(EXIT_FAILURE);
108  }
109 
110  glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
111  window = eastl::unique_ptr<GLFWwindow, DestroyglfwWin>(glfwCreateWindow(width, height, title, nullptr, nullptr));
112 
113  if (!window)
114  {
115  glfwTerminate();
116  exit(EXIT_FAILURE);
117  }
118 
119  glfwGetFramebufferSize(window.get(), &displayWidth, &displayHeight);
120 
121  glfwSetWindowSizeCallback(window.get(), OnWindowResized);
122 
123 
124  ImGuiIO& io = ImGui::GetIO();
125  io.DisplaySize = ImVec2(float(width), float(height));
126  io.DisplayFramebufferScale = ImVec2(width > 0 ? (float(displayWidth) / width) : 0, height > 0 ? (float(displayHeight) / height) : 0);
127  }
128 
129  Window::~Window() noexcept
130  {
131  glfwDestroyWindow(window.get());
132  glfwTerminate();
133  }
134 
135  void Window::Update() const noexcept
136  {
137  }
138 
139  void Window::SwapBuffers() const noexcept
140  {
141  glfwSwapBuffers(window.get());
142  }
143 
144  void Window::SetWidth(int newWidth)
145  {
146  width = newWidth;
147  }
148 
149  void Window::SetHeight(int newHeight)
150  {
151  height = newHeight;
152  }
153 
154 } //namespace Engine
Definition: imgui.h:96
ImVec2 DisplaySize
Definition: imgui.h:783
#define debug_error(debug_class, function, value)
This functions logs a debug error to the log and console. This does not halt the program! ...
Definition: Logging.hpp:30
IMGUI_API ImGuiIO & GetIO()
Definition: imgui.cpp:2144
void error_callback(int error, const char *description)
Definition: Window.cpp:11
Definition: imgui.h:777
ImVec2 DisplayFramebufferScale
Definition: imgui.h:800
void operator()(GLFWwindow *ptr) const
Definition: Window.cpp:20