From 5196401dd3c00bbe4f004b250cfd5db9ebf5436b Mon Sep 17 00:00:00 2001 From: Redacted Date: Fri, 5 Jul 2024 22:32:42 -0400 Subject: [PATCH] JGL Render Pass --- CMakeLists.txt | 4 +- include/Redacted3D/engine/engine.h | 1 + include/Redacted3D/types/entity/entity.h | 2 +- src/demo/RuntimeTest/include/fonts.h | 13 +++ src/demo/RuntimeTest/include/freeCam.h | 2 + src/demo/RuntimeTest/main.cpp | 2 + src/demo/RuntimeTest/src/freeCam.cpp | 12 ++- src/engine/engine.cpp | 112 +++++++++++------------ src/types/entity/moby.cpp | 2 +- 9 files changed, 87 insertions(+), 63 deletions(-) create mode 100644 src/demo/RuntimeTest/include/fonts.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 743620e..23d3cd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ CPMAddPackage( CPMAddPackage( NAME JGL - URL https://git.redacted.cc/josh/JGL/archive/Prerelease-15.zip + URL https://git.redacted.cc/josh/JGL/archive/Prerelease-16.zip ) CPMAddPackage( @@ -80,7 +80,7 @@ CPMAddPackage( CPMAddPackage( NAME jlog - URL https://git.redacted.cc/josh/jlog/archive/Prerelease-8.zip + URL https://git.redacted.cc/josh/jlog/archive/Prerelease-12.zip ) add_library(Re3D SHARED ${SOURCES}) diff --git a/include/Redacted3D/engine/engine.h b/include/Redacted3D/engine/engine.h index a23c0ef..c4d1a98 100644 --- a/include/Redacted3D/engine/engine.h +++ b/include/Redacted3D/engine/engine.h @@ -53,6 +53,7 @@ public: void initGL() const; void loadConfig(); static void init(); + void jglRenderPass(); void preRender(); void render(); static void postRender(); diff --git a/include/Redacted3D/types/entity/entity.h b/include/Redacted3D/types/entity/entity.h index 911321b..48dd717 100644 --- a/include/Redacted3D/types/entity/entity.h +++ b/include/Redacted3D/types/entity/entity.h @@ -110,7 +110,6 @@ public: Vector3 getAngle(); void setAngle(const Vector3& a); void setAngle(float pitch, float yaw, float roll); - ///Removes an entity from the list, Checks if the assets are being used by any other entity. Removes them from their lists & deletes. Then deletes the entity. void erase(); bool draw = true; @@ -118,6 +117,7 @@ public: bool isCollidingWith(Entity* entity); virtual void pre_render() {} virtual void post_render() {} + virtual void jglRenderPass() {} ///The default rendering routine. Works for 99% of cases. virtual void render(); virtual void update(float elapsed) {} diff --git a/src/demo/RuntimeTest/include/fonts.h b/src/demo/RuntimeTest/include/fonts.h new file mode 100644 index 0000000..bf8c7be --- /dev/null +++ b/src/demo/RuntimeTest/include/fonts.h @@ -0,0 +1,13 @@ +#pragma once +#include +#include + +namespace Fonts { + inline int Jupiteroid = -1; + inline int ModeSeven = -1; + + inline void initFonts() { + Jupiteroid = JGL::LoadFont("assets/fonts/Jupiteroid/JupiteroidRegular.ttf"); + ModeSeven = JGL::LoadFont("assets/fonts/modeseven.ttf"); + } +} \ No newline at end of file diff --git a/src/demo/RuntimeTest/include/freeCam.h b/src/demo/RuntimeTest/include/freeCam.h index e10d98d..d277b64 100644 --- a/src/demo/RuntimeTest/include/freeCam.h +++ b/src/demo/RuntimeTest/include/freeCam.h @@ -1,7 +1,9 @@ #pragma once #include +#include class FreeCam : public Camera { public: void pre_render() override; + void jglRenderPass() override; }; \ No newline at end of file diff --git a/src/demo/RuntimeTest/main.cpp b/src/demo/RuntimeTest/main.cpp index 432c273..69b1f20 100644 --- a/src/demo/RuntimeTest/main.cpp +++ b/src/demo/RuntimeTest/main.cpp @@ -10,6 +10,8 @@ int main() engine->window = new ReWindow::RWindow("Re3D Test Application", 1152, 864, RenderingAPI::OPENGL); engine->world = new(World); Engine::init(); + JGL::InitTextEngine(); + Fonts::initFonts(); engine->window->setVsyncEnabled(false); engine->window->setResizable(false); engine->world->setAmbientLightColor(1.0f, 1.0f, 1.0f); diff --git a/src/demo/RuntimeTest/src/freeCam.cpp b/src/demo/RuntimeTest/src/freeCam.cpp index c75d973..82cd3da 100644 --- a/src/demo/RuntimeTest/src/freeCam.cpp +++ b/src/demo/RuntimeTest/src/freeCam.cpp @@ -1,4 +1,5 @@ #include +#include void FreeCam::pre_render() { if (engine->window->isKeyDown(Keys::W)) @@ -16,7 +17,7 @@ void FreeCam::pre_render() { if (engine->window->isKeyDown(Keys::Space)) vMove(4); - if (engine->window->isKeyDown(Keys::LShift)) + if (engine->window->isKeyDown(Keys::LeftShift)) vMove(-4); if (engine->window->isKeyDown(Keys::LeftArrow)) @@ -38,3 +39,12 @@ void FreeCam::pre_render() { setAngle(getAngle().x, getAngle().y, getAngle().z + 75.0f * engine->frameDelta); } + +void FreeCam::jglRenderPass() { + JGL::J3D::DrawString3D(JGL::Colors::White, "Entity Count: " + std::to_string(engine->world->getEntityCount()), {2.5,0,0}, -0.005125, 48, Fonts::ModeSeven); + JGL::J3D::DrawString3D(JGL::Colors::White, "Cam Pos: X: " + std::to_string(position.x) + " Y: " + std::to_string(position.y) + " Z: " + std::to_string(position.z), {4.75, 0.25,0}, -0.005125, 32, Fonts::ModeSeven); + + JGL::J3D::DrawString3D(JGL::Colors::White, "FPS: " + std::to_string(engine->framerate()), {0,0,0}, -0.005125, 48, Fonts::ModeSeven); + JGL::J3D::DrawString3D(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), {0,0.25,0}, -0.005125, 48, Fonts::ModeSeven); + JGL::J3D::DrawString3D(JGL::Colors::White, "Frame dT: " + std::to_string(engine->frameDelta), {0,0.5,0}, -0.005125, 48, Fonts::ModeSeven); +} diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 5f905c5..4788800 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1,10 +1,7 @@ #include #include #include -#include #include -#include -#include using namespace J3ML; @@ -85,66 +82,65 @@ void Engine::initGL() const { glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); } - void Engine::init() - { - engine->window->Open(); - engine->initGL(); - engine->loadConfig(); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - JGL::InitTextEngine(); - } +void Engine::init() { + engine->window->Open(); + engine->initGL(); + engine->loadConfig(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); +} - void Engine::preRender() - { - engine->window->pollEvents(); - engine->frameCount++; - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +void Engine::preRender() { + engine->window->pollEvents(); + engine->frameCount++; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - for (auto& e : world->GetChildren()) - e->pre_render(); - } + for (auto& e : world->GetChildren()) + e->pre_render(); +} + +void Engine::render() { + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + if(world->getActiveCamera() != nullptr) + world->getActiveCamera()->render(); + + for (auto& e : world->GetChildren()) + if (e->draw) + if (auto* c = dynamic_cast(e); c == nullptr) //If it's not a camera. + e->render(); + + if (glGetError() != GL_NO_ERROR) + exit(0); +} + +void Engine::jglRenderPass() { + glDisable(GL_LIGHTING); + ///If elements are attached to a camera that's not the active one then they shouldn't be drawn. + if(world->getActiveCamera() != nullptr) + world->getActiveCamera()->jglRenderPass(); + + for (auto& e : world->GetChildren()) + if (e->draw) + if (auto* c = dynamic_cast(e); c == nullptr) //If it's not a camera. + e->jglRenderPass(); + glEnable(GL_LIGHTING); +} + +void Engine::postRender() { + for (auto& e : engine->world->GetChildren()) + e->post_render(); + ReWindow::RWindow::glSwapBuffers(); +} +void Engine::renderPass() { + preRender(); + render(); + jglRenderPass(); + postRender(); +} - void Engine::render() - { - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - if(world->getActiveCamera() != nullptr) - world->getActiveCamera()->render(); - - for (auto& e : world->GetChildren()) - if (e->draw) - if (auto* c = dynamic_cast(e); c == nullptr) //If it's not a camera. - e->render(); - - if (glGetError() != GL_NO_ERROR) - exit(0); - - //TODO JGL rendering pass. - glDisable(GL_LIGHTING); - JGL::J3D::DrawString3D(JGL::Colors::White, std::to_string((int) framerate()), {0.5f, 0, 0.5f}, 0.0125f); - glEnable(GL_LIGHTING); - } - - void Engine::postRender() - { - for (auto& e : engine->world->GetChildren()) - e->post_render(); - - ReWindow::RWindow::glSwapBuffers(); - } - - - void Engine::renderPass() - { - preRender(); - render(); - postRender(); - } - -[[noreturn]] void Engine::renderLoop() -{ +[[noreturn]] void Engine::renderLoop() { while (true) { auto start = std::chrono::high_resolution_clock::now(); renderPass(); diff --git a/src/types/entity/moby.cpp b/src/types/entity/moby.cpp index 7fc03ae..48508a1 100644 --- a/src/types/entity/moby.cpp +++ b/src/types/entity/moby.cpp @@ -37,7 +37,7 @@ void Moby::vAngleMove(float speed) { } //Returns the position we'd be at *if* we did a movement. -Direction Moby::projectedHorizontalMove(Vector3 a, float vel) { +Position Moby::projectedHorizontalMove(Vector3 a, float vel) { Position p; p.z -= (vel*engine->frameDelta) * a.x; p.x += (vel*engine->frameDelta) * a.z;