From 463895a44fa7bb3eda0a9d8f08b936f07b8cc18e Mon Sep 17 00:00:00 2001 From: Redacted Date: Sat, 6 Jul 2024 23:10:48 -0400 Subject: [PATCH 1/6] 1 --- CMakeLists.txt | 2 +- src/demo/RuntimeTest/src/freeCam.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbbedff..19295bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ CPMAddPackage( CPMAddPackage( NAME JGL - URL https://git.redacted.cc/josh/JGL/archive/Prerelease-16.zip + URL https://git.redacted.cc/josh/JGL/archive/Prerelease-17.zip ) CPMAddPackage( diff --git a/src/demo/RuntimeTest/src/freeCam.cpp b/src/demo/RuntimeTest/src/freeCam.cpp index 82cd3da..0354356 100644 --- a/src/demo/RuntimeTest/src/freeCam.cpp +++ b/src/demo/RuntimeTest/src/freeCam.cpp @@ -41,10 +41,12 @@ void FreeCam::pre_render() { } 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, "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); + //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); + + JGL::J2D::DrawString2D(JGL::Colors::White, "FPS: " + std::to_string((int) engine->framerate()), 0, -1, -0.005125, 48, Fonts::ModeSeven); + JGL::J2D::DrawString2D(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, 0, -0.000125,8192, Fonts::Jupiteroid); } From c2077481c399e31c70f3e48bb9c280916f213b6f Mon Sep 17 00:00:00 2001 From: josh Date: Sat, 6 Jul 2024 23:50:30 -0400 Subject: [PATCH 2/6] 2D Text Context!!! --- src/demo/RuntimeTest/src/freeCam.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/demo/RuntimeTest/src/freeCam.cpp b/src/demo/RuntimeTest/src/freeCam.cpp index 0354356..f95d597 100644 --- a/src/demo/RuntimeTest/src/freeCam.cpp +++ b/src/demo/RuntimeTest/src/freeCam.cpp @@ -47,6 +47,26 @@ void FreeCam::jglRenderPass() { //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); - JGL::J2D::DrawString2D(JGL::Colors::White, "FPS: " + std::to_string((int) engine->framerate()), 0, -1, -0.005125, 48, Fonts::ModeSeven); - JGL::J2D::DrawString2D(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, 0, -0.000125,8192, Fonts::Jupiteroid); + // HOLY SHYT!!!! + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0.0f, engine->window->getWidth(), engine->window->getHeight(), 0.0f, -1.f, 1.f); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + JGL::J2D::DrawString2D(JGL::Colors::White, "FPS: " + std::to_string((int) engine->framerate()), 200, 50, 1, 16, Fonts::ModeSeven); + JGL::J2D::DrawString2D(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 200, 75, 1,16, Fonts::Jupiteroid); + + + JGL::J2D::FillRect2D({255,0,0}, {25.f, 25.f}, {50, 50}); + + //glMatrixMode(GL_MODELVIEW); + + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); } From 8ee3cec4609e460a2f31b5a53a41e9556bdbc23e Mon Sep 17 00:00:00 2001 From: josh Date: Sun, 7 Jul 2024 00:20:29 -0400 Subject: [PATCH 3/6] Test 2??? --- src/demo/RuntimeTest/src/freeCam.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/demo/RuntimeTest/src/freeCam.cpp b/src/demo/RuntimeTest/src/freeCam.cpp index f95d597..7edf0f9 100644 --- a/src/demo/RuntimeTest/src/freeCam.cpp +++ b/src/demo/RuntimeTest/src/freeCam.cpp @@ -37,7 +37,6 @@ void FreeCam::pre_render() { if (engine->window->isKeyDown(Keys::E)) setAngle(getAngle().x, getAngle().y, getAngle().z + 75.0f * engine->frameDelta); - } void FreeCam::jglRenderPass() { @@ -49,19 +48,11 @@ void FreeCam::jglRenderPass() { // HOLY SHYT!!!! - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(0.0f, engine->window->getWidth(), engine->window->getHeight(), 0.0f, -1.f, 1.f); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - JGL::J2D::DrawString2D(JGL::Colors::White, "FPS: " + std::to_string((int) engine->framerate()), 200, 50, 1, 16, Fonts::ModeSeven); - JGL::J2D::DrawString2D(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 200, 75, 1,16, Fonts::Jupiteroid); + JGL::J2D::DrawString2D(JGL::Colors::White, "FPS: " + std::to_string((int) engine->framerate()), 200, 50, 1, 16, Fonts::ModeSeven); + JGL::J2D::DrawString2D(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 200, 75, 1,16, Fonts::Jupiteroid); - JGL::J2D::FillRect2D({255,0,0}, {25.f, 25.f}, {50, 50}); + JGL::J2D::FillRect2D({255,0,0}, {25.f, 25.f}, {50, 50}); //glMatrixMode(GL_MODELVIEW); From e550dea76e08e95993fce1676057ffe5275ba67b Mon Sep 17 00:00:00 2001 From: Redacted Date: Sun, 7 Jul 2024 20:24:56 -0400 Subject: [PATCH 4/6] Update JGL --- CMakeLists.txt | 2 +- src/demo/RuntimeTest/main.cpp | 2 +- src/demo/RuntimeTest/src/freeCam.cpp | 30 +++++++++++----------------- src/engine/engine.cpp | 2 ++ 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19295bc..30b56f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ CPMAddPackage( CPMAddPackage( NAME JGL - URL https://git.redacted.cc/josh/JGL/archive/Prerelease-17.zip + URL https://git.redacted.cc/josh/JGL/archive/Prerelease-18.zip ) CPMAddPackage( diff --git a/src/demo/RuntimeTest/main.cpp b/src/demo/RuntimeTest/main.cpp index 69b1f20..38c24c4 100644 --- a/src/demo/RuntimeTest/main.cpp +++ b/src/demo/RuntimeTest/main.cpp @@ -10,7 +10,7 @@ int main() engine->window = new ReWindow::RWindow("Re3D Test Application", 1152, 864, RenderingAPI::OPENGL); engine->world = new(World); Engine::init(); - JGL::InitTextEngine(); + JGL::Update(engine->window->getSize()); Fonts::initFonts(); engine->window->setVsyncEnabled(false); engine->window->setResizable(false); diff --git a/src/demo/RuntimeTest/src/freeCam.cpp b/src/demo/RuntimeTest/src/freeCam.cpp index 7edf0f9..595fd97 100644 --- a/src/demo/RuntimeTest/src/freeCam.cpp +++ b/src/demo/RuntimeTest/src/freeCam.cpp @@ -40,24 +40,18 @@ void FreeCam::pre_render() { } 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, "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); + using namespace JGL; + J3D::Begin(); + J3D::DrawString(JGL::Colors::Red, "3D Sample Text.", {0, 0, 0}, 0.0225, 32, Fonts::Jupiteroid); + J3D::End(); - // HOLY SHYT!!!! - - JGL::J2D::DrawString2D(JGL::Colors::White, "FPS: " + std::to_string((int) engine->framerate()), 200, 50, 1, 16, Fonts::ModeSeven); - JGL::J2D::DrawString2D(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 200, 75, 1,16, Fonts::Jupiteroid); - - - JGL::J2D::FillRect2D({255,0,0}, {25.f, 25.f}, {50, 50}); - - //glMatrixMode(GL_MODELVIEW); - - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); + J2D::Begin(); + J2D::FillRect(JGL::Colors::Blue, {32, 32}, {100.5, 100.5}); + J2D::FillTriangle(JGL::Colors::Yellow, {{140, 200},{135, 100},{105, 100}}); + J2D::DrawString(JGL::Colors::White, "Framerate: " + std::to_string((int) engine->framerate()), 0, -16, 1, 16, Fonts::Jupiteroid); + J2D::DrawString(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, -33, 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, -50, 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, -67, 1,16, Fonts::Jupiteroid); + J2D::End(); } diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 624d076..484b093 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -114,6 +115,7 @@ void Engine::render() { } void Engine::jglRenderPass() { + JGL::Update(engine->window->getSize()); 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) From 7f65fee8910ec46577281291d300832e551c2a5e Mon Sep 17 00:00:00 2001 From: Redacted Date: Tue, 16 Jul 2024 20:09:49 -0400 Subject: [PATCH 5/6] More accurate lighting. Sacrificed one texture unit to make it such that point lights on things that are multi-textured look the same as on regular things. --- CMakeLists.txt | 2 +- assets/textures/multi/1.png | Bin 6214 -> 0 bytes assets/textures/multi/default.png | Bin 6307 -> 6214 bytes include/Redacted3D/engine/world.h | 2 +- include/Redacted3D/types/entity/entity.h | 4 +- include/Redacted3D/types/shader.h | 6 +- src/demo/RuntimeTest/include/cube.h | 2 +- src/demo/RuntimeTest/src/cube.cpp | 20 ++--- src/demo/RuntimeTest/src/freeCam.cpp | 12 +-- src/engine/engine.cpp | 7 +- src/types/entity/entity.cpp | 99 +++++++++++++---------- src/types/entity/skybox.cpp | 2 +- src/types/texture.cpp | 6 +- 13 files changed, 92 insertions(+), 70 deletions(-) delete mode 100644 assets/textures/multi/1.png diff --git a/CMakeLists.txt b/CMakeLists.txt index 30b56f6..a788217 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ CPMAddPackage( CPMAddPackage( NAME JGL - URL https://git.redacted.cc/josh/JGL/archive/Prerelease-18.zip + URL https://git.redacted.cc/josh/JGL/archive/Prerelease-20.zip ) CPMAddPackage( diff --git a/assets/textures/multi/1.png b/assets/textures/multi/1.png deleted file mode 100644 index 67b2b4e091676e5bdff8058a2055c72f1e4c65fc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6214 zcmeHL3vg7`8NO&H32Ar+6&31rnacC--q+r}_jZ>&HX&JLVJ9pCkxK95+~k(sy*GDn zvP*ajgraDtQ9@}0qXQJBIwVx7V<>2mK@>Zb!ce1)ikU!sP%Mvv0mRaCcau$`V8J3Y zoypGb+{gLPch2|y|9}3o=kdVw;z3#WWFZJL$X8NWiXa2v?EoY*9bV=c&nxho=N>vW`@OoCe|vFx{=D)p?l}A9 zq<3CvE?+<%-n0MhhCg0F+;zy-ft9b^b$C7R?>I1W&3gs^{`|AF#RL96ZEp4>6-TB* zZYx!RDcPGh^3jjBtbHOlqBZ}G`@MH$?0SBc)KoBR!q3Y#&B|Ew z;FXO&Z+(0FxE*(nx;(d$-@*RlMB9YS+FbPD;OS4;OWR|-!t8#d4X%fs2H zAAh4#X<*KzpE(A8}4BYt1zRJl{mbcjt zHU9Wu=S#=v8ORk%f3Eqfchd1MeKoH&6+O9ZdAO~8XVdsauXhZ_&&m6@oSeF}tY8!J z>W0Ivj%BB@L(LzbZ>p+0l7V_(oBAP=@!0EgR&RfI*Q>jl|DauIdHGW3?V&@)voC(| z$WjE!X;EQ(&GAp;B`s_hWK9J2cvy#lham3UxGqQwfQgErT#a~ar*`eOp{ne$&35{6 zzwQMUYDtX&X4Xs(N;L~4PPXMv&T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ajZq~-I=!}FznYGn>RG9OJ^n>U)f?I z|Nnm4a+!(ycea+jeR0WwPcLr$^S#-vO-LFt6v?xW;=lV%+t$5V+b=a7z8HJPzGuk) ej+ciliw!xOnOW<)JL_XhZeP*#!fgdVt^E(oSlELA diff --git a/assets/textures/multi/default.png b/assets/textures/multi/default.png index abdfa4ed684145f183a186800c94ec0bf70318ef..67b2b4e091676e5bdff8058a2055c72f1e4c65fc 100644 GIT binary patch delta 1117 zcmZ2%c+6me3gh94stWbI%?3PwzKh5z);%%p(+qjVCcED+M_^@D(7ASgzT*Wo_w*}x z1h_obt^E=-$#GXnkg%?0iILjO8m8vyb}^IIYzi$~JoU$`H;;uT2lzgX4ybP1xYkX4 z{gt|=NA5OiO2XAFUpbPBn3Wy=My>o3_CEYZ-1ql*Vm zoSd=q2ZK!?!)ngLZQ>VaS@}LaBQg1g)4#VbS!x(>`b6@?WnA`RU|?*`baoE#baqxK zD9TUE%t>WnsF+hb(bnUzgGAf?WmCICL~c1AQFIn%-@T$Ed99P6R!h{vQ1;2*{}*^V zPkQu7V~3c`pU5>mN(`sI*$~l z%`p4O_VLWJ+=6@ReH$jN5t=XTKcmF)k^4Grx&4KDyL3LB>6qzxUf8|kXcD`&>>00R z^=>x4GNGn(KeetouJv5^T-4HIQQx2F^E~}JHFe!(DMz91h$a?6t}KnkOwxw8N`rKk zytKJ^)c(yc)gsL&TFn!a8ACHB#M=Lm|MPBb=!{ukCOL5~cz(3d&aLr*-i0;R=e}=z zY~s)G-?(7u_P4n_w3%jIsgB)Ex*1q=UgaSvf)l#9Rq{# zwaraTCz(_dlZ{NwEi4UmEeui(bxqRD(sYw7jSX}S(kv6rlT0iOj1to(=d&*3Gc*D! zG&40aF*CNXG@h)?wq3x)%D^PV(8$Wjz{=E6*T7`*D>gX{!OarvjBJyoIbun8Jn3;{=nrSU;;D`X0{QKy_t_U zn?r2*jz4@13=C{Z-tI08|A8z9WA&QPllw*G>seR?L`>pkn>>K&ZK9`(V@SoVx7QBx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1Dosf XUTd+=HLJW0jClr6S3j3^P6 diff --git a/include/Redacted3D/types/shader.h b/include/Redacted3D/types/shader.h index 9921172..083f2c6 100644 --- a/include/Redacted3D/types/shader.h +++ b/include/Redacted3D/types/shader.h @@ -8,11 +8,11 @@ public: std::string name; ///The shader program - GLuint id = NULL; + GLuint id = 0; ///The individual shaders - GLuint vertex = NULL; - GLuint fragment = NULL; + GLuint vertex = 0; + GLuint fragment = 0; Shader(const char* name, const std::string& vertexPath, const std::string& fragmentPath); Shader(const char* name, const std::string& filePath, const GLenum& type); diff --git a/src/demo/RuntimeTest/include/cube.h b/src/demo/RuntimeTest/include/cube.h index 9f38e34..84432ee 100644 --- a/src/demo/RuntimeTest/include/cube.h +++ b/src/demo/RuntimeTest/include/cube.h @@ -17,7 +17,7 @@ public: //The "camera point" is the position the camera will want to be while following the player. //We will probably end up having a different camera point class controlled by the "world". - void update(float elapsed) override; + //void update(float elapsed) override; void pre_render() override; void loadTexture() override; Cube(); diff --git a/src/demo/RuntimeTest/src/cube.cpp b/src/demo/RuntimeTest/src/cube.cpp index 3e4542f..9eb5284 100644 --- a/src/demo/RuntimeTest/src/cube.cpp +++ b/src/demo/RuntimeTest/src/cube.cpp @@ -1,15 +1,11 @@ #include #include -#include void Cube::pre_render() { getGeometry(); setAngle(getAngle().Add(24 * engine->frameDelta)); } -void Cube::update(float elapsed) { - -} Cube::Cube() { name = "cube"; modelPath = "assets/models/cube.obj"; @@ -19,13 +15,13 @@ Cube::Cube() { void Cube::loadTexture() { //MultiTexture texture(this, texturePath.c_str(), true); - std::vector textures; - textures.emplace_back("assets/textures/motion/default.png"); - textures.emplace_back("assets/textures/motion/1.png"); - textures.emplace_back("assets/textures/motion/2.png"); - textures.emplace_back("assets/textures/motion/3.png"); - textures.emplace_back("assets/textures/motion/4.png"); - textures.emplace_back("assets/textures/motion/5.png"); - textures.emplace_back("assets/textures/motion/6.png"); + + + std::vector textures = { + "assets/textures/motion/default.png", "assets/textures/motion/1.png", "assets/textures/motion/2.png", + "assets/textures/motion/3.png", "assets/textures/motion/4.png", "assets/textures/motion/5.png", + "assets/textures/motion/6.png" + }; + MotionTexture texture(this, textures, 250, true); } diff --git a/src/demo/RuntimeTest/src/freeCam.cpp b/src/demo/RuntimeTest/src/freeCam.cpp index 595fd97..e307d82 100644 --- a/src/demo/RuntimeTest/src/freeCam.cpp +++ b/src/demo/RuntimeTest/src/freeCam.cpp @@ -39,19 +39,21 @@ void FreeCam::pre_render() { setAngle(getAngle().x, getAngle().y, getAngle().z + 75.0f * engine->frameDelta); } +Vector3 textAngle = {0,0,0}; void FreeCam::jglRenderPass() { - + textAngle.x = textAngle.x - (96.f * engine->frameDelta); using namespace JGL; J3D::Begin(); - J3D::DrawString(JGL::Colors::Red, "3D Sample Text.", {0, 0, 0}, 0.0225, 32, Fonts::Jupiteroid); + J3D::DrawString(JGL::Colors::Red, "Text", {0, -2, 0}, textAngle, 4.f, 32, Fonts::Jupiteroid); J3D::End(); J2D::Begin(); - J2D::FillRect(JGL::Colors::Blue, {32, 32}, {100.5, 100.5}); - J2D::FillTriangle(JGL::Colors::Yellow, {{140, 200},{135, 100},{105, 100}}); + J2D::FillRect({255,0,0,128}, {0, 72}, {100, 100}); + J2D::FillCircle(JGL::Colors::White, {16, 128}, 12, 16); + J2D::DrawString(JGL::Colors::White, "Framerate: " + std::to_string((int) engine->framerate()), 0, -16, 1, 16, Fonts::Jupiteroid); J2D::DrawString(JGL::Colors::White, "Framecount: " + std::to_string(engine->frameCount), 0, -33, 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, -50, 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, -67, 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, -67, 1,16, Fonts::Jupiteroid); J2D::End(); } diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 484b093..d8b084f 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -3,6 +3,7 @@ #include #include #include +#include using namespace J3ML; @@ -81,6 +82,7 @@ void Engine::initGL() const { glDepthMask(GL_TRUE); glEnable(GL_CULL_FACE); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + glEnable(GL_LIGHT0); } void Engine::init() { @@ -110,8 +112,11 @@ void Engine::render() { if (auto* c = dynamic_cast(e); c == nullptr) //If it's not a camera. e->render(); - if (glGetError() != GL_NO_ERROR) + int glError = glGetError(); + if (glError != GL_NO_ERROR) { + FATAL("GL Error: " + std::to_string(glError)) exit(0); + } } void Engine::jglRenderPass() { diff --git a/src/types/entity/entity.cpp b/src/types/entity/entity.cpp index ce7724b..1b217a7 100644 --- a/src/types/entity/entity.cpp +++ b/src/types/entity/entity.cpp @@ -42,7 +42,7 @@ Entity::Entity() { ticksAlive = 0; children = std::vector (); parent = nullptr; - scale = 1.0f; + scale = {1.0f, 1.0f, 1.0f}; //UUIDv4::UUIDGenerator uuidGenerator; //UUIDv4::UUID id = uuidGenerator.getUUID(); @@ -50,10 +50,10 @@ Entity::Entity() { } void Entity::setScale(const float &multiplier) { - scale = multiplier; + scale.Set(multiplier, multiplier, multiplier); } -GLfloat Entity::getScale() const { +Vector3 Entity::getScale() const { return scale; } @@ -79,24 +79,47 @@ VertexArray* Entity::getGeometry() { return getGeometry(); } +inline Texture* baseTexture = new Texture; void Entity::render() { - bool multiTexture = false; - bool motionTexture = false; + if (!baseTexture) { + Texture t; + glGenTextures(1, &t.id); + glBindTexture(GL_TEXTURE_2D, t.id); - if (auto* t = dynamic_cast(getTexture())) - multiTexture = true; + unsigned char whitePixel[4] = { 255, 255, 255, 255}; + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, whitePixel); - if (!multiTexture) - if (auto* t = dynamic_cast(getTexture())) - motionTexture = true; + 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); + } + + MultiTexture texture; + texture.id = baseTexture->id; + + + if (auto* t = dynamic_cast(getTexture())) { + texture.multi.emplace_back(*t); + for (const auto &item: t->multi) + texture.multi.push_back(item); + } + + else if (auto* j = dynamic_cast(getTexture())) + texture.multi.push_back(*j->current()); + + else if (auto* k = dynamic_cast(getTexture())) + texture.multi.push_back(*k); glPushMatrix(); glTranslatef(position.x, position.y, position.z); glRotatef(angle.x, 1.0f, 0.0f, 0.0f); glRotatef(angle.y, 0.0f, 1.0f, 0.0f); glRotatef(angle.z, 0.0f, 0.0f, 1.0f); - if (getScale() != 1.0f) - glScalef(getScale(), getScale(), getScale()); + if (getScale().x != 1.0f || getScale().y != 1.0f || getScale().z != 1.0f) + glScalef(getScale().x, getScale().y, getScale().z); //Set up texture. glActiveTexture(GL_TEXTURE0); @@ -104,7 +127,9 @@ void Entity::render() { glEnable(GL_TEXTURE_2D); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glBindTexture(GL_TEXTURE_2D, motionTexture ? ((MotionTexture*)getTexture())->current()->id : getTexture()->id); + glBindTexture(GL_TEXTURE_2D, texture.id); + //Texture unit mode. + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); if (!engine->useVBO) glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &getGeometry()->vertices[0].x), @@ -114,35 +139,26 @@ void Entity::render() { glBindBuffer(GL_ARRAY_BUFFER, getGeometry()->tbo), glTexCoordPointer(2, GL_FLOAT, 0, nullptr); - if (!multiTexture) - getGeometry()->draw(); - if (multiTexture) { - auto* multi = (MultiTexture*) getTexture(); + int i = 0; + for(auto& t : texture.multi) { + glActiveTexture(GL_TEXTURE1 + i); + glClientActiveTexture(GL_TEXTURE1 + i); + glEnable(GL_TEXTURE_2D); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); - int i = 0; - GLfloat blendingFactor[3] = {engine->world->getAmbientLightColor().x * 0.2f, engine->world->getAmbientLightColor().y * 0.2f, engine->world->getAmbientLightColor().z * 0.2f}; - for(auto& texture : multi->multi) { - glActiveTexture(GL_TEXTURE1 + i); - glClientActiveTexture(GL_TEXTURE1 + i); - glEnable(GL_TEXTURE_2D); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); + if (!engine->useVBO) + glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &getGeometry()->vertices[0].x), + glTexCoordPointer(2, GL_FLOAT, sizeof(TextureCoordinate), &getGeometry()->texCoords[0].x); - if (!engine->useVBO) - glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &getGeometry()->vertices[0].x), - glTexCoordPointer(2, GL_FLOAT, sizeof(TextureCoordinate), &getGeometry()->texCoords[0].x); - - if (engine->useVBO) - glBindBuffer(GL_ARRAY_BUFFER, getGeometry()->tbo), - glTexCoordPointer(2, GL_FLOAT, 0, nullptr); + if (engine->useVBO) + glBindBuffer(GL_ARRAY_BUFFER, getGeometry()->tbo), + glTexCoordPointer(2, GL_FLOAT, 0, nullptr); //Texture unit mode. glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); - - //Makes the lighting work the way you'd think it would. - glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, blendingFactor); - glBindTexture(GL_TEXTURE_2D, texture.id); + glBindTexture(GL_TEXTURE_2D, t.id); i++; } getGeometry()->draw(); @@ -156,7 +172,6 @@ void Entity::render() { glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } - } //Reset texture unit 0. glActiveTexture(GL_TEXTURE0); @@ -220,9 +235,10 @@ void Entity::erase() { AABB Entity::getAABB() { AABB aabb = Collision::genMinimallyEnclosingAABB(getGeometry()); - if (getScale() != 1) - aabb.minPoint *= scale, - aabb.maxPoint *= scale; + //TODO this won't look right. + if (getScale().x != 1) + aabb.minPoint *= scale.x, + aabb.maxPoint *= scale.x; aabb.minPoint += position; aabb.maxPoint += position; @@ -231,7 +247,8 @@ AABB Entity::getAABB() { Sphere Entity::getSphere() { Sphere sphere = Collision::genMinimallyEnclosingSphere(getGeometry()); - sphere.Radius *= scale; + //TODO this won't look right. + sphere.Radius *= scale.x; sphere.Position = position; return sphere; } diff --git a/src/types/entity/skybox.cpp b/src/types/entity/skybox.cpp index 1f7d7da..c15d978 100644 --- a/src/types/entity/skybox.cpp +++ b/src/types/entity/skybox.cpp @@ -12,7 +12,7 @@ void Skybox::render() { glTranslatef(position.x ,position.y, position.z); glBindTexture(GL_TEXTURE_2D, getTexture()->id); glCullFace(GL_FRONT); - glScalef(getScale(), getScale(), getScale()); + glScalef(getScale().x, getScale().y, getScale().z); getGeometry()->draw(); glCullFace(GL_BACK); glBindTexture(GL_TEXTURE_2D,0); diff --git a/src/types/texture.cpp b/src/types/texture.cpp index 5123fc0..21155af 100644 --- a/src/types/texture.cpp +++ b/src/types/texture.cpp @@ -1,9 +1,10 @@ -#include #include +#include #include void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureList) { auto* texture = new RTexture(file, {RTextureFlag::INVERT_Y}); + glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); if (texture->format == RTextureFormat::RGBA) @@ -11,6 +12,7 @@ void Texture::load(Entity* entity, const std::string& file, bool storeOnTextureL 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()); delete texture; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); @@ -74,7 +76,7 @@ MultiTexture::MultiTexture(Entity* entity, const char* pathContainingTextures, b //You cannot have more than 8 total textures rendered in one pass. //In Fixed-Function OpenGL you only have 8 TMUs available. //TODO: multi-pass multi-texturing (will be slower). - if (multi.size() > 7) + if (multi.size() > 6) engine->setError(ENGINE_ERROR_CODE::MULTI_TEXTURE_SIZE_EXCEEDS, true); } From f5ab98317635fa5a0cdb073cd33b720d574ea94f Mon Sep 17 00:00:00 2001 From: Redacted Date: Wed, 17 Jul 2024 13:52:24 -0400 Subject: [PATCH 6/6] Cleanup --- assets/textures/multi/1.png | Bin 0 -> 6214 bytes assets/textures/multi/default.png | Bin 6214 -> 6307 bytes include/Redacted3D/types/entity/entity.h | 14 ++++--- include/Redacted3D/types/texture.h | 16 ++++---- src/demo/RuntimeTest/include/cube.h | 1 - src/demo/RuntimeTest/src/ball.cpp | 6 +-- src/demo/RuntimeTest/src/cube.cpp | 24 +++++------ src/demo/RuntimeTest/src/demoSky.cpp | 4 +- src/types/entity/entity.cpp | 49 ++++++++++++----------- src/types/entity/skybox.cpp | 2 - src/types/texture.cpp | 46 ++++++++++++--------- 11 files changed, 87 insertions(+), 75 deletions(-) create mode 100644 assets/textures/multi/1.png diff --git a/assets/textures/multi/1.png b/assets/textures/multi/1.png new file mode 100644 index 0000000000000000000000000000000000000000..67b2b4e091676e5bdff8058a2055c72f1e4c65fc GIT binary patch literal 6214 zcmeHL3vg7`8NO&H32Ar+6&31rnacC--q+r}_jZ>&HX&JLVJ9pCkxK95+~k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CnK>g%!PTWcp8=*~VA*0^!A)rhRcqT~AxAFBYC z53eb@<9c{$k!oO=;A_lu!4TjY3**FNQw%MP3c4OrrG)n#)e*UCZA--rYHDat;9k$b zQK9-OmxvA#sQ~<5uzeXoRbx4g6*r;O_iC# zd7?YEZvk6UCI!MJ3UEmx0YZY@$tV||cL6YE|Bu`LXnS2Y_ z0#U>Xh7&M`b5W2j<-#~oA~6Y<8ChTmmU243)wjj4rX>~@bX;P2yjI@O7>pgbSm7*B zFg(RzxYJr)ZUIGFUOmYFy322h-E>qW9CB6$q7Z2;tEu+ZE zP6>JuiVC0uX&Jgwq-7i<7*>{L4yOoQxanTxV65IkiY^f-3NAypF*HU?aK|CCgn&^J z#{!&S6^e1)EQ&BzQ)LiROq9W{Ky^E;9cgzRb349K>5>M$wy>};B;UcUG2Cf8Qd{k= ziUFhU`}}lO*za=)6zw16hV<>1t6#1gQs9P+`=hI0t{YO|hK&28>!!(-)pJ+}BJi(R z3?9Y(ZpY=p@E9*$e6Y9>xniB@QDYbX3tk55C3B+)@`D`fHvn1x^ho$J!}R%!GCoa9 z8#;oXKf1OA9@eh*73K%yt)I8-8MF)?T9i+JajZq~-I=!}FznYGn>RG9OJ^n>U)f?I z|Nnm4a+!(ycea+jeR0WwPcLr$^S#-vO-LFt6v?xW;=lV%+t$5V+b=a7z8HJPzGuk) ej+ciliw!xOnOW<)JL_XhZeP*#!fgdVt^E(oSlELA literal 0 HcmV?d00001 diff --git a/assets/textures/multi/default.png b/assets/textures/multi/default.png index 67b2b4e091676e5bdff8058a2055c72f1e4c65fc..abdfa4ed684145f183a186800c94ec0bf70318ef 100644 GIT binary patch delta 1225 zcmX?Ru-I^d3gf|vstWajhZT5!r+4)|5I@r6JnPFk>5@NPGrl-Q-;ETLXeqoEf8Kpp zDM$3CJrygL3M5=zWx}!C!Ft9?KD&d>%m03v*tF(^6s!K@YdgC)Kl*qtA^a$n5;4ev}2D+j56-uZU^*QS@blJ)OboLIMp zB~15X!?z7fc$*GJ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mCICL~c1AQFIn%-@T$Ed99P6R!h{vQ1;2*{}*^V zPkQu7V~3c`pU5>mN(`sI*$~l z%`p4O_VLWJ+=6@ReH$jN5t=XTKcmF)k^4Grx&4KDyL3LB>6qzxUf8|kXcD`&>>00R z^=>x4GNGn(KeetouJv5^T-4HIQQx2F^E~}JHFe!(DMz91h$a?6t}KnkOwxw8N`rKk zytKJ^)c(yc)gsL&TFn!a8ACHB#M=Lm|MPBb=!{ukCOL5~cz(3d&aLr*-i0;R=e}=z zY~s)G-?(7u_P4n_w3%jIsgB)Ex*1q=UgaSvf)l#9Rq{# zwaraTCz(_dlZ{NwEi4UmEeui(bxqRD(sYw7jSX}S(kv6rlT0iOj1to(=d&*3Gc*D! zG&40aF*CNXG@h)?wq3x)%D^PV(8$Wjz{=E6*T7`*D>gX{!OarvjBJyoIbun8Jn3;{=nrSU;;D`X0{QKy_t_U zn?r2*jz4@13=C{Z-tI08|A8z9WA&QPllw*G>seR?L`>pkn>>K&ZK9`(V@SoVx7QBx zHYf children; + +///Loads the geometry for it. +void loadGeometry(const std::string& file); +void loadTexture(const std::string& file); +void loadMultiTexture(const std::vector& files); +void loadMotionTexture(const std::vector& files, u16 frameDelta, bool doAnim = true); + public: std::string name; //Entity name. TODO remove this. bool alive; - virtual std::vector GetEntityUUIDList() const { return std::vector { "" }; } template diff --git a/include/Redacted3D/types/texture.h b/include/Redacted3D/types/texture.h index b420d1c..572697b 100644 --- a/include/Redacted3D/types/texture.h +++ b/include/Redacted3D/types/texture.h @@ -33,22 +33,24 @@ public: void erase() override; ///Every texture other than the base texture. std::vector multi; - ///Loads a multi-texture from a given directory. One must be called "default.png" - MultiTexture(Entity* entity, const char* pathContainingTextures, bool storeOnTextureList); + ///Loads a list of Textures into a MultiTexture. + MultiTexture(Entity* entity, const std::vector& textures, bool storeOnTextureList); MultiTexture() = default; - //TODO load multi-texture from array of std::string of file names. }; ///A list of textures where the one actually displayed depends on how much time has elapsed. class MotionTexture : public Texture { private: std::chrono::high_resolution_clock::time_point lastUpdate; - int lastDisplayedIndex; - u16 msDelay; -public: + int lastDisplayedIndex = 0; + u16 msDelay = 0; bool doAnim = true; +public: std::vector motion; Texture* current(); - MotionTexture(Entity* entity, const std::vector& textures,u16 msBetweenFrames, bool storeOnTextureList); + Texture* base(); + void advance(); + void toggleAnim(); + MotionTexture(Entity* entity, const std::vector& textures,u16 msBetweenFrames, bool storeOnTextureList, bool doAnim = true); MotionTexture() = default; }; \ No newline at end of file diff --git a/src/demo/RuntimeTest/include/cube.h b/src/demo/RuntimeTest/include/cube.h index 84432ee..20bb6c5 100644 --- a/src/demo/RuntimeTest/include/cube.h +++ b/src/demo/RuntimeTest/include/cube.h @@ -19,6 +19,5 @@ public: //We will probably end up having a different camera point class controlled by the "world". //void update(float elapsed) override; void pre_render() override; - void loadTexture() override; Cube(); }; \ No newline at end of file diff --git a/src/demo/RuntimeTest/src/ball.cpp b/src/demo/RuntimeTest/src/ball.cpp index ada22f0..85ab380 100644 --- a/src/demo/RuntimeTest/src/ball.cpp +++ b/src/demo/RuntimeTest/src/ball.cpp @@ -10,7 +10,7 @@ void Ball::update(float elapsed) { Ball::Ball() { name = "ball"; - modelPath = "assets/models/sphere_lo.obj"; - texturePath = "assets/textures/missing.png"; + loadGeometry("assets/models/sphere_lo.obj"); + loadTexture("assets/textures/missing.png"); setScale(1.0f); -} +} \ No newline at end of file diff --git a/src/demo/RuntimeTest/src/cube.cpp b/src/demo/RuntimeTest/src/cube.cpp index 9eb5284..93a75e7 100644 --- a/src/demo/RuntimeTest/src/cube.cpp +++ b/src/demo/RuntimeTest/src/cube.cpp @@ -8,20 +8,20 @@ void Cube::pre_render() { Cube::Cube() { name = "cube"; - modelPath = "assets/models/cube.obj"; - texturePath = "assets/textures/multi/"; setScale(0.5f); -} -void Cube::loadTexture() { - //MultiTexture texture(this, texturePath.c_str(), true); - - - std::vector textures = { + loadGeometry("assets/models/cube.obj"); + std::vector motionTextures = { "assets/textures/motion/default.png", "assets/textures/motion/1.png", "assets/textures/motion/2.png", - "assets/textures/motion/3.png", "assets/textures/motion/4.png", "assets/textures/motion/5.png", - "assets/textures/motion/6.png" - }; + "assets/textures/motion/3.png", "assets/textures/motion/4.png", "assets/textures/motion/5.png", + "assets/textures/motion/6.png" + }; - MotionTexture texture(this, textures, 250, true); + std::vector multiTextures = { + "assets/textures/multi/default.png", "assets/textures/multi/1.png", "assets/textures/multi/2.png", "assets/textures/multi/3.png", + "assets/textures/multi/4.png", "assets/textures/multi/5.png", "assets/textures/multi/6.png" + }; + + loadMultiTexture(multiTextures); + //loadMotionTexture(motionTextures, 250, true); } diff --git a/src/demo/RuntimeTest/src/demoSky.cpp b/src/demo/RuntimeTest/src/demoSky.cpp index b1c0774..17113a4 100644 --- a/src/demo/RuntimeTest/src/demoSky.cpp +++ b/src/demo/RuntimeTest/src/demoSky.cpp @@ -3,7 +3,7 @@ DemoSkybox::DemoSkybox() { name = "skybox"; - modelPath = engine->workingDir + "/assets/models/sphere_vlo.obj"; - texturePath = engine->workingDir + "/assets/textures/skybox.png"; + loadGeometry("assets/models/sphere_vlo.obj"); + loadTexture("assets/textures/skybox.png"); setScale(engine->farPlane); } \ No newline at end of file diff --git a/src/types/entity/entity.cpp b/src/types/entity/entity.cpp index 1b217a7..163a926 100644 --- a/src/types/entity/entity.cpp +++ b/src/types/entity/entity.cpp @@ -57,17 +57,23 @@ Vector3 Entity::getScale() const { return scale; } -void Entity::loadTexture() { - Texture texture(this, texturePath.c_str(), true); +void Entity::loadTexture(const std::string& file) { + Texture texture(this, file.c_str(), true); } -void Entity::loadGeometry() { - VertexArray vArray(this, modelPath, true); +void Entity::loadMultiTexture(const std::vector& files) { + MultiTexture texture(this, files, true); +} + +void Entity::loadMotionTexture(const std::vector& files, u16 frameDelta, bool doAnim) { + MotionTexture(this, files, frameDelta, true, doAnim); +} + +void Entity::loadGeometry(const std::string& file) { + VertexArray vArray(this, file, true); } VertexArray* Entity::getGeometry() { - if (engine->world->geometryList.empty()) - loadGeometry(); for (auto& vArray : engine->world->geometryList) for (auto& entity : vArray->usedBy) if (instanceOf(this, entity)) { @@ -75,8 +81,18 @@ VertexArray* Entity::getGeometry() { vArray->usedBy.push_back(this); return vArray; } - loadGeometry(); - return getGeometry(); + return nullptr; +} + +Texture* Entity::getTexture() { + for (auto& texture : engine->world->textureList) + for (auto& entity : texture->usedBy) + if (instanceOf(this, entity)) { + if (std::find(texture->usedBy.begin(), texture->usedBy.end(), this) == texture->usedBy.end()) //If this is the first time the entity is using it. + texture->usedBy.push_back(this); + return texture; + } + return nullptr; } inline Texture* baseTexture = new Texture; @@ -100,7 +116,6 @@ void Entity::render() { MultiTexture texture; texture.id = baseTexture->id; - if (auto* t = dynamic_cast(getTexture())) { texture.multi.emplace_back(*t); for (const auto &item: t->multi) @@ -164,7 +179,7 @@ void Entity::render() { getGeometry()->draw(); //Reset the multi-texture units. - for (int j = 0; j <= i; j++) { + for (int j = 0; j < i; j++) { glActiveTexture(GL_TEXTURE1 + j); glClientActiveTexture(GL_TEXTURE1 + j); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); @@ -195,20 +210,6 @@ void Entity::render() { //bool Entity::isCollidingWith(Entity *entity) {} -Texture* Entity::getTexture() { - if (engine->world->textureList.empty()) - loadTexture(); - for (auto& texture : engine->world->textureList) - for (auto& entity : texture->usedBy) - if (instanceOf(this, entity)) { - if (std::find(texture->usedBy.begin(), texture->usedBy.end(), this) == texture->usedBy.end()) //If this is the first time the entity is using it. - texture->usedBy.push_back(this); - return texture; - } - loadTexture(); - return getTexture(); -} - void Entity::erase() { Texture* t = getTexture(); VertexArray* vA = getGeometry(); diff --git a/src/types/entity/skybox.cpp b/src/types/entity/skybox.cpp index c15d978..941b45c 100644 --- a/src/types/entity/skybox.cpp +++ b/src/types/entity/skybox.cpp @@ -21,7 +21,5 @@ void Skybox::render() { Skybox::Skybox() { name = "skybox"; - modelPath = engine->workingDir + "/assets/models/sphere_vlo.obj"; - texturePath = engine->workingDir + "/assets/textures/missing.png"; setScale(engine->farPlane); } \ No newline at end of file diff --git a/src/types/texture.cpp b/src/types/texture.cpp index 21155af..d30afb4 100644 --- a/src/types/texture.cpp +++ b/src/types/texture.cpp @@ -57,35 +57,31 @@ void Texture::erase(Texture* texture) const { engine->world->textureList.erase(engine->world->textureList.begin() + i); } - -MultiTexture::MultiTexture(Entity* entity, const char* pathContainingTextures, bool storeOnTextureList) { - for (const auto& entry : std::filesystem::directory_iterator(pathContainingTextures)) - if (entry.is_regular_file() && entry.path().extension() == ".png") { - Texture texture(entity, (const char*) entry.path().c_str(), false); - - //The base texture *must* go in the first slot. - if (entry.path().filename() == "default.png") - this->id = texture.id, - this->usedBy = texture.usedBy; - else multi.push_back(texture); - } +MultiTexture::MultiTexture(Entity* entity, const std::vector& textures, bool storeOnTextureList) { + Texture base; + for (const auto& t : textures) { + if (id != 0) + multi.emplace_back(entity, t.c_str(), false); + else + base = Texture(entity, t.c_str(), false), + id = base.id, + usedBy = base.usedBy; + } if (storeOnTextureList) engine->world->textureList.push_back(new MultiTexture(*this)); - //You cannot have more than 8 total textures rendered in one pass. - //In Fixed-Function OpenGL you only have 8 TMUs available. - //TODO: multi-pass multi-texturing (will be slower). if (multi.size() > 6) - engine->setError(ENGINE_ERROR_CODE::MULTI_TEXTURE_SIZE_EXCEEDS, true); + engine->setError(ENGINE_ERROR_CODE::MULTI_TEXTURE_SIZE_EXCEEDS, false); } void MultiTexture::erase() { Texture::erase(this); } -MotionTexture::MotionTexture(Entity* entity, const std::vector& textures, u16 msBetweenFrames, bool storeOnTextureList) { +MotionTexture::MotionTexture(Entity* entity, const std::vector& textures, u16 msBetweenFrames, bool storeOnTextureList, bool doAnim) { msDelay = msBetweenFrames; + this->doAnim = doAnim; Texture base(entity, textures[0].c_str(), false); std::vector extra(textures.begin()+1, textures.end()); @@ -126,4 +122,18 @@ Texture* MotionTexture::current() { return this; return &motion[lastDisplayedIndex - 1]; -} \ No newline at end of file +} + +void MotionTexture::advance() { + lastDisplayedIndex++; + if (lastDisplayedIndex > motion.size()) + lastDisplayedIndex = 0; +} + +void MotionTexture::toggleAnim() { + doAnim = !doAnim; +} + +Texture* MotionTexture::base() { + return this; +}