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

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

Implement GetError() in game-gui-glfw and start using game-gui-glfw in opengl-game to show a window

  • Property mode set to 100644
File size: 1.5 KB
Line 
1#include "game-gui-glfw.hpp"
2
3string GameGui_GLFW::s_errorMessage;
4
5void glfw_error_callback(int error, const char* description) {
6 GameGui_GLFW::s_errorMessage = description;
7}
8
9string& GameGui_GLFW::GetError() {
10 return GameGui_GLFW::s_errorMessage;
11}
12
13bool 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
20void GameGui_GLFW::Shutdown() {
21 glfwTerminate();
22}
23
24void* 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
32void 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
39bool 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
46vector<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
57void GameGui_GLFW::GetWindowSize(int* width, int* height) {
58 glfwGetFramebufferSize(window, width, height);
59}
Note: See TracBrowser for help on using the repository browser.