source: opengl-game/vulkan-game.cpp@ 27c40ce

feature/imgui-sdl points-test
Last change on this file since 27c40ce was 27c40ce, checked in by Dmitry Portnoy <dmp1488@…>, 5 years ago

Update vulkangame to correctly display a window in Windows and add some commented-out code for a generic system for processing UI events

  • Property mode set to 100644
File size: 2.2 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 if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
19 return;
20 }
21
22 SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);
23 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
24
25 SDL_RenderClear(renderer);
26
27 SDL_RenderPresent(renderer);
28
29 initVulkan();
30 mainLoop();
31 cleanup();
32}
33
34bool VulkanGame::initWindow(int width, int height, unsigned char guiFlags) {
35 gui = new GameGui_SDL();
36
37 if (gui->init() == RTWO_ERROR) {
38 cout << "UI library could not be initialized!" << endl;
39 cout << gui->getError() << endl;
40 return RTWO_ERROR;
41 }
42
43 window = (SDL_Window*) gui->createWindow("Vulkan Game", width, height, guiFlags & GUI_FLAGS_WINDOW_FULLSCREEN);
44 if (window == nullptr) {
45 cout << "Window could not be created!" << endl;
46 cout << gui->getError() << endl;
47 return RTWO_ERROR;
48 }
49
50 int actualWidth, actualHeight;
51 gui->getWindowSize(&actualWidth, &actualHeight);
52
53 cout << "Target window size: (" << width << ", " << height << ")" << endl;
54 cout << "Actual window size: (" << actualWidth << ", " << actualHeight << ")" << endl;
55
56 return RTWO_SUCCESS;
57}
58
59void VulkanGame::initVulkan() {
60}
61
62void VulkanGame::mainLoop() {
63 SDL_Event e;
64 //MouseEvent mouseEvent;
65 bool quit = false;
66
67 while (!quit) {
68 /*
69 gui->processEvents();
70
71 if (gui->getKeyEvent(SDLK_ESCAPE) == RTWO_KEY_EVENT_PRESSED) {
72 quit = true;
73 }
74
75 while (gui->pollMouseEvent(&mouseEvent)) {
76 cout << "Mouse click detected at (" << mouseEvent.x << ", " << mouseEvent.y << ")" << endl;
77 }
78 */
79
80 while (SDL_PollEvent(&e)) {
81 if (e.type == SDL_QUIT) {
82 quit = true;
83 }
84 if (e.type == SDL_KEYDOWN) {
85 quit = true;
86 }
87 if (e.type == SDL_MOUSEBUTTONDOWN) {
88 quit = true;
89 }
90 }
91 }
92}
93
94void VulkanGame::cleanup() {
95 gui->destroyWindow();
96 gui->shutdown();
97 delete gui;
98}
Note: See TracBrowser for help on using the repository browser.