Changeset 0df3c9a in opengl-game


Ignore:
Timestamp:
Aug 29, 2019, 9:16:07 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
4eb4d0a
Parents:
eba8c0c
Message:

Create a basic SDL window

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • space-game.cpp

    reba8c0c r0df3c9a  
    11#include "space-game.hpp"
    22
     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
    317void SpaceGame::run() {
     18   if (initWindow() == RTWO_ERROR) {
     19      return;
     20   }
     21   initVulkan();
     22   mainLoop();
     23   cleanup();
    424}
     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}
  • space-game.hpp

    reba8c0c r0df3c9a  
    22#define _SPACE_GAME_H
    33
     4#include "game-gui-sdl.hpp"
     5
     6const int SCREEN_WIDTH = 800;
     7const int SCREEN_HEIGHT = 600;
     8
    49class SpaceGame {
    510   public:
     11      SpaceGame();
     12      ~SpaceGame();
     13
    614      void run();
     15
     16   private:
     17      GameGui* gui;
     18      SDL_Window* window;
     19
     20      bool initWindow();
     21      void initVulkan();
     22      void mainLoop();
     23      void cleanup();
    724};
    825
Note: See TracChangeset for help on using the changeset viewer.