hibiscus/test/app.cpp
2023-05-30 17:00:39 +01:00

99 lines
2.3 KiB
C++

#include <logging/types.hpp>
#include <fmt/format.h>
#include <renderer/renderer.hpp>
#include <rsdl.hpp>
#include <resources/font.hpp>
#include <resources/font.hpp>
#include <string>
#include <iostream>
#include <chrono>
#include <thread>
#include <engine/engine.hpp>
#include <pragmautil.hpp>
#if defined(_MSC_VER) || defined(_MSC_FULL_VER)
WARNING("Please avoid using MSVC in C++ projects utilising std::chrono and std::this_thread due to unfixed frame timing issues in the MSVC C++ implementation")
#endif
using namespace hibis;
using namespace hibis::rsdl;
void logger(LoggingSeverity severity, std::string message) {
std::string sevString;
switch (severity) {
case Message:
sevString = "Message";
break;
case Information:
sevString = "Information";
break;
case Warning:
sevString = "Warning";
break;
case Error:
sevString = "Error";
break;
case Fatal:
sevString = "Fatal";
break;
}
std::cout << fmt::format("[{}]: {}", sevString, message) << std::endl;
}
int main() {
RSDL renderer = RSDL("test", IntVec2 {800, 600}, &logger);
Engine engine = Engine(&renderer, &logger);
#ifdef _WIN32
Font font = Font("C:\\Windows\\Fonts\\Arial.ttf", 16);
#else
Font font = Font("/usr/share/fonts/noto/NotoSans-Light.ttf", 16);
#endif
Texture image = Texture((char*)"test.png");
unsigned char red = 0;
bool increaseRed = true;
bool increaseSize = true;
uint size = 16;
uint f = 0;
logger(Information, "Started Hibis test app! BEHOLD: Colours.");
while (renderer.mKeepOpen) {
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});
renderer.drawTexture(&image, 1.0f, IntVec2 {10, 10});
engine.drawNodes();
renderer.renderCurrent();
renderer.update();
std::this_thread::sleep_for(std::chrono::milliseconds(16));
}
return 0;
}