hibiscus/test/app.cpp

106 lines
2.7 KiB
C++
Raw Normal View History

2023-05-26 21:41:51 +00:00
#include <logging/types.hpp>
#include <fmt/format.h>
#include <renderer/renderer.hpp>
#include <rglcore.hpp>
2023-05-26 21:41:51 +00:00
#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)
2023-05-30 14:20:34 +00:00
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
2023-05-26 21:41:51 +00:00
using namespace hibis;
using namespace hibis::rglcore;
2023-05-26 21:41:51 +00:00
void logger(LoggingSeverity severity, std::string message) {
std::string sevString;
switch (severity) {
case Message:
2023-06-01 19:19:18 +00:00
sevString = " Message ";
2023-05-26 21:41:51 +00:00
break;
case Information:
sevString = "Information";
break;
case Warning:
2023-06-01 19:19:18 +00:00
sevString = " Warning ";
2023-05-26 21:41:51 +00:00
break;
case Error:
2023-06-01 19:19:18 +00:00
sevString = " Error ";
2023-05-26 21:41:51 +00:00
break;
case Fatal:
2023-06-01 19:19:18 +00:00
sevString = " Fatal ";
2023-05-26 21:41:51 +00:00
break;
}
std::cout << fmt::format("[{}]: {}", sevString, message) << std::endl;
2023-05-26 21:41:51 +00:00
}
int main() {
2023-06-01 19:19:18 +00:00
logger(Information, fmt::format("PWD: {}", std::getenv("PWD")));
RGLCore renderer = RGLCore("test", IntVec2 {800, 600}, &logger);
2023-05-26 21:41:51 +00:00
Engine engine = Engine(&renderer, &logger);
#ifdef _WIN32
2023-06-01 19:19:18 +00:00
Font font = Font(engine.mFreeTypeLibrary, "C:\\Windows\\Fonts\\Arial.ttf", 16);
2023-05-26 21:41:51 +00:00
#else
Font font = Font(engine.mFreeTypeLibrary, "/usr/share/fonts/noto/NotoSans-Light.ttf", 16);
2023-05-26 21:41:51 +00:00
#endif
2023-05-30 16:00:39 +00:00
Texture image = Texture((char*)"test.png");
2023-06-01 19:19:18 +00:00
Shader shader = Shader("../test/test.vert", "../test/test.frag");
renderer.compileShader(&shader);
2023-05-30 16:00:39 +00:00
uint8_t red = 0;
2023-05-26 21:41:51 +00:00
bool increaseRed = true;
bool increaseSize = true;
uint size = 16;
uint f = 0;
2023-06-01 19:19:18 +00:00
Point2D points[3] = {{-0.5f, -0.5f}, {0.5f, -0.5f}, {0.0f, 0.5f}};
2023-05-26 21:41:51 +00:00
logger(Information, "Started Hibis test app! BEHOLD: Colours.");
while (renderer.mKeepOpen) {
2023-05-26 21:41:51 +00:00
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});
2023-06-01 19:19:18 +00:00
renderer.useShader(&shader, points);
2023-06-14 20:59:21 +00:00
renderer.stopUsingShaders();
2023-06-01 19:19:18 +00:00
//renderer.drawText(&font, "Testing Text", IntVec2 {0, 0}, Color {255, 255, 255, 255});
//renderer.drawTexture(&image, 1.0f, IntVec2 {10, 10});
2023-05-26 21:41:51 +00:00
engine.drawNodes();
renderer.renderCurrent();
renderer.update();
std::this_thread::sleep_for(std::chrono::milliseconds(16));
}
return 0;
}