source: opengl-game/vulkan-game.cpp@ b6e60b4

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

In vulkangame and openglgame:

  • use int instead of usigned int for width and heights paremters
  • Fix a bug where GUI_FLAGS_WINDOW_FULLSCREEN was being incorrectly checked
  • Print the size of a window after it has been created
  • Property mode set to 100644
File size: 1.7 KB
Line 
1#include "vulkan-game.hpp"
2
3#include <iostream>
4
5#include "consts.hpp"
6
7#define GAMEGUI_INCLUDE_VULKAN
8#include "game-gui-sdl.hpp"
9
10using namespace std;
11
12VulkanGame::VulkanGame() {
13 gui = nullptr;
14 window = nullptr;
15}
16
17VulkanGame::~VulkanGame() {
18}
19
20void VulkanGame::run(int width, int height, unsigned char guiFlags) {
21 if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
22 return;
23 }
24
25 initVulkan();
26 mainLoop();
27 cleanup();
28}
29
30bool VulkanGame::initWindow(int width, int height, unsigned char guiFlags) {
31 gui = new GameGui_SDL();
32
33 if (gui->init() == RTWO_ERROR) {
34 cout << "UI library could not be initialized!" << endl;
35 cout << gui->getError() << endl;
36 return RTWO_ERROR;
37 }
38
39 window = (SDL_Window*) gui->createWindow("Vulkan Game", width, height, guiFlags & GUI_FLAGS_WINDOW_FULLSCREEN);
40 if (window == nullptr) {
41 cout << "Window could not be created!" << endl;
42 return RTWO_ERROR;
43 }
44
45 int actualWidth, actualHeight;
46 gui->getWindowSize(&actualWidth, &actualHeight);
47
48 cout << "Target window size: (" << width << ", " << height << ")" << endl;
49 cout << "Actual window size: (" << actualWidth << ", " << actualHeight << ")" << endl;
50
51 return RTWO_SUCCESS;
52}
53
54void VulkanGame::initVulkan() {
55}
56
57void VulkanGame::mainLoop() {
58 SDL_Event e;
59 bool quit = false;
60
61 while (!quit) {
62 while (SDL_PollEvent(&e)) {
63 if (e.type == SDL_QUIT) {
64 quit = true;
65 }
66 if (e.type == SDL_KEYDOWN) {
67 quit = true;
68 }
69 if (e.type == SDL_MOUSEBUTTONDOWN) {
70 quit = true;
71 }
72 }
73 }
74}
75
76void VulkanGame::cleanup() {
77 gui->destroyWindow();
78 gui->shutdown();
79 delete gui;
80}
Note: See TracBrowser for help on using the repository browser.