hibiscus/renderer/rglcore/rglcore.cpp

72 lines
1.9 KiB
C++

#include <fmt/format.h>
#include "rglcore.hpp"
namespace hibis::rglcore {
RGLCore::RGLCore(std::string title, IntVec2 size, LoggerCallback callback) : Renderer(callback) {
mLogger(Information, "Preparing GLFW3...");
if (!glfwInit()) {
mLogger(Fatal, "GLFW couldn't be initialised!");
exit(1);
}
mLogger(Information, "Creating GLFWwindow...");
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
mWindow = glfwCreateWindow(size.x, size.y, title.c_str(), NULL, NULL);
if (!mWindow) {
mLogger(Fatal, "Window could not be created!");
exit(1);
}
glfwMakeContextCurrent(mWindow);
mLogger(Information, "Preparing GLEW...");
glewExperimental = GL_FALSE;
GLenum err = glewInit();
if (err != GLEW_OK) {
mLogger(Fatal, "GLEW could not be created due to GLEW err " + std::to_string(err));
exit(err);
}
mLogger(Information, "Setting viewport...");
glViewport(0, 0, size.x, size.y);
mLogger(Information, "Finished setting up RGLCore!");
}
RGLCore::~RGLCore() {
glfwDestroyWindow(mWindow);
glfwTerminate();
}
// Draw
void RGLCore::clearScreen(Color col) {
float r = (float)(col.r) / 255, g = (float)(col.g) / 255, b = (float)(col.b) / 255, a = (float)(col.a) / 255;
glClearColor(r, g, b, a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void RGLCore::renderCurrent() {
glfwSwapBuffers(mWindow);
}
void RGLCore::drawText(Resource* resource, std::string text, IntVec2 pos, Color color) {}
void RGLCore::drawTexture(Texture* resource, float scale, IntVec2 pos) {}
// Pre and Post draw
void RGLCore::preDraw() {}
void RGLCore::postDraw() {}
void RGLCore::update() {
mKeepOpen = !glfwWindowShouldClose(mWindow);
glfwPollEvents();
}
void RGLCore::setWindowTitle(std::string title) {
glfwSetWindowTitle(mWindow, title.c_str());
}
}