update engine components

This commit is contained in:
2024-08-21 13:38:58 -04:00
parent 22711d1db1
commit 145346fac3
15 changed files with 61 additions and 60 deletions

View File

@@ -29,7 +29,7 @@ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
CPMAddPackage(
NAME ReWindow
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-3.zip
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-12.zip
)
CPMAddPackage(
@@ -44,17 +44,17 @@ CPMAddPackage(
CPMAddPackage(
NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/Release-2.2.zip
URL https://git.redacted.cc/josh/j3ml/archive/Release-3.0.zip
)
CPMAddPackage(
NAME JGL
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-25.zip
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-31.zip
)
CPMAddPackage(
NAME ReTexture
URL https://git.redacted.cc/Redacted/ReTexture/archive/Prerelease-2.zip
URL https://git.redacted.cc/Redacted/ReTexture/archive/Release-1.2.zip
)
CPMAddPackage(
@@ -74,7 +74,7 @@ CPMAddPackage(
CPMAddPackage(
NAME Collage
URL https://git.redacted.cc/Redacted/Collage/archive/v0.5.zip
URL https://git.redacted.cc/Redacted/Collage/archive/v0.6.zip
)
CPMAddPackage(
@@ -97,7 +97,6 @@ target_include_directories(Re3D PUBLIC
${ReWindow_SOURCE_DIR}/include
#${ReHardwareID_SOURCE_DIR}/include
${J3ML_SOURCE_DIR}/include
${ReTexture_SOURCE_DIR}/include
${glad_SOURCE_DIR}/include
${UUID_SOURCE_DIR}/include
#${archive_SOURCE_DIR}/include
@@ -110,11 +109,11 @@ set_target_properties(Re3D PROPERTIES LINKER_LANGUAGE CXX)
if (UNIX AND NOT APPLE)
find_package(OpenGL REQUIRED)
target_link_libraries(Re3D PUBLIC Event ReWindowLibrary ReTexture J3ML GL glad Collage JGL jlog)
target_link_libraries(Re3D PUBLIC Event ReWindowLibrary J3ML GL glad Collage JGL jlog)
endif()
if (WIN32)
target_link_libraries(Re3D PUBLIC Event ReWindowLibrary ReTexture J3ML glad Collage JGL jlog)
target_link_libraries(Re3D PUBLIC Event ReWindowLibrary J3ML glad Collage JGL jlog)
endif()
include(src/demo/RuntimeTest/CMakeLists.txt)

View File

@@ -1,6 +1,6 @@
#pragma once
#include <Redacted3D/types/vertex.h>
#include <J3ML/Geometry.h>
#include <J3ML/Geometry.hpp>
using J3ML::Geometry::AABB;
using J3ML::Geometry::OBB;

View File

@@ -4,7 +4,7 @@
#include <Redacted3D/types/texture.h>
#include <Redacted3D/types/shader.h>
#include <Redacted3D/types/entity/baseEntity.h>
#include <J3ML/LinearAlgebra/Vector3.h>
#include <J3ML/LinearAlgebra/Vector3.hpp>
using J3ML::LinearAlgebra::Vector3;
using J3ML::LinearAlgebra::Vector2;

View File

@@ -2,7 +2,7 @@
#include <Redacted3D/types/entity/3D/moby.h>
#include <Redacted3D/engine/engine.h>
#include <glad/glad.h>
#include <J3ML/Geometry.h>
#include <J3ML/Geometry.hpp>
using J3ML::LinearAlgebra::Matrix4x4;
using J3ML::Geometry::Frustum;

View File

@@ -3,8 +3,8 @@
#include <Redacted3D/types/entity/baseEntity.h>
#include <Redacted3D/types/vertex.h>
#include <Redacted3D/types/texture.h>
#include <J3ML/LinearAlgebra/Matrix4x4.h>
#include <J3ML/LinearAlgebra/Vector3.h>
#include <J3ML/LinearAlgebra/Matrix4x4.hpp>
#include <J3ML/LinearAlgebra/Vector3.hpp>
#include <Redacted3D/engine/collision.h>
//#include <archive.h>

View File

@@ -1,7 +1,7 @@
#pragma once
#include <vector>
#include <string>
#include <J3ML/J3ML.h>
#include <J3ML/J3ML.hpp>
class BaseEntity {
protected:

View File

@@ -3,19 +3,18 @@
#include <glad/glad.h>
#include <vector>
#include <string>
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra.hpp>
#include <JGL/Texture.h>
#include <chrono>
//Forward declaration of entity.
class Entity;
//Base texture. One texture.
class Texture {
class Texture : public JGL::Texture {
public:
///Reference counter.
std::vector<Entity*> usedBy;
///The id OpenGL uses to keep track of where the texture is in vram.
GLuint id = 0;
///Loads a texture for a given entity type from a file you specify.
void load(Entity* entity, const std::string& file, bool storeOnTextureList);
///removes texture from texture list and deletes it.

View File

@@ -1,7 +1,7 @@
#pragma once
#include <vector>
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra.hpp>
class Moby;

View File

@@ -3,9 +3,9 @@
#include <vector>
#include <Collage/types/animation.h>
#include <Collage/types/model.h>
#include <J3ML/LinearAlgebra/Vector3.h>
#include <J3ML/LinearAlgebra/Vector2.h>
#include <J3ML/Geometry/OBB.h>
#include <J3ML/LinearAlgebra/Vector3.hpp>
#include <J3ML/LinearAlgebra/Vector2.hpp>
#include <J3ML/Geometry/OBB.hpp>
#include <glad/glad.h>
///Forward declaration of entity.

View File

@@ -1,6 +1,5 @@
#pragma once
#include <JGL/JGL.h>
#include <JGL/Colors.h>
namespace Fonts {
inline JGL::Font Jupiteroid;

View File

@@ -38,6 +38,7 @@ int main()
skybox->setAngle(0,0,0);
skybox->SetParent(engine->world);
JGL::J3D::Init(engine->window->getSize(), engine->fov, engine->farPlane);
engine->renderLoop();
}

View File

@@ -1,5 +1,5 @@
#include <freeCam.h>
#include <JGL/Colors.h>
#include <mcolor.h>
void FreeCam::pre_render() {
if (engine->window->isKeyDown(Keys::W))
@@ -46,16 +46,16 @@ void FreeCam::jglRenderPass() {
J3D::Begin();
glDisable(GL_CULL_FACE);
J3D::DrawString(JGL::Colors::Red, "Text", {0, -2, 0}, textAngle, 4.f, 32, Fonts::Jupiteroid);
J3D::DrawString(Colors::Red, "Text", {0, -2, 0}, textAngle, 4.f, 32, Fonts::Jupiteroid);
glEnable(GL_CULL_FACE);
J3D::End();
J2D::Begin();
J2D::FillRect({255,0,0,128}, {0, 72}, {100, 100});
J2D::FillCircle(JGL::Colors::White, {16, 128}, 12, 16);
J2D::FillCircle(Colors::White, {16, 128}, 12, 16);
J2D::DrawString(JGL::Colors::White, "Framerate: " + std::to_string((int) engine->framerate()), 0, 0, 1, 16, Fonts::Jupiteroid);
J2D::DrawString(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, 17, 1,16, Fonts::Jupiteroid);
J2D::DrawString(JGL::Colors::White, "Position: " + std::to_string(position.x) + " " + std::to_string(position.y) + " " + std::to_string(position.z), 0, 33, 1,16, Fonts::Jupiteroid);
J2D::DrawString(JGL::Colors::White, "ViewAngle: " + std::to_string(getAngle().x) + " " + std::to_string(getAngle().y) + " " + std::to_string(getAngle().z), 0, 50, 1,16, Fonts::Jupiteroid);
J2D::DrawString(Colors::White, "Framerate: " + std::to_string((int) engine->framerate()), 0, 0, 1, 16, Fonts::Jupiteroid);
J2D::DrawString(Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, 17, 1,16, Fonts::Jupiteroid);
J2D::DrawString(Colors::White, "Position: " + std::to_string(position.x) + " " + std::to_string(position.y) + " " + std::to_string(position.z), 0, 33, 1,16, Fonts::Jupiteroid);
J2D::DrawString(Colors::White, "ViewAngle: " + std::to_string(getAngle().x) + " " + std::to_string(getAngle().y) + " " + std::to_string(getAngle().z), 0, 50, 1,16, Fonts::Jupiteroid);
J2D::End();
}

View File

@@ -61,14 +61,14 @@ void Entity::loadTexture(const std::string& file) {
for (const auto* e : engine->world->GetChildren())
if (instanceOf(this, e))
return;
Texture texture(this, file.c_str(), true);
Texture(this, file.c_str(), true);
}
void Entity::loadMultiTexture(const std::vector<std::string>& files) {
for (const auto* e : engine->world->GetChildren())
if (instanceOf(this, e))
return;
MultiTexture texture(this, files, true);
MultiTexture(this, files, true);
}
void Entity::loadMotionTexture(const std::vector<std::string>& files, u16 frameDelta, bool doAnim) {
@@ -76,6 +76,7 @@ void Entity::loadMotionTexture(const std::vector<std::string>& files, u16 frameD
if (instanceOf(this, e))
return;
MotionTexture(this, files, frameDelta, true, doAnim);
}
void Entity::loadGeometry(const std::string& file) {
@@ -107,26 +108,26 @@ Texture* Entity::getTexture() {
return nullptr;
}
inline Texture* baseTexture = new Texture;
inline Texture* baseTexture = new Texture();
void Entity::render() {
if (!baseTexture) {
Texture t;
glGenTextures(1, &t.id);
glBindTexture(GL_TEXTURE_2D, t.id);
GLuint handle;
glGenTextures(1, &handle);
glBindTexture(GL_TEXTURE_2D, handle);
unsigned char whitePixel[4] = { 255, 255, 255, 255};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, whitePixel);
Color4 whitePixel = {255, 255, 255, 255};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, &whitePixel);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glActiveTexture(0);
baseTexture = new Texture(t);
baseTexture->SetTextureHandle(handle);
}
MultiTexture texture;
texture.id = baseTexture->id;
texture.SetTextureHandle(baseTexture->GetGLTextureHandle());
if (auto* t = dynamic_cast<MultiTexture*>(getTexture())) {
texture.multi.emplace_back(*t);
@@ -154,7 +155,7 @@ void Entity::render() {
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, texture.id);
glBindTexture(GL_TEXTURE_2D, texture.GetGLTextureHandle());
//Texture unit mode.
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
@@ -185,7 +186,7 @@ void Entity::render() {
//Texture unit mode.
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glBindTexture(GL_TEXTURE_2D, t.id);
glBindTexture(GL_TEXTURE_2D, t.GetGLTextureHandle());
i++;
}
getGeometry()->draw();

View File

@@ -10,7 +10,7 @@ void Skybox::pre_render() {
void Skybox::render() {
glPushMatrix();
glTranslatef(position.x ,position.y, position.z);
glBindTexture(GL_TEXTURE_2D, getTexture()->id);
glBindTexture(GL_TEXTURE_2D, getTexture()->GetGLTextureHandle());
glCullFace(GL_FRONT);
glScalef(getScale().x, getScale().y, getScale().z);
getGeometry()->draw();

View File

@@ -1,16 +1,18 @@
#include <ReTexture/rTexture.h>
#include <ReTexture/Texture.h>
#include <Redacted3D/types/texture.h>
#include <Redacted3D/engine/engine.h>
void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureList) {
auto* texture = new RTexture(file, {RTextureFlag::INVERT_Y});
//TODO use JGL implementation of texture.
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
if (texture->format == RTextureFormat::RGBA)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->width, texture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixelData.data());
if (texture->format == RTextureFormat::RGB)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->width, texture->height, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixelData.data());
void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureList) {
auto* texture = new ReTexture::SoftwareTexture(file, {ReTexture::TextureFlag::INVERT_Y});
glGenTextures(1, &texture_handle);
glBindTexture(GL_TEXTURE_2D, texture_handle);
if (texture->getTextureFormat() == ReTexture::TextureFormat::RGBA)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->getWidth(), texture->getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->pixelData.data());
if (texture->getTextureFormat() == ReTexture::TextureFormat::RGB)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture->getWidth(), texture->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixelData.data());
delete texture;
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -20,10 +22,10 @@ void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureL
glBindTexture(GL_TEXTURE_2D, 0);
//If we can't load the missing texture
if (file == "assets/textures/missing.png" && id == 0)
if (file == "assets/textures/missing.png" && texture_handle == 0)
engine->setError(ENGINE_ERROR_CODE::TEXTURE_NOT_FOUND, true);
if (id == 0)
if (texture_handle == 0)
engine->setError(ENGINE_ERROR_CODE::TEXTURE_NOT_FOUND, false),
load(entity, "assets/textures/missing.png", false);
@@ -36,12 +38,12 @@ void Texture::erase() {
Texture::erase(this);
}
Texture::Texture(Entity* entity, const char *filePath, bool storeOnTextureList) {
Texture::Texture(Entity* entity, const char* filePath, bool storeOnTextureList) {
load(entity, filePath, storeOnTextureList);
}
void Texture::erase(Texture* texture) const {
glDeleteTextures(1, &texture->id);
glDeleteTextures(1, &texture->texture_handle);
//If texture is being deleted while in use.
//It won't crash the program. But it'll cause the texture to be reloaded from disk unnecessarily.
@@ -50,7 +52,7 @@ void Texture::erase(Texture* texture) const {
if (auto* t = dynamic_cast<MultiTexture*>(texture))
for (auto &m : t->multi)
glDeleteTextures(1, &m.id);
glDeleteTextures(1, &m.texture_handle);
for (int i = 0; i < engine->world->textureList.size(); i++)
if (engine->world->textureList[i] == texture)
@@ -60,11 +62,11 @@ void Texture::erase(Texture* texture) const {
MultiTexture::MultiTexture(Entity* entity, const std::vector<std::string>& textures, bool storeOnTextureList) {
Texture base;
for (const auto& t : textures) {
if (id != 0)
if (texture_handle != 0)
multi.emplace_back(entity, t.c_str(), false);
else
base = Texture(entity, t.c_str(), false),
id = base.id,
texture_handle = base.GetGLTextureHandle(),
usedBy = base.usedBy;
}
@@ -89,7 +91,7 @@ MotionTexture::MotionTexture(Entity* entity, const std::vector<std::string>& tex
for (auto& t : extra)
motion.emplace_back(entity, t.c_str(), false);
id = base.id;
texture_handle = base.GetGLTextureHandle();
usedBy = base.usedBy;
if (storeOnTextureList)
engine->world->textureList.push_back(new MotionTexture(*this));