diff --git a/crumpet-engine/Game.cpp b/crumpet-engine/Game.cpp index 893c1ec..9c23fad 100644 --- a/crumpet-engine/Game.cpp +++ b/crumpet-engine/Game.cpp @@ -1,15 +1,25 @@ #include "game.h" Game::Game(std::string title, int width, int height) - : m_display(title, width, height) { + : m_display(title, width, height) { std::cout << "Engine initialized" << std::endl; } +void Game::UpdateDisplay() { + m_display.Update(); +} + +void Game::CloseDisplay() { + m_display.Close(); +} + bool Game::IsDisplayClosed() { return m_display.IsClosed(); } -Game::~Game() { - m_display.~Display(); +Display Game::GetDisplay() { + return m_display; } + +Game::~Game() {} diff --git a/crumpet-engine/crumpet-engine.vcxproj b/crumpet-engine/crumpet-engine.vcxproj index 3a0c817..f1a1530 100644 --- a/crumpet-engine/crumpet-engine.vcxproj +++ b/crumpet-engine/crumpet-engine.vcxproj @@ -126,11 +126,13 @@ + + diff --git a/crumpet-engine/crumpet-engine.vcxproj.filters b/crumpet-engine/crumpet-engine.vcxproj.filters index 1058e93..c88409b 100644 --- a/crumpet-engine/crumpet-engine.vcxproj.filters +++ b/crumpet-engine/crumpet-engine.vcxproj.filters @@ -4,6 +4,7 @@ + @@ -17,5 +18,8 @@ headers + + headers + \ No newline at end of file diff --git a/crumpet-engine/display.cpp b/crumpet-engine/display.cpp index 23adcbd..7567d6d 100644 --- a/crumpet-engine/display.cpp +++ b/crumpet-engine/display.cpp @@ -2,19 +2,28 @@ Display::Display(std::string title, int width, int height) { if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { - std::cout << "SDL could not initialize! SDL_Error: %s\n" << SDL_GetError() << std::endl; + std::cout << "SDL could not initialize, SDL ERROR: " << SDL_GetError() << std::endl; } m_window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN); - m_screenSurface = SDL_GetWindowSurface(m_window); + m_renderer = SDL_CreateRenderer(m_window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED); + SDL_SetRenderDrawColor(m_renderer, 123, 122, 0, 255); isClosed = false; } +void Display::Update() { + +} + bool Display::IsClosed() { return isClosed; } +void Display::Close() { + isClosed = true; +} + Display::~Display() { isClosed = true; SDL_DestroyWindow(m_window); diff --git a/crumpet-engine/display.h b/crumpet-engine/display.h index 5f4270e..8e81991 100644 --- a/crumpet-engine/display.h +++ b/crumpet-engine/display.h @@ -7,12 +7,16 @@ class Display { public: Display(std::string title, int width, int height); + + void Update(); + bool IsClosed(); + void Close(); virtual ~Display(); private: SDL_Window *m_window; - SDL_Surface *m_screenSurface; - SDL_Surface *m_texture; + SDL_Renderer *m_renderer; + bool isClosed; }; diff --git a/crumpet-engine/game.h b/crumpet-engine/game.h index 08d0310..9f11676 100644 --- a/crumpet-engine/game.h +++ b/crumpet-engine/game.h @@ -1,13 +1,18 @@ #pragma once #include - #include "display.h" class Game { public: Game(std::string title, int width, int height); + + void UpdateDisplay(); + void CloseDisplay(); bool IsDisplayClosed(); + + Display GetDisplay(); + virtual ~Game(); private: Display m_display; diff --git a/crumpet-engine/main.cpp b/crumpet-engine/main.cpp index 842954f..60be6f3 100644 --- a/crumpet-engine/main.cpp +++ b/crumpet-engine/main.cpp @@ -8,9 +8,14 @@ int main(int argc, char** argv) { Game game("Crumpet engine", SCREEN_WIDTH, SCREEN_HEIGHT); + SDL_Event e; while (!game.IsDisplayClosed()) { - SDL_Event *e; - while (&e) {} + + while (SDL_PollEvent(&e) != 0) + if (e.type == SDL_QUIT) + game.CloseDisplay(); + + game.UpdateDisplay(); } return 0;