Initial rendering
This commit is contained in:
parent
cf60b9ace5
commit
cbe861693e
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,6 +1,9 @@
|
|||
# Directories
|
||||
.dub
|
||||
*/docs/
|
||||
.vscode
|
||||
|
||||
# Files
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
@ -13,8 +16,6 @@
|
|||
*.o
|
||||
*.obj
|
||||
*.lst
|
||||
|
||||
# Files
|
||||
docs.json
|
||||
__dummy.html
|
||||
dub.selections.json
|
|
@ -3,9 +3,9 @@ module gameengine.math.types;
|
|||
// Structs
|
||||
/// Image
|
||||
|
||||
// RGBA value struct
|
||||
// RGBA value struct. Value is between 0 and 255
|
||||
struct Color {
|
||||
float r, g, b, a;
|
||||
ubyte r, g, b, a;
|
||||
}
|
||||
|
||||
// 2D
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
module gameengine.renderer.renderer;
|
||||
|
||||
import gameengine.math.types;
|
||||
|
||||
abstract class Renderer {
|
||||
void setWindowTitle(string str);
|
||||
// Draw
|
||||
void clearScreen(Color);
|
||||
void renderCurrent();
|
||||
|
||||
// Pre and Post draw
|
||||
void preDraw();
|
||||
void postDraw();
|
||||
|
||||
// Util
|
||||
void setWindowTitle(string);
|
||||
}
|
|
@ -1,7 +1,55 @@
|
|||
module gameengine_rsdl;
|
||||
|
||||
import bindbc.sdl;
|
||||
import gameengine.renderer.renderer;
|
||||
import gameengine.math.types;
|
||||
import std.exception;
|
||||
import std.format;
|
||||
|
||||
class RSDL : Renderer {
|
||||
override void setWindowTitle(string title) {}
|
||||
this(char* title, IntVec2 size) {
|
||||
const SDLSupport ret = loadSDL();
|
||||
if(ret != sdlSupport) {
|
||||
throw new Exception("Couldn't load SDL");
|
||||
}
|
||||
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
||||
window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, size.x, size.y, SDL_WINDOW_RESIZABLE);
|
||||
|
||||
if (window is null) {
|
||||
string error = format("Couldn't create window! what: %d", SDL_GetError());
|
||||
throw new Exception(error);
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||
|
||||
if (renderer is null) {
|
||||
string error = format("Couldn't create renderer! what: %d", SDL_GetError());
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
~this() {
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
override void clearScreen(Color col = Color(0, 0, 0, 1)) {
|
||||
SDL_SetRenderDrawColor(renderer, col.r, col.g, col.b, col.a);
|
||||
SDL_RenderClear(renderer);
|
||||
}
|
||||
|
||||
override void renderCurrent() {
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
override void preDraw() {}
|
||||
override void postDraw() {}
|
||||
|
||||
override void setWindowTitle(string title) {}
|
||||
|
||||
private SDL_Window* window;
|
||||
private SDL_Renderer* renderer;
|
||||
}
|
|
@ -1,17 +1,21 @@
|
|||
import std.stdio;
|
||||
|
||||
import gameengine.core.engine;
|
||||
import gameengine.math.types;
|
||||
import gameengine.renderer.renderer;
|
||||
import gameengine_rsdl;
|
||||
|
||||
import core.thread;
|
||||
import std.string : toStringz;
|
||||
|
||||
void main() {
|
||||
Renderer renderer = new RSDL();
|
||||
Renderer renderer = new RSDL(cast(char*)toStringz("test".dup), IntVec2(800, 600));
|
||||
Engine engine = new Engine(renderer);
|
||||
|
||||
while (true) {
|
||||
engine.runNodeProcesses();
|
||||
Thread.sleep(1.msecs);
|
||||
renderer.clearScreen(Color(255, 0, 255, 255));
|
||||
renderer.renderCurrent();
|
||||
Thread.sleep(16.msecs);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue