[0e6ecf3] | 1 | #include "game-gui-glfw.hpp"
|
---|
| 2 |
|
---|
[d8cb15e] | 3 | string GameGui_GLFW::s_errorMessage;
|
---|
| 4 |
|
---|
| 5 | void glfw_error_callback(int error, const char* description) {
|
---|
| 6 | GameGui_GLFW::s_errorMessage = description;
|
---|
| 7 | }
|
---|
| 8 |
|
---|
| 9 | string& GameGui_GLFW::GetError() {
|
---|
| 10 | return GameGui_GLFW::s_errorMessage;
|
---|
| 11 | }
|
---|
| 12 |
|
---|
[0e6ecf3] | 13 | bool GameGui_GLFW::Init() {
|
---|
[d8cb15e] | 14 | GameGui_GLFW::s_errorMessage = "No error";
|
---|
| 15 | glfwSetErrorCallback(glfw_error_callback);
|
---|
| 16 |
|
---|
| 17 | return glfwInit() == GLFW_TRUE ? RTWO_SUCCESS : RTWO_ERROR;
|
---|
[0e6ecf3] | 18 | }
|
---|
| 19 |
|
---|
| 20 | void GameGui_GLFW::Shutdown() {
|
---|
| 21 | glfwTerminate();
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | void* GameGui_GLFW::CreateWindow(const string& title, unsigned int width, unsigned int height) {
|
---|
| 25 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
---|
| 26 |
|
---|
| 27 | window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
|
---|
| 28 |
|
---|
| 29 | return window;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | void GameGui_GLFW::DestroyWindow() {
|
---|
| 33 | // TODO: This function can throw some errors. They should be handled
|
---|
| 34 | glfwDestroyWindow(window);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[4eb4d0a] | 37 | #ifdef GAMEGUI_INCLUDE_VULKAN
|
---|
| 38 |
|
---|
[0e6ecf3] | 39 | bool GameGui_GLFW::CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {
|
---|
| 40 | return glfwCreateWindowSurface(instance, window, nullptr, surface) == VK_SUCCESS ?
|
---|
| 41 | RTWO_SUCCESS : RTWO_ERROR;
|
---|
| 42 | }
|
---|
[8667f76] | 43 |
|
---|
[4eb4d0a] | 44 | #endif
|
---|
| 45 |
|
---|
[8667f76] | 46 | vector<const char*> GameGui_GLFW::GetRequiredExtensions() {
|
---|
| 47 | uint32_t glfwExtensionCount = 0;
|
---|
| 48 | const char** glfwExtensions;
|
---|
| 49 |
|
---|
| 50 | glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
|
---|
| 51 |
|
---|
| 52 | vector<const char*> extensions(glfwExtensions, glfwExtensions + glfwExtensionCount);
|
---|
| 53 |
|
---|
| 54 | return extensions;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | void GameGui_GLFW::GetWindowSize(int* width, int* height) {
|
---|
| 58 | glfwGetFramebufferSize(window, width, height);
|
---|
| 59 | }
|
---|