source: opengl-game/game-gui-glfw.cpp@ 9546928

feature/imgui-sdl points-test
Last change on this file since 9546928 was 9546928, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 5 years ago

Move some constants into consts.hpp

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