Skip to content

Commit 3f17f0e

Browse files
committed
add depth support
1 parent d00c841 commit 3f17f0e

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Source/Renderer/RenderTarget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "GLCheck.h"
55
#include "raylib/rlgl.h"
66
#include "WindowMan.h"
7+
#include "Constants.h"
78

89
#include "glm/glm.hpp"
910
#include "glm/gtc/matrix_transform.hpp"
@@ -63,7 +64,7 @@ void RenderTarget::Begin(bool clear) {
6364

6465
rlMatrixMode(RL_PROJECTION);
6566
rlLoadIdentity();
66-
rlOrtho(0.0f, m_Size.w, m_Size.h, 0.0f, -1.0f, 1.0f);
67+
rlOrtho(0.0f, m_Size.w, m_Size.h, 0.0f, c_NearDepth, c_FarDepth);
6768
rlMatrixMode(RL_MODELVIEW);
6869
rlLoadIdentity();
6970

Source/Renderer/raylib/rlgl.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,16 +740,20 @@ void rlVertex3f(float x, float y, float z)
740740
RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount++;
741741
}
742742

743+
void rlZDepth(float z) {
744+
RLGL.currentBatch->currentZ = z;
745+
}
746+
743747
// Define one vertex (position)
744748
void rlVertex2f(float x, float y)
745749
{
746-
rlVertex3f(x, y, RLGL.currentBatch->currentDepth);
750+
rlVertex3f(x, y, RLGL.currentBatch->currentDepth - RLGL.currentBatch->currentZ);
747751
}
748752

749753
// Define one vertex (position)
750754
void rlVertex2i(int x, int y)
751755
{
752-
rlVertex3f((float)x, (float)y, RLGL.currentBatch->currentDepth);
756+
rlVertex3f((float)x, (float)y, RLGL.currentBatch->currentDepth - RLGL.currentBatch->currentZ);
753757
}
754758

755759
// Define one vertex (texture coordinate)

Source/Renderer/raylib/rlgl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ typedef struct rlRenderBatch {
423423
rlDrawCall *draws; // Draw calls array, depends on textureId
424424
int drawCounter; // Draw calls counter
425425
float currentDepth; // Current depth value for next draw
426+
float currentZ; // Current z order added to depth.
426427
} rlRenderBatch;
427428

428429
// OpenGL version
@@ -629,6 +630,7 @@ RLAPI void rlNormal3f(float x, float y, float z); // Define one vertex (no
629630
RLAPI void rlColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a); // Define one vertex (color) - 4 byte
630631
RLAPI void rlColor3f(float x, float y, float z); // Define one vertex (color) - 3 float
631632
RLAPI void rlColor4f(float x, float y, float z, float w); // Define one vertex (color) - 4 float
633+
RLAPI void rlZDepth(float z); // Set current draw depth for Vertex2(i,f).
632634

633635
//------------------------------------------------------------------------------------
634636
// Functions Declaration - OpenGL style functions (common to 1.1, 3.3+, ES2)

Source/System/Constants.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ namespace RTE {
142142
1.0f, -1.0f, 1.0f, 1.0f,
143143
-1.0f, 1.0f, 0.0f, 0.0f,
144144
-1.0f, -1.0f, 0.0f, 1.0f};
145+
146+
static constexpr float c_GuiDepth = -100.0f;
147+
static constexpr float c_DefaultDrawDepth = 0.0f;
148+
static constexpr float c_TerrainBGDepth = 50.0f;
149+
static constexpr float c_BackgroundDepth = 100.0f;
150+
151+
static constexpr float c_FarDepth = 200.0f;
152+
static constexpr float c_NearDepth = -200.0f;
145153
#pragma endregion
146154

147155
#pragma region Math Constants

0 commit comments

Comments
 (0)