it segfaultsss
This commit is contained in:
0
src/core/renderer.cpp
Normal file
0
src/core/renderer.cpp
Normal file
8
src/core/renderer.hpp
Normal file
8
src/core/renderer.hpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef INFERNO_CORE_RENDERER_H_
|
||||
#define INFERNO_CORE_RENDERER_H_
|
||||
|
||||
class Renderer {
|
||||
// Function initProgressive or whatever takes a pointer to the display
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,96 @@
|
||||
#include "display.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../pixel.hpp"
|
||||
|
||||
Display::Display() {
|
||||
|
||||
}
|
||||
|
||||
bool Display::InitVideoDisplay(std::string title, int x, int y) {
|
||||
this->XRes = x; this->YRes = y;
|
||||
|
||||
m_window = SDL_CreateWindow(
|
||||
title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
this->XRes * this->Scale, this->YRes * this->Scale,
|
||||
SDL_WINDOW_ALLOW_HIGHDPI
|
||||
);
|
||||
|
||||
if (!m_window) {
|
||||
// Add error
|
||||
std::cout << "ERROR: COULD NOT CREATE SDL WINDOW" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_renderer = SDL_CreateRenderer(
|
||||
m_window, -1, SDL_RENDERER_ACCELERATED
|
||||
);
|
||||
|
||||
if (!m_renderer) {
|
||||
// Add error
|
||||
std::cout << "ERROR: COULD NOT CREATE SDL RENDERER" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
m_texture = SDL_CreateTexture(
|
||||
m_renderer, SDL_PIXELFORMAT_ARGB8888,
|
||||
SDL_TEXTUREACCESS_STREAMING, this->XRes, this->YRes
|
||||
);
|
||||
|
||||
if (!m_texture) {
|
||||
// Add error
|
||||
std::cout << "ERROR: COULD NOT CREATE SDL TEXTURE" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
Framebuffer = (uint32_t*)malloc(this->XRes * this->YRes * sizeof(uint32_t));
|
||||
|
||||
if (!Framebuffer) {
|
||||
// Add error
|
||||
std::cout << "ERROR: COULD NOT ALLOCATE FRAMEBUFFER" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Display::SetPixel(int x, int y, Pixel p) {
|
||||
Framebuffer[y * this->XRes + x] = p.rgb();
|
||||
}
|
||||
|
||||
void Display::SetPixel(int x, int y, uint32_t p) {
|
||||
Framebuffer[y * this->XRes + x] = p;
|
||||
}
|
||||
|
||||
void Display::SetPixelSafe(int x, int y, Pixel p) {
|
||||
if (x >= 0 && x < this->XRes && y >= 0 && this->YRes) {
|
||||
Framebuffer[y * this->XRes + x] = p.rgb();
|
||||
}
|
||||
}
|
||||
|
||||
void Display::SetPixelSafe(int x, int y, uint32_t p) {
|
||||
if (x >= 0 && x < this->XRes && y >= 0 && this->YRes) {
|
||||
Framebuffer[y * this->XRes + x] = p;
|
||||
}
|
||||
}
|
||||
|
||||
void Display::SetFramebuffer(uint32_t* fb) {
|
||||
Framebuffer = nullptr;
|
||||
Framebuffer = fb;
|
||||
}
|
||||
|
||||
void Display::Refresh() {
|
||||
SDL_UpdateTexture(m_texture, NULL, Framebuffer, this->XRes * sizeof(uint32_t));
|
||||
SDL_RenderCopy(m_renderer, m_texture, NULL, NULL);
|
||||
SDL_RenderPresent(m_renderer);
|
||||
}
|
||||
|
||||
void Display::CloseDisplay() {
|
||||
|
||||
}
|
||||
|
||||
Display::~Display() {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef INFERNO_DISPLAY_DISPLAY_H_
|
||||
#define INFERNO_DISPLAY_DISPLAY_H_
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
class Pixel;
|
||||
|
||||
class Display {
|
||||
public:
|
||||
Display();
|
||||
|
||||
bool InitVideoDisplay(std::string title, int x, int y);
|
||||
|
||||
int XRes, YRes;
|
||||
std::string Title;
|
||||
unsigned int Scale = 1;
|
||||
|
||||
void SetPixel(int x, int y, Pixel p);
|
||||
void SetPixel(int x, int y, uint32_t p);
|
||||
void SetPixelSafe(int x, int y, Pixel p);
|
||||
void SetPixelSafe(int x, int y, uint32_t p);
|
||||
|
||||
uint32_t* Framebuffer;
|
||||
void SetFramebuffer(uint32_t* fb);
|
||||
|
||||
void Refresh();
|
||||
|
||||
// Error and warn
|
||||
|
||||
void CloseDisplay();
|
||||
|
||||
virtual ~Display();
|
||||
private:
|
||||
// SDL Internals
|
||||
SDL_Window* m_window;
|
||||
SDL_Renderer* m_renderer;
|
||||
SDL_Texture* m_texture;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#include "inferno.hpp"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "pixel.hpp"
|
||||
|
||||
#include "display/display.hpp"
|
||||
|
||||
InfernoEngine::InfernoEngine() {
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
void InfernoEngine::SetMode(OperationMode mode) {
|
||||
if (!m_initialized) {
|
||||
// warn =
|
||||
return;
|
||||
}
|
||||
|
||||
m_mode = mode;
|
||||
}
|
||||
|
||||
bool InfernoEngine::InitWindow(int xRes, int yRes) {
|
||||
if (!m_initialized) {
|
||||
// warn =
|
||||
return true;
|
||||
}
|
||||
|
||||
m_display = new Display();
|
||||
|
||||
if (!m_display->InitVideoDisplay("Inferno Engine", xRes, yRes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InfernoEngine::Ready() {
|
||||
if (!m_initialized) m_initialized = true;
|
||||
|
||||
while (1) {
|
||||
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,
|
||||
rand() % m_display->YRes,
|
||||
rgb888(rand() % 255, rand() % 255, rand() % 255));
|
||||
}
|
||||
|
||||
m_display->Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
std::string InfernoEngine::LastError() {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string InfernoEngine::LastWarn() {
|
||||
return "";
|
||||
}
|
||||
|
||||
InfernoEngine::~InfernoEngine() {
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,12 @@
|
||||
#define INFERNO_INFERNO_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
// TODO: this errored for some reason lol
|
||||
// #include <pair>
|
||||
|
||||
class Display;
|
||||
class Renderer;
|
||||
|
||||
enum OperationMode {
|
||||
MODE_PROGRESSIVE_GUI,
|
||||
@@ -18,24 +22,39 @@ enum OperationMode {
|
||||
|
||||
class InfernoEngine {
|
||||
public:
|
||||
InfernoEngine();
|
||||
|
||||
void SetMode(OperationMode mode);
|
||||
|
||||
// Initializes the SDL framebuffer with OpenGL
|
||||
bool InitWindow();
|
||||
bool InitWindow(int xRes, int yRes);
|
||||
|
||||
void Ready();
|
||||
|
||||
// Queries the modules, if one of them errored it finds their error string
|
||||
// and returns it to the main execution code
|
||||
// and returns it to the main execution code, the same happens for warnings
|
||||
// each module class should have an "err" and "warn" a string, timestamp
|
||||
// pair as an atribute
|
||||
std::string LastError();
|
||||
std::string LastWarn();
|
||||
|
||||
// Error and warning
|
||||
// std::pair<std::string, int> err;
|
||||
// std::pair<std::string, int> warn;
|
||||
|
||||
virtual ~InfernoEngine();
|
||||
private:
|
||||
|
||||
OperationMode m_mode = MODE_PROGRESSIVE_GUI;
|
||||
|
||||
// Initialized flag - core engine features can't
|
||||
// be changed while this flag is set to true
|
||||
bool m_initialized = false;
|
||||
|
||||
// Gotta be a pointer so that if the display
|
||||
// mode is not selected then it is nothing
|
||||
Display* m_display = nullptr;
|
||||
|
||||
Renderer* m_renderer = nullptr;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
28
src/pixel.hpp
Normal file
28
src/pixel.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef INFERNO_PIXEL_H_
|
||||
#define INFERNO_PIXEL_H_
|
||||
|
||||
struct Pixel {
|
||||
uint8_t a;
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
|
||||
inline uint32_t argb() {
|
||||
return a << 24 | r << 16 | g << 8| b;
|
||||
}
|
||||
|
||||
inline uint32_t rgb() {
|
||||
return 0xFF000000 | r << 16 | g << 8| b;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
inline uint32_t argb8888(uint8_t a, uint8_t r, uint8_t g, uint8_t b) {
|
||||
return a << 24 | r << 16 | g << 8| b;
|
||||
}
|
||||
|
||||
inline uint32_t rgb888(uint8_t r, uint8_t g, uint8_t b) {
|
||||
return 0xFF000000 | r << 16 | g << 8| b;
|
||||
}
|
||||
|
||||
#endif
|
||||
0
src/primatives/sphere.cpp
Normal file
0
src/primatives/sphere.cpp
Normal file
0
src/primatives/sphere.hpp
Normal file
0
src/primatives/sphere.hpp
Normal file
13
src/util/types.hpp
Normal file
13
src/util/types.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
// #ifndef INFERNO_UTIL_TYPES_H_
|
||||
// #define INFERNO_UTIL_TYPES_H_
|
||||
|
||||
// typedef signed char int8_t;
|
||||
// typedef short int int16_t;
|
||||
// typedef int int32_t;
|
||||
// typedef long long int int64_t;
|
||||
// typedef unsigned char uint8_t;
|
||||
// typedef unsigned short int uint16_t;
|
||||
// typedef unsigned int uint32_t;
|
||||
// typedef unsigned long long int uint64_t;
|
||||
|
||||
// #endif
|
||||
@@ -5,10 +5,11 @@ int main(int argc, char** argv) {
|
||||
InfernoEngine inferno;
|
||||
|
||||
inferno.SetMode(MODE_PROGRESSIVE_GUI);
|
||||
bool status = inferno.InitWindow();
|
||||
if (!status {
|
||||
bool status = inferno.InitWindow(600, 600);
|
||||
if (!status) {
|
||||
std::cout << "Error initializing window: " << inferno.LastError() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
inferno.Ready();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user