aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/core_3d_camera_first_person.c9
-rw-r--r--examples/core_3d_camera_first_person.pngbin18402 -> 18883 bytes
-rw-r--r--examples/core_3d_camera_free.c17
-rw-r--r--examples/core_3d_camera_free.pngbin25167 -> 25293 bytes
-rw-r--r--examples/core_3d_picking.c2
-rw-r--r--examples/shapes_basic_shapes.pngbin26439 -> 30382 bytes
-rw-r--r--examples/textures_srcrec_dstrec.pngbin48478 -> 47563 bytes
-rw-r--r--src/core.c4
-rw-r--r--src/rlgl.c14
-rw-r--r--src/rlgl.h2
-rw-r--r--src/shapes.c80
11 files changed, 93 insertions, 35 deletions
diff --git a/examples/core_3d_camera_first_person.c b/examples/core_3d_camera_first_person.c
index 16d388df..56e38a23 100644
--- a/examples/core_3d_camera_first_person.c
+++ b/examples/core_3d_camera_first_person.c
@@ -74,10 +74,13 @@ int main()
}
End3dMode();
+
+ DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f));
+ DrawRectangleLines( 10, 10, 220, 70, BLUE);
- DrawText("First person camera default controls:", 20, 20, 10, GRAY);
- DrawText("- Move with keys: W, A, S, D", 40, 50, 10, DARKGRAY);
- DrawText("- Mouse move to look around", 40, 70, 10, DARKGRAY);
+ DrawText("First person camera default controls:", 20, 20, 10, BLACK);
+ DrawText("- Move with keys: W, A, S, D", 40, 40, 10, DARKGRAY);
+ DrawText("- Mouse move to look around", 40, 60, 10, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
diff --git a/examples/core_3d_camera_first_person.png b/examples/core_3d_camera_first_person.png
index 9373da2d..7130b0a2 100644
--- a/examples/core_3d_camera_first_person.png
+++ b/examples/core_3d_camera_first_person.png
Binary files differ
diff --git a/examples/core_3d_camera_free.c b/examples/core_3d_camera_free.c
index 234c46b3..fa7ad85f 100644
--- a/examples/core_3d_camera_free.c
+++ b/examples/core_3d_camera_free.c
@@ -59,13 +59,16 @@ int main()
DrawGrid(10, 1.0f);
End3dMode();
-
- DrawText("Free camera default controls:", 20, 20, 10, GRAY);
- DrawText("- Mouse Wheel to Zoom in-out", 40, 50, 10, DARKGRAY);
- DrawText("- Mouse Wheel Pressed to Pan", 40, 70, 10, DARKGRAY);
- DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 90, 10, DARKGRAY);
- DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 110, 10, DARKGRAY);
- DrawText("- Z to zoom to (0, 0, 0)", 40, 130, 10, DARKGRAY);
+
+ DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5f));
+ DrawRectangleLines( 10, 10, 320, 133, BLUE);
+
+ DrawText("Free camera default controls:", 20, 20, 10, BLACK);
+ DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, DARKGRAY);
+ DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, DARKGRAY);
+ DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, DARKGRAY);
+ DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, DARKGRAY);
+ DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
diff --git a/examples/core_3d_camera_free.png b/examples/core_3d_camera_free.png
index 17920620..8857a478 100644
--- a/examples/core_3d_camera_free.png
+++ b/examples/core_3d_camera_free.png
Binary files differ
diff --git a/examples/core_3d_picking.c b/examples/core_3d_picking.c
index 33eaed8a..da303107 100644
--- a/examples/core_3d_picking.c
+++ b/examples/core_3d_picking.c
@@ -77,7 +77,7 @@ int main()
End3dMode();
- DrawText("Try selecting the box with mouse!", 240, 10, 20, GRAY);
+ DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY);
if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN);
diff --git a/examples/shapes_basic_shapes.png b/examples/shapes_basic_shapes.png
index 03ecf2ec..a7d4a991 100644
--- a/examples/shapes_basic_shapes.png
+++ b/examples/shapes_basic_shapes.png
Binary files differ
diff --git a/examples/textures_srcrec_dstrec.png b/examples/textures_srcrec_dstrec.png
index 7459d6ec..9ea00fe4 100644
--- a/examples/textures_srcrec_dstrec.png
+++ b/examples/textures_srcrec_dstrec.png
Binary files differ
diff --git a/src/core.c b/src/core.c
index 7d229324..d27a031b 100644
--- a/src/core.c
+++ b/src/core.c
@@ -643,6 +643,8 @@ void Begin3dMode(Camera camera)
// Setup Camera view
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
rlMultMatrixf(MatrixToFloat(matView)); // Multiply MODELVIEW matrix by view matrix (camera)
+
+ rlEnableDepthTest(); // Enable DEPTH_TEST for 3D
}
// Ends 3D mode and returns to default 2D orthographic mode
@@ -657,6 +659,8 @@ void End3dMode(void)
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
//rlTranslatef(0.375, 0.375, 0); // HACK to ensure pixel-perfect drawing on OpenGL (after exiting 3D mode)
+
+ rlDisableDepthTest(); // Disable DEPTH_TEST for 2D
}
// Set target FPS for the game
diff --git a/src/rlgl.c b/src/rlgl.c
index d9761732..f9722eda 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -780,6 +780,18 @@ void rlDisableTexture(void)
#endif
}
+// Enable depth test
+void rlEnableDepthTest(void)
+{
+ glEnable(GL_DEPTH_TEST);
+}
+
+// Disable depth test
+void rlDisableDepthTest(void)
+{
+ glDisable(GL_DEPTH_TEST);
+}
+
// Unload texture from GPU memory
void rlDeleteTextures(unsigned int id)
{
@@ -1579,7 +1591,7 @@ void rlglInitGraphics(int offsetX, int offsetY, int width, int height)
//glClearDepth(1.0f); // Clear depth buffer (default)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear used buffers, depth buffer is used for 3D
- glEnable(GL_DEPTH_TEST); // Enables depth testing (required for 3D)
+ glDisable(GL_DEPTH_TEST); // Disable depth testing for 2D (only used for 3D)
glDepthFunc(GL_LEQUAL); // Type of depth testing to apply
glEnable(GL_BLEND); // Enable color blending (required to work with transparencies)
diff --git a/src/rlgl.h b/src/rlgl.h
index 69640feb..7d50b67a 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -244,6 +244,8 @@ void rlColor4f(float x, float y, float z, float w); // Define one vertex (color)
//------------------------------------------------------------------------------------
void rlEnableTexture(unsigned int id); // Enable texture usage
void rlDisableTexture(void); // Disable texture usage
+void rlEnableDepthTest(void); // Enable depth test
+void rlDisableDepthTest(void); // Disable depth test
void rlDeleteTextures(unsigned int id); // Delete OpenGL texture from GPU
void rlDeleteShader(unsigned int id); // Delete OpenGL shader program from GPU
void rlDeleteVertexArrays(unsigned int id); // Unload vertex data (VAO) from GPU memory
diff --git a/src/shapes.c b/src/shapes.c
index 7e3b5634..14d11315 100644
--- a/src/shapes.c
+++ b/src/shapes.c
@@ -98,7 +98,7 @@ void DrawLineV(Vector2 startPos, Vector2 endPos, Color color)
// Draw a color-filled circle
void DrawCircle(int centerX, int centerY, float radius, Color color)
{
- DrawPoly((Vector2){ centerX, centerY }, 36, radius, 0, color);
+ DrawCircleV((Vector2){ centerX, centerY }, radius, color);
}
// Draw a gradient-filled circle
@@ -119,17 +119,40 @@ void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Co
}
// Draw a color-filled circle (Vector version)
+// NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw)
void DrawCircleV(Vector2 center, float radius, Color color)
{
- rlBegin(RL_TRIANGLES);
- for (int i = 0; i < 360; i += 10)
- {
- rlColor4ub(color.r, color.g, color.b, color.a);
- rlVertex2i(center.x, center.y);
- rlVertex2f(center.x + sin(DEG2RAD*i)*radius, center.y + cos(DEG2RAD*i)*radius);
- rlVertex2f(center.x + sin(DEG2RAD*(i + 10)) * radius, center.y + cos(DEG2RAD*(i + 10)) * radius);
- }
- rlEnd();
+ if (rlGetVersion() == OPENGL_11)
+ {
+ rlBegin(RL_TRIANGLES);
+ for (int i = 0; i < 360; i += 10)
+ {
+ rlColor4ub(color.r, color.g, color.b, color.a);
+
+ rlVertex2i(center.x, center.y);
+ rlVertex2f(center.x + sin(DEG2RAD*i)*radius, center.y + cos(DEG2RAD*i)*radius);
+ rlVertex2f(center.x + sin(DEG2RAD*(i + 10)) * radius, center.y + cos(DEG2RAD*(i + 10)) * radius);
+ }
+ rlEnd();
+ }
+ else if ((rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20))
+ {
+ rlEnableTexture(whiteTexture); // Default white texture
+
+ rlBegin(RL_QUADS);
+ for (int i = 0; i < 360; i += 20)
+ {
+ rlColor4ub(color.r, color.g, color.b, color.a);
+
+ rlVertex2i(center.x, center.y);
+ rlVertex2f(center.x + sin(DEG2RAD*i)*radius, center.y + cos(DEG2RAD*i)*radius);
+ rlVertex2f(center.x + sin(DEG2RAD*(i + 10)) * radius, center.y + cos(DEG2RAD*(i + 10)) * radius);
+ rlVertex2f(center.x + sin(DEG2RAD*(i + 20)) * radius, center.y + cos(DEG2RAD*(i + 20)) * radius);
+ }
+ rlEnd();
+
+ rlDisableTexture();
+ }
}
// Draw circle outline
@@ -178,6 +201,7 @@ void DrawRectangleGradient(int posX, int posY, int width, int height, Color colo
}
// Draw a color-filled rectangle (Vector version)
+// NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw)
void DrawRectangleV(Vector2 position, Vector2 size, Color color)
{
if (rlGetVersion() == OPENGL_11)
@@ -196,7 +220,6 @@ void DrawRectangleV(Vector2 position, Vector2 size, Color color)
}
else if ((rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20))
{
- // NOTE: This shape uses QUADS to avoid drawing order issues (view rlglDraw)
rlEnableTexture(whiteTexture); // Default white texture
rlBegin(RL_QUADS);
@@ -221,22 +244,33 @@ void DrawRectangleV(Vector2 position, Vector2 size, Color color)
}
// Draw rectangle outline
+// NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw)
void DrawRectangleLines(int posX, int posY, int width, int height, Color color)
-{
- rlBegin(RL_LINES);
- rlColor4ub(color.r, color.g, color.b, color.a);
- rlVertex2i(posX + 1, posY + 1);
- rlVertex2i(posX + width, posY + 1);
+{
+ if (rlGetVersion() == OPENGL_11)
+ {
+ rlBegin(RL_LINES);
+ rlColor4ub(color.r, color.g, color.b, color.a);
+ rlVertex2i(posX + 1, posY + 1);
+ rlVertex2i(posX + width, posY + 1);
- rlVertex2i(posX + width, posY + 1);
- rlVertex2i(posX + width, posY + height);
+ rlVertex2i(posX + width, posY + 1);
+ rlVertex2i(posX + width, posY + height);
- rlVertex2i(posX + width, posY + height);
- rlVertex2i(posX + 1, posY + height);
+ rlVertex2i(posX + width, posY + height);
+ rlVertex2i(posX + 1, posY + height);
- rlVertex2i(posX + 1, posY + height);
- rlVertex2i(posX + 1, posY + 1);
- rlEnd();
+ rlVertex2i(posX + 1, posY + height);
+ rlVertex2i(posX + 1, posY + 1);
+ rlEnd();
+ }
+ else if ((rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20))
+ {
+ DrawRectangle(posX, posY, width, 1, color);
+ DrawRectangle(posX + width - 1, posY + 1, 1, height - 2, color);
+ DrawRectangle(posX, posY + height - 1, width, 1, color);
+ DrawRectangle(posX, posY + 1, 1, height - 2, color);
+ }
}
// Draw a triangle