| 1 | #include "game-gui-glfw.hpp"
|
|---|
| 2 |
|
|---|
| 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 |
|
|---|
| 13 | bool GameGui_GLFW::Init() {
|
|---|
| 14 | GameGui_GLFW::s_errorMessage = "No error";
|
|---|
| 15 | glfwSetErrorCallback(glfw_error_callback);
|
|---|
| 16 |
|
|---|
| 17 | return glfwInit() == GLFW_TRUE ? RTWO_SUCCESS : RTWO_ERROR;
|
|---|
| 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 |
|
|---|
| 37 | #ifdef GAMEGUI_INCLUDE_VULKAN
|
|---|
| 38 |
|
|---|
| 39 | bool GameGui_GLFW::CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {
|
|---|
| 40 | return glfwCreateWindowSurface(instance, window, nullptr, surface) == VK_SUCCESS ?
|
|---|
| 41 | RTWO_SUCCESS : RTWO_ERROR;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | #endif
|
|---|
| 45 |
|
|---|
| 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 | }
|
|---|