hibiscus/test/source/app.d

66 lines
1.6 KiB
D

import std.stdio;
import std.format;
import std.conv;
import hibis.core.engine;
import hibis.math.types;
import hibis.renderer.renderer;
import hibis.logging.types;
import hibis.callback;
import hibis_rsdl.rsdl;
import hibis_rsdl.resources.font;
import core.thread;
void logger(LoggingSeverity severity, string message) {
writeln(format("[%s]: %s", to!string(severity), message));
}
void main() {
Renderer renderer = new RSDL("test", IntVec2(800, 600), &logger);
Engine engine = new Engine(renderer, &logger);
version(windows) {
Font font = new Font("C:\\Windows\\Fonts\\Arial.ttf", 16);
} else {
Font font = new Font("/usr/share/fonts/noto/NotoSans-Light.ttf", 16);
}
ubyte red = 0;
bool increaseRed = true;
bool increaseSize = true;
uint size = 16;
uint f = 0;
logger(LoggingSeverity.Information, "Started Hibis test app! BEHOLD: Colours.");
while (renderer.keepOpen) {
engine.runNodeProcesses();
// Colour changing background!
if ((red == 255 && increaseRed) || (red == 0 && !increaseRed)) {
increaseRed = !increaseRed;
}
if (increaseRed) red += 1;
else red -= 1;
f++;
if (f == 16) {
f = 0;
if ((size == 64 && increaseSize) || (size == 16 && !increaseSize)) {
increaseSize = !increaseSize;
}
if (increaseSize) size += 2;
else size -= 2;
font.setFontSize(size);
}
// Clear screen then sleep for ~16ms
renderer.clearScreen(Color(red, 0, 0, 255));
renderer.drawText(font, "Testing Text", IntVec2(0, 0), Color(255, 255, 255, 255));
engine.drawNodes();
renderer.renderCurrent();
renderer.update();
Thread.sleep(16.msecs);
}
destroy(font);
}