aboutsummaryrefslogtreecommitdiff
path: root/dxwindow/dxwindow.ixx
diff options
context:
space:
mode:
authorMarc Sunet <marc.sunet@amd.com>2025-11-21 09:41:06 -0800
committerMarc Sunet <marc.sunet@amd.com>2025-11-21 09:41:06 -0800
commit0b5491e0a2f1a9a4023e2c4eb171287bede41388 (patch)
treee82e93313f1fcfcc5622bae706aea9335dbc43ef /dxwindow/dxwindow.ixx
parentb5697421bbc73ed17ef3a8bc003571d1b6351b5c (diff)
Switch to plain C
Diffstat (limited to 'dxwindow/dxwindow.ixx')
-rw-r--r--dxwindow/dxwindow.ixx113
1 files changed, 0 insertions, 113 deletions
diff --git a/dxwindow/dxwindow.ixx b/dxwindow/dxwindow.ixx
deleted file mode 100644
index 6efcc18..0000000
--- a/dxwindow/dxwindow.ixx
+++ /dev/null
@@ -1,113 +0,0 @@
1module;
2
3// Include Windows.h before GLFW to avoid macro redefinition warnings.
4#define WIN32_LEAN_AND_MEAN
5#include <Windows.h>
6
7#define GLFW_INCLUDE_NONE // Do not include OpenGL headers.
8#include <GLFW/glfw3.h>
9
10#define GLFW_EXPOSE_NATIVE_WIN32
11#include <GLFW/glfw3native.h>
12
13#include <cassert>
14#include <cstdio>
15
16export module dxwindow;
17
18namespace dx {
19
20char glfw_error[1024] = {};
21
22void glfw_error_callback(int error, const char* description)
23{
24 sprintf_s(glfw_error, sizeof(glfw_error),
25 "GLFW error %d: %s", error, description);
26}
27
28export {
29
30class Window
31{
32public:
33 ~Window()
34 {
35 if (m_window != nullptr)
36 {
37 glfwDestroyWindow(m_window);
38 }
39 }
40
41 /// Creates the window.
42 bool Initialise(int width, int height, const char* title)
43 {
44 // GLFW by default creates an OpenGL context with the window.
45 // Use GLFW_NO_API to tell it not to do so.
46 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
47
48 if ((m_window = glfwCreateWindow(
49 width, height, title, /*monitor=*/NULL, /*share=*/NULL)) == nullptr)
50 {
51 return false;
52 }
53
54 return true;
55 }
56
57 /// Returns the native window handle.
58 /// If the window has not been initialized, returns an invalid handle.
59 HWND GetWindowHandle()
60 {
61 if (!m_window)
62 {
63 return NULL;
64 }
65 return glfwGetWin32Window(m_window);
66 }
67
68 /// Updates the window by polling for user input.
69 void Update()
70 {
71 assert(m_window);
72 glfwPollEvents();
73 }
74
75 /// Returns true if the user tried to close the window, false otherwise.
76 bool ShouldClose() const
77 {
78 assert(m_window);
79 return glfwWindowShouldClose(m_window) == GLFW_TRUE;
80 }
81
82private:
83 GLFWwindow* m_window = nullptr;
84};
85
86/// Initialise the window subsystem.
87///
88/// This function must be called at the start of your application before any
89/// Windows are created.
90bool WindowInitialise()
91{
92 glfwSetErrorCallback(glfw_error_callback);
93 return glfwInit() == GLFW_TRUE;
94}
95
96/// Terminate the window subsystem.
97///
98/// This function should be called at the end of your application. Any existing
99/// Windows are destroyed and are invalid beyond this call.
100void WindowTerminate()
101{
102 glfwTerminate();
103}
104
105/// Returns the last Window error.
106const char* GetWindowError()
107{
108 return glfw_error;
109}
110
111} // export
112
113} // namespace dx