source: opengl-game/vulkan-game.cpp@ 2e77b3f

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

Move the debug status output from the main functions to the openglgame and vulkangame classes

  • Property mode set to 100644
File size: 2.7 KB
Line 
1#include "vulkan-game.hpp"
2
3#include <iostream>
4
5#include "consts.hpp"
6
7using namespace std;
8
9VulkanGame::VulkanGame() {
10 gui = nullptr;
11 window = nullptr;
12}
13
14VulkanGame::~VulkanGame() {
15}
16
17void VulkanGame::run(int width, int height, unsigned char guiFlags) {
18 cout << "DEBUGGING IS " << (ENABLE_VALIDATION_LAYERS ? "ON" : "OFF") << endl;
19
20 cout << "Vulkan Game" << endl;
21
22 if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
23 return;
24 }
25
26 SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);
27 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
28
29 SDL_RenderClear(renderer);
30
31 SDL_RenderPresent(renderer);
32
33 initVulkan();
34 mainLoop();
35 cleanup();
36}
37
38bool VulkanGame::initWindow(int width, int height, unsigned char guiFlags) {
39 gui = new GameGui_SDL();
40
41 if (gui->init() == RTWO_ERROR) {
42 cout << "UI library could not be initialized!" << endl;
43 cout << gui->getError() << endl;
44 return RTWO_ERROR;
45 }
46
47 window = (SDL_Window*) gui->createWindow("Vulkan Game", width, height, guiFlags & GUI_FLAGS_WINDOW_FULLSCREEN);
48 if (window == nullptr) {
49 cout << "Window could not be created!" << endl;
50 cout << gui->getError() << endl;
51 return RTWO_ERROR;
52 }
53
54 int actualWidth, actualHeight;
55 gui->getWindowSize(&actualWidth, &actualHeight);
56
57 cout << "Target window size: (" << width << ", " << height << ")" << endl;
58 cout << "Actual window size: (" << actualWidth << ", " << actualHeight << ")" << endl;
59
60 return RTWO_SUCCESS;
61}
62
63void VulkanGame::initVulkan() {
64}
65
66void VulkanGame::mainLoop() {
67 UIEvent e;
68 bool quit = false;
69
70 while (!quit) {
71 gui->processEvents();
72
73 while (gui->pollEvent(&e)) {
74 switch(e.type) {
75 case UI_EVENT_QUIT:
76 cout << "Quit event detected" << endl;
77 quit = true;
78 break;
79 case UI_EVENT_WINDOW:
80 cout << "Window event detected" << endl;
81 // Currently unused
82 break;
83 case UI_EVENT_KEY:
84 if (e.key.keycode == SDL_SCANCODE_ESCAPE) {
85 quit = true;
86 } else {
87 cout << "Key event detected" << endl;
88 }
89 break;
90 case UI_EVENT_MOUSEBUTTONDOWN:
91 cout << "Mouse button down event detected" << endl;
92 break;
93 case UI_EVENT_MOUSEBUTTONUP:
94 cout << "Mouse button up event detected" << endl;
95 break;
96 case UI_EVENT_MOUSEMOTION:
97 break;
98 default:
99 cout << "Unhandled UI event: " << e.type << endl;
100 }
101 }
102 }
103}
104
105void VulkanGame::cleanup() {
106 gui->destroyWindow();
107 gui->shutdown();
108 delete gui;
109}
Note: See TracBrowser for help on using the repository browser.