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

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

Start using the logger class to output basic debugging info to a file in both openglgame and vulkangame

  • Property mode set to 100644
File size: 3.7 KB
Line 
1#include "vulkan-game.hpp"
2
3#include <iostream>
4
5#include "consts.hpp"
6#include "logger.hpp"
7
8using namespace std;
9
10VulkanGame::VulkanGame() {
11 gui = nullptr;
12 window = nullptr;
13}
14
15VulkanGame::~VulkanGame() {
16}
17
18void VulkanGame::run(int width, int height, unsigned char guiFlags) {
19 cout << "DEBUGGING IS " << (ENABLE_VALIDATION_LAYERS ? "ON" : "OFF") << endl;
20
21 cout << "Vulkan Game" << endl;
22
23 // This gets the runtime version, use SDL_VERSION() for the comppile-time version
24 // TODO: Create a game-gui function to get the gui version and retrieve it that way
25 SDL_GetVersion(&sdlVersion);
26
27 // TODO: Refactor the logger api to be more flexible,
28 // esp. since gl_log() and gl_log_err() have issues printing anything besides stirngs
29 restart_gl_log();
30 gl_log("starting SDL\n%s.%s.%s",
31 to_string(sdlVersion.major).c_str(),
32 to_string(sdlVersion.minor).c_str(),
33 to_string(sdlVersion.patch).c_str());
34
35 open_log();
36 get_log() << "starting SDL" << endl;
37 get_log() <<
38 (int)sdlVersion.major << "." <<
39 (int)sdlVersion.minor << "." <<
40 (int)sdlVersion.patch << endl;
41
42 if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
43 return;
44 }
45
46 SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);
47 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
48
49 SDL_RenderClear(renderer);
50
51 SDL_RenderPresent(renderer);
52
53 initVulkan();
54 mainLoop();
55 cleanup();
56
57 close_log();
58}
59
60// TODO: Make some more initi functions, or call this initUI if the
61// amount of things initialized here keeps growing
62bool VulkanGame::initWindow(int width, int height, unsigned char guiFlags) {
63 // TODO: Put all fonts, textures, and images in the assets folder
64 gui = new GameGui_SDL();
65
66 if (gui->init() == RTWO_ERROR) {
67 // TODO: Also print these sorts of errors to the log
68 cout << "UI library could not be initialized!" << endl;
69 cout << gui->getError() << endl;
70 return RTWO_ERROR;
71 }
72
73 window = (SDL_Window*) gui->createWindow("Vulkan Game", width, height, guiFlags & GUI_FLAGS_WINDOW_FULLSCREEN);
74 if (window == nullptr) {
75 cout << "Window could not be created!" << endl;
76 cout << gui->getError() << endl;
77 return RTWO_ERROR;
78 }
79
80 int actualWidth, actualHeight;
81 gui->getWindowSize(&actualWidth, &actualHeight);
82
83 cout << "Target window size: (" << width << ", " << height << ")" << endl;
84 cout << "Actual window size: (" << actualWidth << ", " << actualHeight << ")" << endl;
85
86 return RTWO_SUCCESS;
87}
88
89void VulkanGame::initVulkan() {
90}
91
92void VulkanGame::mainLoop() {
93 UIEvent e;
94 bool quit = false;
95
96 while (!quit) {
97 gui->processEvents();
98
99 while (gui->pollEvent(&e)) {
100 switch(e.type) {
101 case UI_EVENT_QUIT:
102 cout << "Quit event detected" << endl;
103 quit = true;
104 break;
105 case UI_EVENT_WINDOW:
106 cout << "Window event detected" << endl;
107 // Currently unused
108 break;
109 case UI_EVENT_KEY:
110 if (e.key.keycode == SDL_SCANCODE_ESCAPE) {
111 quit = true;
112 } else {
113 cout << "Key event detected" << endl;
114 }
115 break;
116 case UI_EVENT_MOUSEBUTTONDOWN:
117 cout << "Mouse button down event detected" << endl;
118 break;
119 case UI_EVENT_MOUSEBUTTONUP:
120 cout << "Mouse button up event detected" << endl;
121 break;
122 case UI_EVENT_MOUSEMOTION:
123 break;
124 default:
125 cout << "Unhandled UI event: " << e.type << endl;
126 }
127 }
128 }
129}
130
131void VulkanGame::cleanup() {
132 gui->destroyWindow();
133 gui->shutdown();
134 delete gui;
135}
Note: See TracBrowser for help on using the repository browser.