summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorhkc <[email protected]>2022-10-11 19:45:34 +0300
committerGitHub <[email protected]>2022-10-11 18:45:34 +0200
commit8ebe62b4dd89cf3f6228d6a5c339c35b0ac25c31 (patch)
treed9fe1a1acb9ffd70a81fcf457c384c8ddc363873
parent4cca234f46fcdac4541ceb26b753ca5f73e8a819 (diff)
downloadraylib-8ebe62b4dd89cf3f6228d6a5c339c35b0ac25c31.tar.gz
raylib-8ebe62b4dd89cf3f6228d6a5c339c35b0ac25c31.zip
Use RL_QUADS/RL_TRIANGLES for single-pixel drawing (#2750)
Addresses problem mentioned in https://github.com/raysan5/raylib/issues/2744#issuecomment-1273568263 (in short: when drawing pixels using DrawPixel{,V} in camera mode, upscaled pixel becomes a line instead of bigger pixel)
-rw-r--r--src/rshapes.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/rshapes.c b/src/rshapes.c
index f8d9db71..7e4cad74 100644
--- a/src/rshapes.c
+++ b/src/rshapes.c
@@ -104,21 +104,50 @@ void SetShapesTexture(Texture2D texture, Rectangle source)
// Draw a pixel
void DrawPixel(int posX, int posY, Color color)
{
- rlBegin(RL_LINES);
- rlColor4ub(color.r, color.g, color.b, color.a);
- rlVertex2f(posX, posY);
- rlVertex2f(posX + 1, posY + 1);
- rlEnd();
+ DrawPixelV((Vector2){ posX, posY }, color);
}
// Draw a pixel (Vector version)
void DrawPixelV(Vector2 position, Color color)
{
- rlBegin(RL_LINES);
+#if defined(SUPPORT_QUADS_DRAW_MODE)
+ rlSetTexture(texShapes.id);
+
+ rlBegin(RL_QUADS);
+
+ rlNormal3f(0.0f, 0.0f, 1.0f);
+ rlColor4ub(color.r, color.g, color.b, color.a);
+
+ rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height);
+ rlVertex2f(position.x, position.y);
+
+ rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height);
+ rlVertex2f(position.x, position.y + 1);
+
+ rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height);
+ rlVertex2f(position.x + 1, position.y + 1);
+
+ rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height);
+ rlVertex2f(position.x + 1, position.y);
+
+ rlEnd();
+
+ rlSetTexture(0);
+#else
+ rlBegin(RL_TRIANGLES);
+
rlColor4ub(color.r, color.g, color.b, color.a);
+
rlVertex2f(position.x, position.y);
- rlVertex2f(position.x + 1.0f, position.y + 1.0f);
+ rlVertex2f(position.x, position.y + 1);
+ rlVertex2f(position.x + 1, position.y);
+
+ rlVertex2f(position.x + 1, position.y);
+ rlVertex2f(position.x, position.y + 1);
+ rlVertex2f(position.x + 1, position.y + 1);
+
rlEnd();
+#endif
}
// Draw a line