source: opengl-game/space-game.cpp@ 0df3c9a

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

Create a basic SDL window

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include "space-game.hpp"
2
3#include <iostream>
4
5#include "game-gui-sdl.hpp"
6
7using namespace std;
8
9SpaceGame::SpaceGame() {
10 gui = nullptr;
11 window = nullptr;
12}
13
14SpaceGame::~SpaceGame() {
15}
16
17void SpaceGame::run() {
18 if (initWindow() == RTWO_ERROR) {
19 return;
20 }
21 initVulkan();
22 mainLoop();
23 cleanup();
24}
25
26bool SpaceGame::initWindow() {
27 gui = new GameGui_SDL();
28
29 if (gui->Init() == RTWO_ERROR) {
30 cout << "UI library could not be initialized!" << endl;
31 cout << SDL_GetError() << endl;
32 return RTWO_ERROR;
33 }
34 cout << "GUI init succeeded" << endl;
35
36 window = (SDL_Window*) gui->CreateWindow("Vulkan Game", SCREEN_WIDTH, SCREEN_HEIGHT);
37 if (window == nullptr) {
38 cout << "Window could not be created!" << endl;
39 return RTWO_ERROR;
40 }
41
42 return RTWO_SUCCESS;
43}
44
45void SpaceGame::initVulkan() {
46}
47
48void SpaceGame::mainLoop() {
49 SDL_Event e;
50 bool quit = false;
51
52 while (!quit) {
53 while (SDL_PollEvent(&e)) {
54 if (e.type == SDL_QUIT) {
55 quit = true;
56 }
57 if (e.type == SDL_KEYDOWN) {
58 quit = true;
59 }
60 if (e.type == SDL_MOUSEBUTTONDOWN) {
61 quit = true;
62 }
63 }
64 }
65}
66
67void SpaceGame::cleanup() {
68 gui->DestroyWindow();
69 gui->Shutdown();
70 delete gui;
71}
Note: See TracBrowser for help on using the repository browser.