This commit is contained in:
Ben Kyd
2019-07-16 16:24:30 +01:00
parent ed42a92be8
commit 8a8636c144
4 changed files with 18 additions and 6 deletions

View File

@@ -23,6 +23,8 @@ bool Display::InitVideoDisplay(std::string title, int x, int y) {
return false;
}
this->WindowOpen = true;
m_renderer = SDL_CreateRenderer(
m_window, -1, SDL_RENDERER_ACCELERATED
);
@@ -88,7 +90,11 @@ void Display::Refresh() {
}
void Display::CloseDisplay() {
free(Framebuffer);
SDL_DestroyTexture(m_texture);
SDL_DestroyRenderer(m_renderer);
SDL_DestroyWindow(m_window);
SDL_Quit();
}
Display::~Display() {

View File

@@ -13,6 +13,7 @@ public:
bool InitVideoDisplay(std::string title, int x, int y);
bool WindowOpen = false;
int XRes, YRes;
std::string Title;
unsigned int Scale = 1;

View File

@@ -1,5 +1,6 @@
#include "inferno.hpp"
#include <iostream>
#include <SDL2/SDL.h>
#include "pixel.hpp"
@@ -19,14 +20,17 @@ void InfernoEngine::SetMode(OperationMode mode) {
}
bool InfernoEngine::InitWindow(int xRes, int yRes) {
if (!m_initialized) {
if (m_initialized) {
// warn =
return true;
}
m_display = new Display();
if (m_display == nullptr)
m_display = new Display();
if (!m_display->InitVideoDisplay("Inferno Engine", xRes, yRes)) {
bool status = m_display->InitVideoDisplay("Inferno Engine", xRes, yRes);
if (!status) {
return false;
}
@@ -38,13 +42,13 @@ bool InfernoEngine::InitWindow(int xRes, int yRes) {
void InfernoEngine::Ready() {
if (!m_initialized) m_initialized = true;
while (1) {
while (m_display->WindowOpen) {
SDL_Event e;
while (SDL_PollEvent(&e) == SDL_TRUE)
if (e.type == SDL_QUIT) m_display->CloseDisplay();
for (int i = 0; i < 360000; i++) {
m_display->SetPixel(rand() % m_display->XRes,
m_display->SetPixelSafe(rand() % m_display->XRes,
rand() % m_display->YRes,
rgb888(rand() % 255, rand() % 255, rand() % 255));
}

View File

@@ -5,6 +5,7 @@ int main(int argc, char** argv) {
InfernoEngine inferno;
inferno.SetMode(MODE_PROGRESSIVE_GUI);
bool status = inferno.InitWindow(600, 600);
if (!status) {
std::cout << "Error initializing window: " << inferno.LastError() << std::endl;