Fix JGL text being broken
This commit is contained in:
@@ -53,7 +53,7 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME JGL
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-11.zip
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Release-12.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
|
@@ -8,15 +8,7 @@
|
||||
#include <engine/world.h>
|
||||
#include <rewindow/types/window.h>
|
||||
|
||||
|
||||
enum class GAMESTATE: uint8_t {
|
||||
NORMAL = 0, //Gameplay.
|
||||
IN_MAIN_MENU = 1,
|
||||
IN_PAUSE_MENU = 2,
|
||||
IN_LEVEL_ANIMATION = 3, //A cutscene which moves entities in the world and cannot be interrupted.
|
||||
};
|
||||
|
||||
enum class ENGINE_ERROR_CODE: uint8_t {
|
||||
enum class ENGINE_ERROR_CODE: u8 {
|
||||
NO_ERROR = 0,
|
||||
ANIM_OUT_OF_BOUNDS = 1,
|
||||
TEXTURE_NOT_FOUND = 2,
|
||||
@@ -33,8 +25,8 @@ enum class ENGINE_ERROR_CODE: uint8_t {
|
||||
struct EngineError {
|
||||
ENGINE_ERROR_CODE error;
|
||||
bool critical;
|
||||
|
||||
};
|
||||
|
||||
class Engine {
|
||||
private:
|
||||
EngineError error;
|
||||
@@ -44,39 +36,31 @@ public:
|
||||
World* world;
|
||||
void setError(ENGINE_ERROR_CODE code, bool critical);
|
||||
EngineError getError();
|
||||
//GAMESTATE gameState = GAMESTATE::NORMAL;
|
||||
//uint16_t minimumTickDelta = 15625;
|
||||
//float tickDelta = NULL;
|
||||
bool fullscreen;
|
||||
bool debug = true;
|
||||
bool useVBO = true;
|
||||
uint64_t tickCount = 0;
|
||||
uint64_t frameCount = 0;
|
||||
u64 tickCount = 0;
|
||||
u64 frameCount = 0;
|
||||
float nearPlane = 0.001f;
|
||||
float frameDelta = 0;
|
||||
GLenum glError = GL_NO_ERROR;
|
||||
float nearPlane = 0.01f;
|
||||
float farPlane = 100.0f;
|
||||
float fov = 75;
|
||||
[[nodiscard]] float framerate() const;
|
||||
static void takeScreenshot() ;
|
||||
void quit() const;
|
||||
void quit (ENGINE_ERROR_CODE code);
|
||||
void quit (ENGINE_ERROR_CODE code) const;
|
||||
static float getGLVersion();
|
||||
void initGL() const;
|
||||
void loadConfig();
|
||||
|
||||
static void init();
|
||||
void preRender();
|
||||
void render();
|
||||
void postRender();
|
||||
static void postRender();
|
||||
void renderPass();
|
||||
void renderLoop();
|
||||
[[noreturn]] void renderLoop();
|
||||
|
||||
Engine() {
|
||||
//window = new(ReWindow::RWindow);
|
||||
//world = new(World);
|
||||
error = {ENGINE_ERROR_CODE::NO_ERROR, false};
|
||||
}
|
||||
};
|
||||
|
||||
inline auto* engine = new(Engine);
|
@@ -12,7 +12,7 @@ using J3ML::LinearAlgebra::Vector2;
|
||||
// TODO: Move data to Entity / or rename to DataModelEntry
|
||||
struct ByteArray
|
||||
{
|
||||
std::vector<uint8_t> bytes;
|
||||
std::vector<u8> bytes;
|
||||
};
|
||||
|
||||
class Serializable
|
||||
|
@@ -87,7 +87,7 @@ protected:
|
||||
J3ML::LinearAlgebra::Position position; // X Y Z
|
||||
public:
|
||||
std::string uuid;
|
||||
uint32_t ticksAlive; //At 64tps it'd take 776 days to overflow.
|
||||
u32 ticksAlive; //At 64tps it'd take 776 days to overflow.
|
||||
[[nodiscard]] Vector3 GetPos() const;
|
||||
void SetPos(const Vector3& rhs);
|
||||
Matrix4x4 GetMatrix() const;
|
||||
|
@@ -8,8 +8,8 @@
|
||||
class Ball : public Moby {
|
||||
public:
|
||||
bool alive;
|
||||
uint8_t health;
|
||||
uint8_t state;
|
||||
u8 health;
|
||||
u8 state;
|
||||
Vector3 cameraTarget;//The point where the 3rd-person camera will want to look at.
|
||||
//Each type of entity will have an "update" function and a "render" function.
|
||||
//These will be declared in each type of entity and not in the base entity because
|
||||
|
@@ -8,8 +8,8 @@
|
||||
class Cube : public Moby {
|
||||
public:
|
||||
bool alive;
|
||||
uint8_t health;
|
||||
uint8_t state;
|
||||
u8 health;
|
||||
u8 state;
|
||||
Vector3 cameraTarget;//The point where the 3rd-person camera will want to look at.
|
||||
//Each type of entity will have an "update" function and a "render" function.
|
||||
//These will be declared in each type of entity and not in the base entity because
|
||||
|
@@ -14,7 +14,7 @@ int main()
|
||||
engine->init();
|
||||
engine->window->setVsyncEnabled(false);
|
||||
engine->window->setResizable(false);
|
||||
engine->world->setAmbientLightColor(1.2f, 1.2f, 1.2f, 0.0f);
|
||||
engine->world->setAmbientLightColor(1.0f, 1.0f, 1.0f, 0.0f);
|
||||
Shader test("test", engine->workingDir + "/assets/shaders/defaultVertex.glsl", engine->workingDir + "/assets/shaders/defaultFragment.glsl");
|
||||
|
||||
auto* camera = new(FreeCam);
|
||||
|
@@ -11,8 +11,6 @@ void Cube::pre_render() {
|
||||
angle.x = angle.x + 24*engine->frameDelta;
|
||||
angle.y = angle.y + 24*engine->frameDelta;
|
||||
angle.z = angle.z + 24*engine->frameDelta;
|
||||
|
||||
//AABB aabb = Collision::genMinimallyEnclosingAABB(getGeometry());
|
||||
}
|
||||
|
||||
void Cube::update(float elapsed) {
|
||||
|
@@ -1,11 +1,6 @@
|
||||
#include <engine/engine.h>
|
||||
#include <glad/glad.h>
|
||||
#include <sstream>
|
||||
#include <engine/world.h>
|
||||
#include <thread>
|
||||
#include <types/entity/camera.h>
|
||||
#include <types/entity/skybox.h>
|
||||
|
||||
#include <engine/engine.h>
|
||||
#include <JGL/JGL.h>
|
||||
#include <JGL/Colors.h>
|
||||
|
||||
@@ -58,12 +53,14 @@ void outputErrorCode() {
|
||||
break;
|
||||
case ENGINE_ERROR_CODE::TEXTURE_ERASED_WHILE_IN_USE:
|
||||
std::cerr << "TEXTURE ERASED WHILE IN USE" << std::endl;
|
||||
case ENGINE_ERROR_CODE::VERTEX_ARRAY_ERASED_WHILE_IN_USE:
|
||||
std::cerr << "VERTEX ARRAY ERASED WHILE IN USE" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
float Engine::getGLVersion() {
|
||||
const std::string full_gl_ver = (const char*) (glGetString(GL_VERSION));
|
||||
const std::string gl_major = full_gl_ver.substr(0, 3);
|
||||
const std::string gl_major = std::string(((const char*) (glGetString(GL_VERSION)))).substr(0, 3);
|
||||
return std::stof(gl_major);
|
||||
}
|
||||
|
||||
@@ -73,19 +70,18 @@ void Engine::initGL() const {
|
||||
glLoadIdentity();
|
||||
auto window_size = window->getSize();
|
||||
auto aspect = (float) window_size[0] / (float) window_size[1];
|
||||
glMultMatrixf(perspective(this->fov, aspect, nearPlane, farPlane).data());
|
||||
//glMultMatrixf(Matrix4x4::OpenGLPerspProjRH(nearPlane, farPlane, window_size.x, window_size.y).ptr());
|
||||
glMultMatrixf(perspective(fov, aspect, nearPlane, farPlane).data());
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glViewport(0,0,window->getSize().x,window->getSize().y);
|
||||
glViewport(0,0,window_size.x,window_size.y);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glDepthMask(GL_TRUE);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_VERTEX_ARRAY);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
}
|
||||
|
||||
@@ -100,11 +96,6 @@ void Engine::initGL() const {
|
||||
|
||||
void Engine::preRender()
|
||||
{
|
||||
// TODO: Move into Update(dt)
|
||||
// TODO: Create FixedUpdate(step)
|
||||
|
||||
|
||||
//std::cout << engine->frameCount << std::endl;
|
||||
engine->window->pollEvents();
|
||||
engine->frameCount++;
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@@ -119,20 +110,17 @@ void Engine::initGL() const {
|
||||
{
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
//glEnable(GL_BLEND);
|
||||
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
for (auto& e : engine->world->GetChildren()) {
|
||||
for (auto& e : engine->world->GetChildren())
|
||||
if (e->draw)
|
||||
e->render();
|
||||
}
|
||||
engine->glError = glGetError();
|
||||
if (engine->glError != GL_NO_ERROR) {
|
||||
std::cerr << "OpenGL: " << glError << std::endl;
|
||||
|
||||
if (glGetError() != GL_NO_ERROR)
|
||||
exit(0);
|
||||
}
|
||||
glColor4f(0.f, 0.f, 0.f, 0.f);
|
||||
JGL::J3D::DrawString3D(JGL::Colors::Blue, "JGL Sample Text", {0.5f, 0, 0.5f}, 0.1f);
|
||||
//JGL::J2D::FillRect2D(JGL::Colors::Purples::BlueViolet, {0.f, -5.f}, {24, 24});
|
||||
|
||||
//TODO JGL rendering pass.
|
||||
glDisable(GL_LIGHTING);
|
||||
JGL::J3D::DrawString3D(JGL::Colors::Blue, "Example Text", {0.5f, 0, 0.5f}, 0.025f);
|
||||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
void Engine::postRender()
|
||||
@@ -140,12 +128,7 @@ void Engine::initGL() const {
|
||||
for (auto& e : engine->world->GetChildren())
|
||||
e->post_render();
|
||||
|
||||
//Reset all the transformations for the next frame.
|
||||
glPushMatrix();
|
||||
glPopMatrix();
|
||||
ReWindow::RWindow::glSwapBuffers();
|
||||
if (engine->frameCount == 1000)
|
||||
engine->takeScreenshot();
|
||||
}
|
||||
|
||||
|
||||
@@ -156,33 +139,93 @@ void Engine::initGL() const {
|
||||
postRender();
|
||||
}
|
||||
|
||||
void Engine::renderLoop()
|
||||
[[noreturn]] void Engine::renderLoop()
|
||||
{
|
||||
while (true) {
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
renderPass();
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
float dT = (std::chrono::duration_cast<std::chrono::microseconds>(stop - start).count());
|
||||
|
||||
//If we have more than 1000 fps.
|
||||
if (dT < 1000 && engine->window->getFlag(RWindowFlags::IN_FOCUS)) {
|
||||
int remaining = 1000 - dT;
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(remaining));
|
||||
dT += remaining;
|
||||
float dT = std::chrono::duration<float, std::micro>(stop - start).count();
|
||||
bool inFocus = engine->window->getFlag(RWindowFlags::IN_FOCUS);
|
||||
|
||||
if (dT < 1000.0f && inFocus) {
|
||||
auto remaining = std::chrono::microseconds(static_cast<int>(1000.0f - dT));
|
||||
std::this_thread::sleep_for(remaining);
|
||||
dT += std::chrono::duration<float, std::micro>(remaining).count();
|
||||
}
|
||||
//Decrease framerate when focus is lost.
|
||||
if (!engine->window->getFlag(RWindowFlags::IN_FOCUS)) {
|
||||
int remaining = 41666.67f - dT;
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(remaining));
|
||||
dT += remaining;
|
||||
|
||||
// Decrease framerate when focus is lost.
|
||||
if (!inFocus) {
|
||||
auto remaining = std::chrono::microseconds(static_cast<int>(41666.67f - dT));
|
||||
std::this_thread::sleep_for(remaining);
|
||||
dT += std::chrono::duration<float, std::micro>(remaining).count();
|
||||
}
|
||||
engine->frameDelta = (dT / 1000000);
|
||||
engine->frameDelta = dT / 1000000.0f;
|
||||
}
|
||||
}
|
||||
|
||||
float Engine::framerate() const
|
||||
{
|
||||
return 1.f / this->frameDelta;
|
||||
float Engine::framerate() const {
|
||||
return 1.f / frameDelta;
|
||||
}
|
||||
|
||||
void Engine::loadConfig() {
|
||||
std::ifstream file("cfg/engine.cfg");
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "Couldn't load engine config." << std::endl;
|
||||
quit();
|
||||
return;
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
std::istringstream stream(line);
|
||||
std::string prefix;
|
||||
stream >> prefix;
|
||||
//if (prefix == "Resolution:") {
|
||||
//int x, y;
|
||||
//stream >> x >> y;
|
||||
//window->setSize(x,y);
|
||||
//glViewport(0,0,x,y);
|
||||
//}
|
||||
if (prefix == "Fullscreen:")
|
||||
stream >> fullscreen;
|
||||
if (prefix == "Debug:")
|
||||
stream >> debug;
|
||||
if (prefix == "CameraFOV:")
|
||||
stream >> fov;
|
||||
}
|
||||
//If we have a window already.
|
||||
//if (window != NULL) {
|
||||
//window->destroyWindow();
|
||||
//Some window managers won't handle destroying and remaking the window with zero delay very well.
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
//initVideo();
|
||||
//initGL();
|
||||
//}
|
||||
|
||||
if (debug) {
|
||||
std::cout << "Fullscreen: " << fullscreen << std::endl;
|
||||
std::cout << "Resolution: " << window->getSize()[0] << "x" << window->getSize()[1] << std::endl;
|
||||
std::cout << "Camera FOV: " << fov << std::endl;
|
||||
std::cout << "Debug: " << debug << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::setError(ENGINE_ERROR_CODE code, bool critical) {
|
||||
error.error = code;
|
||||
error.critical = critical;
|
||||
outputErrorCode();
|
||||
if (error.critical)
|
||||
engine->quit(code);
|
||||
}
|
||||
|
||||
EngineError Engine::getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
void Engine::quit(ENGINE_ERROR_CODE code) const {
|
||||
window->destroyWindow();
|
||||
exit((int) code);
|
||||
}
|
||||
|
||||
void Engine::takeScreenshot() {
|
||||
@@ -229,60 +272,4 @@ void Engine::takeScreenshot() {
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
void Engine::loadConfig() {
|
||||
std::ifstream file("cfg/engine.cfg");
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "Couldn't load engine config." << std::endl;
|
||||
this->quit();
|
||||
return;
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
std::istringstream stream(line);
|
||||
std::string prefix;
|
||||
stream >> prefix;
|
||||
//if (prefix == "Resolution:") {
|
||||
//int x, y;
|
||||
//stream >> x >> y;
|
||||
//window->setSize(x,y);
|
||||
//glViewport(0,0,x,y);
|
||||
//}
|
||||
if (prefix == "Fullscreen:")
|
||||
stream >> fullscreen;
|
||||
if (prefix == "Debug:")
|
||||
stream >> debug;
|
||||
if (prefix == "CameraFOV:")
|
||||
stream >> fov;
|
||||
}
|
||||
//If we have a window already.
|
||||
//if (window != NULL) {
|
||||
//window->destroyWindow();
|
||||
//Some window managers won't handle destroying and remaking the window with zero delay very well.
|
||||
//std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
//initVideo();
|
||||
//initGL();
|
||||
//}
|
||||
std::cout << "Fullscreen: " << fullscreen << std::endl;
|
||||
std::cout << "Resolution: " << window->getSize()[0] << "x" << window->getSize()[1] << std::endl;
|
||||
std::cout << "Camera FOV: " << fov << std::endl;
|
||||
std::cout << "Debug: " << debug << std::endl;
|
||||
}
|
||||
|
||||
void Engine::setError(ENGINE_ERROR_CODE code, bool critical) {
|
||||
error.error = code;
|
||||
error.critical = critical;
|
||||
outputErrorCode();
|
||||
if (error.critical)
|
||||
engine->quit(code);
|
||||
|
||||
}
|
||||
|
||||
EngineError Engine::getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
void Engine::quit(ENGINE_ERROR_CODE code) {
|
||||
window->destroyWindow();
|
||||
exit((int) code);
|
||||
}
|
||||
}
|
@@ -41,7 +41,7 @@ void VertexArray::draw() {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
if (engine->useVBO && vbo !=0 && tbo !=0 && ebo !=0) {
|
||||
if (engine->useVBO && vbo != 0 && tbo != 0 && ebo != 0) {
|
||||
//Vertices
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
glVertexPointer(3, GL_FLOAT, 0, nullptr);
|
||||
|
Reference in New Issue
Block a user