aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2015-09-21 12:48:43 +0200
committerRay <raysan5@gmail.com>2015-09-21 12:48:43 +0200
commit6ffb3c72fbbdd73467e7ef36b542f20a5b1f9300 (patch)
tree91c29dd4360112c28bace784e0a3458696fcc4a0 /src
parent544df87a8e636ed3c2b14200218bd76318b6947d (diff)
downloadraylib-6ffb3c72fbbdd73467e7ef36b542f20a5b1f9300.tar.gz
raylib-6ffb3c72fbbdd73467e7ef36b542f20a5b1f9300.zip
Solved bug with depth when drawing...
...shapes based on LINES, TRIANGLES and QUADS. Now the calling order of the drawing functions is respected!
Diffstat (limited to 'src')
-rw-r--r--src/rlgl.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/rlgl.c b/src/rlgl.c
index ec23e988..70a03047 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -200,6 +200,8 @@ static int currentMatrixMode;
static DrawMode currentDrawMode;
+static float currentDepth = -1.0f;
+
// Vertex arrays for lines, triangles and quads
static VertexPositionColorBuffer lines; // No texture support
static VertexPositionColorBuffer triangles; // No texture support
@@ -580,6 +582,11 @@ void rlEnd(void)
} break;
default: break;
}
+
+ // NOTE: Depth increment is dependant on rlOrtho(): z-near and z-far values,
+ // as well as depth buffer bit-depth (16bit or 24bit or 32bit)
+ // Correct increment formula would be: depthInc = (zfar - znear)/pow(2, bits)
+ currentDepth += (1.0f/20000.0f);
}
// Define one vertex (position)
@@ -648,13 +655,13 @@ void rlVertex3f(float x, float y, float z)
// Define one vertex (position)
void rlVertex2f(float x, float y)
{
- rlVertex3f(x, y, 0.0f);
+ rlVertex3f(x, y, currentDepth);
}
// Define one vertex (position)
void rlVertex2i(int x, int y)
{
- rlVertex3f((float)x, (float)y, 0.0f);
+ rlVertex3f((float)x, (float)y, currentDepth);
}
// Define one vertex (texture coordinate)
@@ -1395,6 +1402,9 @@ void rlglDraw(void)
quads.vCounter = 0;
quads.tcCounter = 0;
quads.cCounter = 0;
+
+ // Reset depth for next draw
+ currentDepth = -1.0f;
#endif
}
@@ -1583,7 +1593,7 @@ void rlglInitGraphics(int offsetX, int offsetY, int width, int height)
rlMatrixMode(RL_PROJECTION); // Switch to PROJECTION matrix
rlLoadIdentity(); // Reset current matrix (PROJECTION)
- rlOrtho(0, width - offsetX, height - offsetY, 0, 0, 1); // Config orthographic mode: top-left corner --> (0,0)
+ rlOrtho(0, width - offsetX, height - offsetY, 0, 0.0f, 1.0f); // Config orthographic mode: top-left corner --> (0,0)
rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix
rlLoadIdentity(); // Reset current matrix (MODELVIEW)