rendering kinda
This commit is contained in:
@@ -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() {}
|
||||
|
||||
@@ -126,11 +126,13 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="display.cpp" />
|
||||
<ClCompile Include="entity.cpp" />
|
||||
<ClCompile Include="game.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="display.h" />
|
||||
<ClInclude Include="entity.h" />
|
||||
<ClInclude Include="game.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="display.cpp" />
|
||||
<ClCompile Include="game.cpp" />
|
||||
<ClCompile Include="entity.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="headers">
|
||||
@@ -17,5 +18,8 @@
|
||||
<ClInclude Include="game.h">
|
||||
<Filter>headers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="entity.h">
|
||||
<Filter>headers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user