source: opengl-game/vulkan-game.cpp@ 5edbd58

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

For both openglgame and vulkangame, pass in the window width and height and a fullscreen flag to the run() function

  • Property mode set to 100644
File size: 1.5 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(unsigned int width, unsigned int height, unsigned char guiFlags) {
21 if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
22 return;
23 }
24 initVulkan();
25 mainLoop();
26 cleanup();
27}
28
29bool VulkanGame::initWindow(unsigned int width, unsigned int height, unsigned char guiFlags) {
30 gui = new GameGui_SDL();
31
32 if (gui->Init() == RTWO_ERROR) {
33 cout << "UI library could not be initialized!" << endl;
34 cout << gui->GetError() << endl;
35 return RTWO_ERROR;
36 }
37 cout << "GUI init succeeded" << endl;
38
39 window = (SDL_Window*) gui->CreateWindow("Vulkan Game", width, height);
40 if (window == nullptr) {
41 cout << "Window could not be created!" << endl;
42 return RTWO_ERROR;
43 }
44
45 return RTWO_SUCCESS;
46}
47
48void VulkanGame::initVulkan() {
49}
50
51void VulkanGame::mainLoop() {
52 SDL_Event e;
53 bool quit = false;
54
55 while (!quit) {
56 while (SDL_PollEvent(&e)) {
57 if (e.type == SDL_QUIT) {
58 quit = true;
59 }
60 if (e.type == SDL_KEYDOWN) {
61 quit = true;
62 }
63 if (e.type == SDL_MOUSEBUTTONDOWN) {
64 quit = true;
65 }
66 }
67 }
68}
69
70void VulkanGame::cleanup() {
71 gui->DestroyWindow();
72 gui->Shutdown();
73 delete gui;
74}
Note: See TracBrowser for help on using the repository browser.