diff options
Diffstat (limited to 'dxwindow/dxwindow.ixx')
| -rw-r--r-- | dxwindow/dxwindow.ixx | 113 |
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 @@ | |||
| 1 | module; | ||
| 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 | |||
| 16 | export module dxwindow; | ||
| 17 | |||
| 18 | namespace dx { | ||
| 19 | |||
| 20 | char glfw_error[1024] = {}; | ||
| 21 | |||
| 22 | void 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 | |||
| 28 | export { | ||
| 29 | |||
| 30 | class Window | ||
| 31 | { | ||
| 32 | public: | ||
| 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 | |||
| 82 | private: | ||
| 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. | ||
| 90 | bool 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. | ||
| 100 | void WindowTerminate() | ||
| 101 | { | ||
| 102 | glfwTerminate(); | ||
| 103 | } | ||
| 104 | |||
| 105 | /// Returns the last Window error. | ||
| 106 | const char* GetWindowError() | ||
| 107 | { | ||
| 108 | return glfw_error; | ||
| 109 | } | ||
| 110 | |||
| 111 | } // export | ||
| 112 | |||
| 113 | } // namespace dx | ||
