diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 6668b9e..25c03db 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -30,8 +30,8 @@ void Engine::Init() { glEnable(GL_CULL_FACE); glEnable(GL_BLEND); - glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); // , GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_SUBTRACT);// , GL_FUNC_ADD); + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); + glBlendEquation(GL_FUNC_SUBTRACT); // Objet de skybox avec sa propre texture et son propre shader! m_skybox.Init(0.2f); @@ -89,6 +89,7 @@ void Engine::UnloadResource() {} void Engine::DrawHud(float elapsedTime) { // Setter le blend function , tout ce qui sera noir sera transparent + glDisable(GL_STENCIL_TEST); glColor4f(1.f, 1.f, 1.f, 1.f); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendEquation(GL_FUNC_ADD); @@ -138,9 +139,10 @@ void Engine::DrawHud(float elapsedTime) { glTexCoord2f(0, 1); glVertex2i(0, crossSize); glEnd(); - glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); // , GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_SUBTRACT);// , GL_FUNC_ADD); + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); + glBlendEquation(GL_FUNC_SUBTRACT); glEnable(GL_DEPTH_TEST); + glEnable(GL_STENCIL_TEST); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); @@ -197,18 +199,13 @@ void Engine::Render(float elapsedTime) { else if (m_mouseR) m_world.ChangeBlockAtCursor(BTYPE_AIR, m_player, m_block); - glStencilFunc(GL_EQUAL, 1, 0x00); - glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); m_world.Update(m_renderCount, m_badHitCount, m_player, all, m_shader01, m_textureAtlas, m_perlin, m_blockinfo); - glStencilFunc(GL_GREATER, 1, 0xFF); if (m_isSkybox) m_skybox.Render(skybox); if (m_wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glDisable(GL_STENCIL_TEST); DrawHud(elapsedTime); - glEnable(GL_STENCIL_TEST); if (m_wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); diff --git a/SQCSim2021/player.cpp b/SQCSim2021/player.cpp index 005500c..0754a09 100644 --- a/SQCSim2021/player.cpp +++ b/SQCSim2021/player.cpp @@ -162,4 +162,3 @@ void Player::Teleport(int& x, int& z) { m_position.x -= x * CHUNK_SIZE_X; m_position.z -= z * CHUNK_SIZE_Z; } - diff --git a/SQCSim2021/world.cpp b/SQCSim2021/world.cpp index 473cd58..37e3e43 100644 --- a/SQCSim2021/world.cpp +++ b/SQCSim2021/world.cpp @@ -107,11 +107,14 @@ void World::GetScope(int& x, int& y) { } void World::Update(int& rendercount, int& badhitcount, Player& player, Transformation& world, Shader& shader, TextureAtlas& atlas, Perlin& perlin, BlockInfo* blockinfo[BTYPE_LAST]) { + glStencilFunc(GL_EQUAL, 1, 0x00); + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); atlas.Bind(); RenderWorld(rendercount, badhitcount, player, world, shader); TransposeWorld(player); UpdateWorld(player, perlin, blockinfo); shader.Disable(); + glStencilFunc(GL_GREATER, 1, 0xFF); } bool World::GenerateChunk(int chx, int chy, Perlin& perlin) { diff --git a/SQCSim2021/world.h b/SQCSim2021/world.h index 55eeb98..db8cc16 100644 --- a/SQCSim2021/world.h +++ b/SQCSim2021/world.h @@ -46,8 +46,6 @@ private: void RenderWorld(int& rendercount, int& badhitcount, Player& player, Transformation& world, Shader& shader); void UpdateWorld(Player& player, Perlin& perlin, BlockInfo* blockinfo[BTYPE_LAST]); void TransposeWorld(Player& player); - /*Chunk* RetrieveChunk(int x, int y);*/ - }; #endif // WORLD_H__