JGL Render Pass
This commit is contained in:
@@ -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})
|
||||
|
@@ -53,6 +53,7 @@ public:
|
||||
void initGL() const;
|
||||
void loadConfig();
|
||||
static void init();
|
||||
void jglRenderPass();
|
||||
void preRender();
|
||||
void render();
|
||||
static void postRender();
|
||||
|
@@ -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) {}
|
||||
|
13
src/demo/RuntimeTest/include/fonts.h
Normal file
13
src/demo/RuntimeTest/include/fonts.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <JGL/JGL.h>
|
||||
#include <JGL/Colors.h>
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
#include <Redacted3D/types/entity/camera.h>
|
||||
#include <fonts.h>
|
||||
|
||||
class FreeCam : public Camera {
|
||||
public:
|
||||
void pre_render() override;
|
||||
void jglRenderPass() override;
|
||||
};
|
@@ -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);
|
||||
|
@@ -1,4 +1,5 @@
|
||||
#include <freeCam.h>
|
||||
#include <JGL/Colors.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
@@ -1,10 +1,7 @@
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <Redacted3D/engine/engine.h>
|
||||
#include <Redacted3D/engine/utils/instanceOf.h>
|
||||
#include <Redacted3D/types/entity/camera.h>
|
||||
#include <JGL/JGL.h>
|
||||
#include <JGL/Colors.h>
|
||||
|
||||
using namespace J3ML;
|
||||
|
||||
@@ -85,29 +82,23 @@ void Engine::initGL() const {
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
}
|
||||
|
||||
void Engine::init()
|
||||
{
|
||||
void Engine::init() {
|
||||
engine->window->Open();
|
||||
engine->initGL();
|
||||
engine->loadConfig();
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
JGL::InitTextEngine();
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::preRender()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Engine::render()
|
||||
{
|
||||
void Engine::render() {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
if(world->getActiveCamera() != nullptr)
|
||||
@@ -120,31 +111,36 @@ void Engine::initGL() const {
|
||||
|
||||
if (glGetError() != GL_NO_ERROR)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//TODO JGL rendering pass.
|
||||
void Engine::jglRenderPass() {
|
||||
glDisable(GL_LIGHTING);
|
||||
JGL::J3D::DrawString3D(JGL::Colors::White, std::to_string((int) framerate()), {0.5f, 0, 0.5f}, 0.0125f);
|
||||
glEnable(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();
|
||||
|
||||
void Engine::postRender()
|
||||
{
|
||||
for (auto& e : world->GetChildren())
|
||||
if (e->draw)
|
||||
if (auto* c = dynamic_cast<Camera*>(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()
|
||||
{
|
||||
void Engine::renderPass() {
|
||||
preRender();
|
||||
render();
|
||||
jglRenderPass();
|
||||
postRender();
|
||||
}
|
||||
}
|
||||
|
||||
[[noreturn]] void Engine::renderLoop()
|
||||
{
|
||||
[[noreturn]] void Engine::renderLoop() {
|
||||
while (true) {
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
renderPass();
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user