Browse Source

progress in secret project

vlod 6 months ago
parent
commit
18c4e4c4cd
40 changed files with 190 additions and 48 deletions
  1. 2 2
      Pika/gameplay/containers.h
  2. 102 35
      Pika/gameplay/containers/silksong/silkSong.h
  3. BIN
      Pika/resources/hollowknight/background2.jpg
  4. BIN
      Pika/resources/hollowknight/block1.png
  5. BIN
      Pika/resources/hollowknight/block2.png
  6. BIN
      Pika/resources/hollowknight/block3.png
  7. BIN
      Pika/resources/hollowknight/block4.png
  8. 24 0
      Pika/resources/hollowknight/blur.frag
  9. BIN
      Pika/resources/hollowknight/bush.png
  10. BIN
      Pika/resources/hollowknight/bush2.png
  11. BIN
      Pika/resources/hollowknight/bush3.png
  12. BIN
      Pika/resources/hollowknight/grass.png
  13. BIN
      Pika/resources/hollowknight/grass2.png
  14. BIN
      Pika/resources/hollowknight/grass3.png
  15. BIN
      Pika/resources/hollowknight/grassDecoration.png
  16. BIN
      Pika/resources/hollowknight/grassDecorationBig.png
  17. BIN
      Pika/resources/hollowknight/map21.bin
  18. BIN
      Pika/resources/hollowknight/map22.bin
  19. BIN
      Pika/resources/hollowknight/mushroom7.png
  20. BIN
      Pika/resources/hollowknight/mushroom8.png
  21. BIN
      Pika/resources/hollowknight/old/background.jpg
  22. BIN
      Pika/resources/hollowknight/old/block1.png
  23. BIN
      Pika/resources/hollowknight/old/block2.png
  24. BIN
      Pika/resources/hollowknight/old/block3.png
  25. BIN
      Pika/resources/hollowknight/old/block4.png
  26. BIN
      Pika/resources/hollowknight/old/bush.png
  27. BIN
      Pika/resources/hollowknight/old/grass.png
  28. BIN
      Pika/resources/hollowknight/old/grass2.png
  29. BIN
      Pika/resources/hollowknight/old/grass3.png
  30. BIN
      Pika/resources/hollowknight/old/vines1.png
  31. BIN
      Pika/resources/hollowknight/old/vines2.png
  32. BIN
      Pika/resources/hollowknight/old/vines3.png
  33. BIN
      Pika/resources/hollowknight/stones.png
  34. BIN
      Pika/resources/hollowknight/stones2.png
  35. BIN
      Pika/resources/hollowknight/vines1.png
  36. BIN
      Pika/resources/hollowknight/vines2.png
  37. BIN
      Pika/resources/hollowknight/vines3.png
  38. 8 2
      Pika/resources/logs.txt
  39. 1 0
      Pika/thirdparty/gl2d/include/gl2d/gl2d.h
  40. 53 9
      Pika/thirdparty/gl2d/src/gl2d.cpp

+ 2 - 2
Pika/gameplay/containers.h

@@ -28,7 +28,7 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 //#include "containers/minecraftDungeons/mcDungeonsEditor.h"
 //#include "containers/minecraftDungeons/mcDungeonsgameplay.h"
 //#include "containers/minecraftDungeons/mcDungeonsMenu.h"
-//#include "containers/hollowknight/hollowknight.h"
+#include "containers/hollowknight/hollowknight.h"
 
 //#include "containers/marioKart/marioKartEditor.h"
 //#include "containers/marioKart/marioKart.h"
@@ -66,6 +66,7 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 	PIKA_DECLARE_CONTAINER(ImmageViewer) \
 	PIKA_DECLARE_CONTAINER(ThreeDTest) \
 	PIKA_DECLARE_CONTAINER(ThreeDEditor) \
+	PIKA_DECLARE_CONTAINER(Holloknight)\
 	PIKA_DECLARE_CONTAINER(PikaTextEditor)
 	//PIKA_DECLARE_CONTAINER(ThreeDGameExample) \
 	//PIKA_DECLARE_CONTAINER(ThreeDGameMenu) \
@@ -73,7 +74,6 @@ Container *getContainer(const char* name, pika::memory::MemoryArena *memoryArena
 	//PIKA_DECLARE_CONTAINER(MarioKart) \
 	//PIKA_DECLARE_CONTAINER(IsometricGameEditor) \
 	//PIKA_DECLARE_CONTAINER(Mario) \
-	//PIKA_DECLARE_CONTAINER(Holloknight)\
 	//PIKA_DECLARE_CONTAINER(Bezie)\
 	//PIKA_DECLARE_CONTAINER(PhysicsTest)\
 	//PIKA_DECLARE_CONTAINER(Logo)\

+ 102 - 35
Pika/gameplay/containers/silksong/silkSong.h

@@ -20,10 +20,11 @@ struct SilkSong: public Container
 	gl2d::Renderer2D renderer;
 	gl2d::Texture sprites;
 	gl2d::TextureAtlasPadding atlas;
+	gl2d::FrameBuffer fbo;
 
 	b2World world{{0, 10}};
 
-	constexpr static int ASSETS_COUNT = 18;
+	constexpr static int ASSETS_COUNT = 27;
 
 	std::vector<const char*> assetsNames=
 	{
@@ -45,6 +46,18 @@ struct SilkSong: public Container
 		"block2.png",
 		"block3.png",
 		"block4.png",
+
+		"bush2.png",
+		"bush3.png",
+		"grassDecoration.png",
+		"grassDecorationBig.png",
+		"mushroom7.png",
+		"mushroom8.png",
+		"stones.png",
+		"stones2.png",
+		"background2.jpg",
+
+
 	};
 
 	gl2d::Texture assets[ASSETS_COUNT];
@@ -202,7 +215,7 @@ struct SilkSong: public Container
 		}
 	};
 
-	Block blocks[10];
+	//Block blocks[10];
 	b2Body *currentBodySelected = 0;
 	int currentSelectedSprite = 0;
 
@@ -227,25 +240,34 @@ struct SilkSong: public Container
 
 	struct GameSprite
 	{
-		glm::vec2 pos = {};
+		glm::vec3 pos = {};
 		float scale = 1;
 		int type = 0;
 		float rotation = 0;
 		bool flip = 0;
 		int layer = 0; //0 is background than 1 is objects than 2 is decoration than player than 3
+		glm::vec4 color = {1,1,1,1};
 	};
 
 	std::vector<GameSprite> gameSprites;
 
+	gl2d::ShaderProgram blurShader;
+
 	bool create(RequestedContainerInfo &requestedInfo, pika::StaticString<256> commandLineArgument)
 	{
-		
+
+		fbo.create(1, 1, true, true);
+
 		renderer.create(requestedInfo.requestedFBO.fbo);
 		renderer.currentCamera.zoom = 80.f;
 		renderer.currentCamera.position.x = -440;
 		renderer.currentCamera.position.y = -500;
 		renderer.currentCamera3D.position.z = 2;
 
+
+		blurShader = gl2d::createPostProcessShaderFromFile(PIKA_RESOURCES_PATH "hollowknight/blur.frag");
+
+
 		if (!requestedInfo.readEntireFileBinary(PIKA_RESOURCES_PATH "hollowknight/inputMetrics.bin",
 			&inputMetrics, sizeof(inputMetrics)))
 		{
@@ -271,7 +293,7 @@ struct SilkSong: public Container
 		{
 			sfs::SafeSafeKeyValueData data;
 
-			pika::sfs::safeLoad(data, PIKA_RESOURCES_PATH "hollowknight/map", false);
+			pika::sfs::safeLoad(data, PIKA_RESOURCES_PATH "hollowknight/map2", false);
 
 			void *geometry = 0;
 			size_t s = 0;
@@ -279,10 +301,10 @@ struct SilkSong: public Container
 			{
 				SavedBlock *b = (SavedBlock*)geometry;
 
-				for (int i = 0; i < s / sizeof(SavedBlock); i++)
-				{
-					blocks[i].create(world, b[i].dimensions, b[i].rotation, b[i].type);
-				}
+				//for (int i = 0; i < s / sizeof(SavedBlock); i++)
+				//{
+				//	blocks[i].create(world, b[i].dimensions, b[i].rotation, b[i].type);
+				//}
 			}
 			else
 			{
@@ -295,7 +317,7 @@ struct SilkSong: public Container
 			{
 				GameSprite *loagedGameSprites = (GameSprite *)loadedSprites;
 
-				for (int i = 0; i < s / sizeof(SavedBlock); i++)
+				for (int i = 0; i < s / sizeof(GameSprite); i++)
 				{
 					gameSprites.push_back(loagedGameSprites[i]);
 				}
@@ -309,6 +331,11 @@ struct SilkSong: public Container
 		character.physicalBody.dynamicBody->SetFixedRotation(true);
 		characterJumpSensor = character.physicalBody.addSensor({0, 0.5, 0.55f, 0.1f});
 
+
+		Block floor;
+		floor.create(world, {-1000, 10, 2000, 1}, 0, b2BodyType::b2_staticBody);
+
+
 		return true;
 	}
 
@@ -318,11 +345,14 @@ struct SilkSong: public Container
 		RequestedContainerInfo &requestedInfo)
 	{
 	#pragma region clear stuff
-		glClear(GL_COLOR_BUFFER_BIT);
+		//glBindFramebuffer(GL_FRAMEBUFFER, fbo.fbo);
+		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 		renderer.updateWindowMetrics(windowState.windowW, windowState.windowH);
+		fbo.resize(windowState.windowW, windowState.windowH);
 	#pragma endregion
 
 	#pragma region input
+		requestedInfo.requestedFBO.depthTexture;
 
 		//::pika::gl2d::cameraController(renderer.currentCamera, input, 60 * (!followPlayer), 4);
 
@@ -475,7 +505,34 @@ struct SilkSong: public Container
 
 	#pragma region render
 
-		for (int i = 0; i < 4; i++)
+		//background
+
+		{
+			int index = 0;
+			for (auto &s : gameSprites)
+			{
+				if (s.layer == 0)
+				{
+		
+					if (currentSelectedSprite == index && selectType == 2)
+					{
+						renderer.renderRectangle({glm::vec2(s.pos), glm::vec2(assets[s.type].GetSize()) * s.scale * (1.f / 400.f)},
+							assets[s.type], {1,0.7,0.7,1.0}, {}, s.rotation, s.flip ? glm::vec4(1, 1, 0, 0) : glm::vec4(0, 1, 1, 0), s.pos.z);
+					}
+					else
+					{
+						renderer.renderRectangle({glm::vec2(s.pos), glm::vec2(assets[s.type].GetSize()) * s.scale * (1.f / 400.f)},
+							assets[s.type], s.color, {}, s.rotation, s.flip ? glm::vec4(1, 1, 0, 0) : glm::vec4(0, 1, 1, 0), s.pos.z);
+					}
+				}
+		
+				index++;
+			}
+		}
+		renderer.flushPostProcess({blurShader});
+
+
+		for (int i = 1; i < 4; i++)
 		{
 			//player
 			if (i == 3)
@@ -493,12 +550,12 @@ struct SilkSong: public Container
 					if (currentSelectedSprite == index && selectType == 2)
 					{
 						renderer.renderRectangle({glm::vec2(s.pos), glm::vec2(assets[s.type].GetSize()) * s.scale * (1.f / 400.f)},
-							assets[s.type], {1,0.5,0.5,1.0}, {}, s.rotation, s.flip ? glm::vec4(1, 1, 0, 0) : glm::vec4(0, 1, 1, 0), index * 0.1);
+							assets[s.type], {1,0.7,0.7,1.0}, {}, s.rotation, s.flip ? glm::vec4(1, 1, 0, 0) : glm::vec4(0, 1, 1, 0), s.pos.z);
 					}
 					else
 					{
 						renderer.renderRectangle({glm::vec2(s.pos), glm::vec2(assets[s.type].GetSize()) * s.scale * (1.f / 400.f)},
-							assets[s.type], Colors_White, {}, s.rotation, s.flip ? glm::vec4(1, 1, 0, 0) : glm::vec4(0, 1, 1, 0), index * 0.1);
+							assets[s.type], s.color, {}, s.rotation, s.flip ? glm::vec4(1, 1, 0, 0) : glm::vec4(0, 1, 1, 0), s.pos.z);
 					}
 				}
 
@@ -627,13 +684,13 @@ struct SilkSong: public Container
 		{
 			ImGui::Begin("Game Editor");
 
-			if (ImGui::Button("Spawn"))
-			{
-				for (int i = 0; i < 10; i++)
-				{
-					blocks[i].create(world, {1 + sin(i) * 5, -1.5 * i, 1,1}, 0, b2BodyType::b2_dynamicBody);
-				}
-			}
+			//if (ImGui::Button("Spawn"))
+			//{
+			//	for (int i = 0; i < 10; i++)
+			//	{
+			//		blocks[i].create(world, {1 + sin(i) * 5, -1.5 * i, 1,1}, 0, b2BodyType::b2_dynamicBody);
+			//	}
+			//}
 
 			ImGui::DragFloat2("Camera pos", &renderer.currentCamera.position[0], 0.001);
 			ImGui::DragFloat("Camera zoom", &renderer.currentCamera.zoom, 0.5, 10, 1000);
@@ -739,7 +796,7 @@ struct SilkSong: public Container
 				
 				}
 
-				ImGui::DragFloat2("Pos: ", &pos.x, 0.1);
+				ImGui::DragFloat3("Pos: ", &pos.x, 0.1);
 				ImGui::SliderAngle("Angle", &angle);
 
 				currentBodySelected->SetTransform(pos, angle);
@@ -758,6 +815,12 @@ struct SilkSong: public Container
 					gameSprites.push_back({});
 					currentSelectedSprite = gameSprites.size() - 1;
 				}
+
+				if (currentSelectedSprite > 0 && currentSelectedSprite < gameSprites.size())
+				if (ImGui::Button("Remove sprite"))
+				{
+					gameSprites.erase(gameSprites.begin() + currentSelectedSprite);
+				}
 				
 				ImGui::InputInt("Sprite", &currentSelectedSprite);
 
@@ -775,9 +838,11 @@ struct SilkSong: public Container
 
 					ImGui::DragFloat3("Pos", &s.pos[0], 0.01);
 
+					ImGui::ColorEdit4("Color", &s.color[0]);
+
 					ImGui::Checkbox("Flip", &s.flip);
 
-					ImGui::SliderAngle("Angle", &s.rotation);
+					ImGui::SliderFloat("Angle", &s.rotation, -360, 360, "%.00f deg");
 
 					ImGui::DragFloat("Scale", &s.scale, 0.01, 0.001, 100);
 
@@ -792,24 +857,23 @@ struct SilkSong: public Container
 
 			if (ImGui::Button("Save map"))
 			{
-				SavedBlock b[10];
-
-				for (int i = 0; i < 10; i++)
-				{
-					b[i].dimensions = glm::vec4(blocks[i].getPosTopLeft(), blocks[i].getSize());
-					b[i].rotation = blocks[i].getRotation();
-					b[i].type = blocks[i].dynamicBody->GetType();
-				}
+				//SavedBlock b[10];
+				//for (int i = 0; i < 10; i++)
+				//{
+				//	b[i].dimensions = glm::vec4(blocks[i].getPosTopLeft(), blocks[i].getSize());
+				//	b[i].rotation = blocks[i].getRotation();
+				//	b[i].type = blocks[i].dynamicBody->GetType();
+				//}
 
 				sfs::SafeSafeKeyValueData data;
 
-				data.setRawData("geometry", b, sizeof(b));
+				//data.setRawData("geometry", b, sizeof(b));
 
 				data.setRawData("sprites", gameSprites.data(), sizeof(GameSprite) *gameSprites.size());
 
 
 				pika::memory::pushCustomAllocatorsToStandard();
-				sfs::safeSave(data, PIKA_RESOURCES_PATH "hollowknight/map", false);
+				sfs::safeSave(data, PIKA_RESOURCES_PATH "hollowknight/map2", false);
 				pika::memory::popCustomAllocatorsToStandard();
 
 			}
@@ -818,8 +882,11 @@ struct SilkSong: public Container
 			ImGui::End();
 		}
 
-		requestedInfo.writeEntireFileBinary(PIKA_RESOURCES_PATH "hollowknight/inputMetrics.bin",
-			&inputMetrics, sizeof(inputMetrics));
+		//renderer.renderRectangle({0,0, renderer.windowW, renderer.windowH}, fbo.texture);
+		//renderer.flushFBO(gl2d::FrameBuffer{requestedInfo.requestedFBO.fbo});
+
+		//requestedInfo.writeEntireFileBinary(PIKA_RESOURCES_PATH "hollowknight/inputMetrics.bin",
+		//	&inputMetrics, sizeof(inputMetrics));
 
 	#pragma endregion
 

BIN
Pika/resources/hollowknight/background2.jpg


BIN
Pika/resources/hollowknight/block1.png


BIN
Pika/resources/hollowknight/block2.png


BIN
Pika/resources/hollowknight/block3.png


BIN
Pika/resources/hollowknight/block4.png


+ 24 - 0
Pika/resources/hollowknight/blur.frag

@@ -0,0 +1,24 @@
+#version 330
+precision highp float;
+
+out vec4 color;
+in vec2 v_positions;
+uniform sampler2D u_sampler;
+
+void main()
+{
+	ivec2 s = textureSize(u_sampler, 0).xy;
+
+	vec2 texelSize = vec2(1.f) / s;
+
+	vec3 rez = vec3(0.f);
+
+	for(int i=-3; i<=3; i++)
+		for(int j=-3; j<=3; j++)
+		{
+			rez += texture2D(u_sampler, 
+				(v_positions + vec2(1.f))/2.f + texelSize*vec2(i,j)).rgb * (1.f / 49.f);
+		}
+
+	color = vec4(rez,1);
+}

BIN
Pika/resources/hollowknight/bush.png


BIN
Pika/resources/hollowknight/bush2.png


BIN
Pika/resources/hollowknight/bush3.png


BIN
Pika/resources/hollowknight/grass.png


BIN
Pika/resources/hollowknight/grass2.png


BIN
Pika/resources/hollowknight/grass3.png


BIN
Pika/resources/hollowknight/grassDecoration.png


BIN
Pika/resources/hollowknight/grassDecorationBig.png


BIN
Pika/resources/hollowknight/map21.bin


BIN
Pika/resources/hollowknight/map22.bin


BIN
Pika/resources/hollowknight/mushroom7.png


BIN
Pika/resources/hollowknight/mushroom8.png


BIN
Pika/resources/hollowknight/old/background.jpg


BIN
Pika/resources/hollowknight/old/block1.png


BIN
Pika/resources/hollowknight/old/block2.png


BIN
Pika/resources/hollowknight/old/block3.png


BIN
Pika/resources/hollowknight/old/block4.png


BIN
Pika/resources/hollowknight/old/bush.png


BIN
Pika/resources/hollowknight/old/grass.png


BIN
Pika/resources/hollowknight/old/grass2.png


BIN
Pika/resources/hollowknight/old/grass3.png


BIN
Pika/resources/hollowknight/old/vines1.png


BIN
Pika/resources/hollowknight/old/vines2.png


BIN
Pika/resources/hollowknight/old/vines3.png


BIN
Pika/resources/hollowknight/stones.png


BIN
Pika/resources/hollowknight/stones2.png


BIN
Pika/resources/hollowknight/vines1.png


BIN
Pika/resources/hollowknight/vines2.png


BIN
Pika/resources/hollowknight/vines3.png


+ 8 - 2
Pika/resources/logs.txt

@@ -1,2 +1,8 @@
-#2025-06-06 12:36:09: Created container: SilkSong
-#2025-06-06 12:36:26: Destroyed continer: SilkSong #1
+#2025-06-06 16:00:00[error]: Error reading map file
+#2025-06-06 16:00:00: Created container: SilkSong
+#2025-06-06 16:00:21: Destroyed continer: SilkSong #1
+#2025-06-06 16:01:00[warning]: Couldn't reloaded dll
+#2025-06-06 16:01:02: Reloaded dll
+#2025-06-06 16:01:05[error]: Error reading map file
+#2025-06-06 16:01:05: Created container: SilkSong
+#2025-06-06 16:01:56: Destroyed continer: SilkSong #2

+ 1 - 0
Pika/thirdparty/gl2d/include/gl2d/gl2d.h

@@ -407,6 +407,7 @@ namespace gl2d
 	{
 		FrameBuffer() {};
 		explicit FrameBuffer(int w, int h) { create(w, h); };
+		explicit FrameBuffer(unsigned int fbo):fbo(fbo) { };
 
 		unsigned int fbo = 0;
 		Texture texture = {};

+ 53 - 9
Pika/thirdparty/gl2d/src/gl2d.cpp

@@ -779,6 +779,8 @@ or gladLoadGLLoader() or glewInit()?", userDefinedData);
 		glBindBuffer(GL_ARRAY_BUFFER, renderer.buffers[Renderer2DBufferType::texturePositions]);
 		glBufferData(GL_ARRAY_BUFFER, renderer.texturePositions.size() * sizeof(glm::vec2), renderer.texturePositions.data(), GL_STREAM_DRAW);
 
+		bool use3D = false;
+
 		//todo 2 different shaders to properly optimize this
 		if (renderer.currentShader.u_viewProjection >= 0)
 		{
@@ -788,6 +790,7 @@ or gladLoadGLLoader() or glewInit()?", userDefinedData);
 				renderer.currentCamera3D.aspectRatio = 1;
 
 				glUniformMatrix4fv(renderer.currentShader.u_viewProjection, 1, GL_FALSE, &renderer.currentCamera3D.getViewProjectionMatrix()[0][0]);
+				use3D = true;
 			}
 			else
 			{
@@ -796,6 +799,21 @@ or gladLoadGLLoader() or glewInit()?", userDefinedData);
 
 		}
 
+		GLint oldDepthFunc = 0;
+		GLboolean depthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
+
+		if (use3D)
+		{
+			glEnable(GL_DEPTH_TEST);
+
+			glGetIntegerv(GL_DEPTH_FUNC, &oldDepthFunc);
+			glDepthFunc(GL_LEQUAL);
+		}
+		else
+		{
+			glDisable(GL_DEPTH_TEST);
+		}
+
 		//Instance render the textures
 		{
 			const int size = renderer.spriteTextures.size();
@@ -823,6 +841,15 @@ or gladLoadGLLoader() or glewInit()?", userDefinedData);
 			glBindVertexArray(0);
 		}
 
+		if (use3D)
+		{
+			glDepthFunc(oldDepthFunc);
+			if (depthTestEnabled)
+				glEnable(GL_DEPTH_TEST);
+			if (!depthTestEnabled)
+				glDisable(GL_DEPTH_TEST);
+		}
+
 		if (clearDrawData)
 		{
 			renderer.clearDrawData();
@@ -860,14 +887,14 @@ or gladLoadGLLoader() or glewInit()?", userDefinedData);
 	//doesn't set the viewport
 	void renderQuadToScreenInternal(gl2d::Renderer2D &renderer)
 	{
-		static float positions[12] = {
-		-1, 1,
-		-1, -1,
-		1, 1,
+		static float positions[26] = {
+		-1, 1,0,1,
+		-1, -1,0,1,
+		1, 1,0,1,
 
-		1, 1,
-		-1, -1,
-		1, -1,};
+		1, 1,0,1,
+		-1, -1,0,1,
+		1, -1,0,1};
 
 		//not used
 		static float colors[6 * 4] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,};
@@ -881,6 +908,8 @@ or gladLoadGLLoader() or glewInit()?", userDefinedData);
 			1, 0,
 		};
 
+		enableNecessaryGLFeatures();
+		
 
 		glBindVertexArray(renderer.vao);
 
@@ -949,6 +978,11 @@ or gladLoadGLLoader() or glewInit()?", userDefinedData);
 		FrameBuffer frameBuffer, bool clearDrawData)
 	{
 
+		if (frameBuffer.fbo == 0)
+		{
+			frameBuffer.fbo = defaultFBO;
+		}
+
 		if (postProcesses.empty())
 		{
 			if (clearDrawData)
@@ -958,7 +992,7 @@ or gladLoadGLLoader() or glewInit()?", userDefinedData);
 			}
 		}
 
-		if (!postProcessFbo1.fbo) { postProcessFbo1.create(0, 0); }
+		if (!postProcessFbo1.fbo) { postProcessFbo1.create(windowW, windowH); }
 
 		postProcessFbo1.resize(windowW, windowH);
 		postProcessFbo1.clear();
@@ -2159,11 +2193,21 @@ or gladLoadGLLoader() or glewInit()?", userDefinedData);
 		GLfloat oldColor[4];
 		glGetFloatv(GL_COLOR_CLEAR_VALUE, oldColor);
 
+		GLfloat oldDepth;
+		glGetFloatv(GL_DEPTH_CLEAR_VALUE, &oldDepth);
+
 		glClearColor(color.r, color.g, color.b, color.a);
-		glClear(GL_COLOR_BUFFER_BIT);
+		glClearDepth(1.0f); // Optional, sets the value to which the depth buffer is cleared
+
+		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+		// Restore old state
 		glClearColor(oldColor[0], oldColor[1], oldColor[2], oldColor[3]);
+		glClearDepth(oldDepth);
 	#else
 		glClearBufferfv(GL_COLOR, 0, &color[0]);
+		GLfloat depthClearValue = 1.0f;
+		glClearBufferfv(GL_DEPTH, 0, &depthClearValue);
 	#endif
 
 	}