Skip to content

Commit 8ebe62b

Browse files
authored
Use RL_QUADS/RL_TRIANGLES for single-pixel drawing (#2750)
Addresses problem mentioned in #2744 (comment) (in short: when drawing pixels using DrawPixel{,V} in camera mode, upscaled pixel becomes a line instead of bigger pixel)
1 parent 4cca234 commit 8ebe62b

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

src/rshapes.c

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,50 @@ void SetShapesTexture(Texture2D texture, Rectangle source)
104104
// Draw a pixel
105105
void DrawPixel(int posX, int posY, Color color)
106106
{
107-
rlBegin(RL_LINES);
108-
rlColor4ub(color.r, color.g, color.b, color.a);
109-
rlVertex2f(posX, posY);
110-
rlVertex2f(posX + 1, posY + 1);
111-
rlEnd();
107+
DrawPixelV((Vector2){ posX, posY }, color);
112108
}
113109

114110
// Draw a pixel (Vector version)
115111
void DrawPixelV(Vector2 position, Color color)
116112
{
117-
rlBegin(RL_LINES);
113+
#if defined(SUPPORT_QUADS_DRAW_MODE)
114+
rlSetTexture(texShapes.id);
115+
116+
rlBegin(RL_QUADS);
117+
118+
rlNormal3f(0.0f, 0.0f, 1.0f);
119+
rlColor4ub(color.r, color.g, color.b, color.a);
120+
121+
rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height);
122+
rlVertex2f(position.x, position.y);
123+
124+
rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height);
125+
rlVertex2f(position.x, position.y + 1);
126+
127+
rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height);
128+
rlVertex2f(position.x + 1, position.y + 1);
129+
130+
rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height);
131+
rlVertex2f(position.x + 1, position.y);
132+
133+
rlEnd();
134+
135+
rlSetTexture(0);
136+
#else
137+
rlBegin(RL_TRIANGLES);
138+
118139
rlColor4ub(color.r, color.g, color.b, color.a);
140+
119141
rlVertex2f(position.x, position.y);
120-
rlVertex2f(position.x + 1.0f, position.y + 1.0f);
142+
rlVertex2f(position.x, position.y + 1);
143+
rlVertex2f(position.x + 1, position.y);
144+
145+
rlVertex2f(position.x + 1, position.y);
146+
rlVertex2f(position.x, position.y + 1);
147+
rlVertex2f(position.x + 1, position.y + 1);
148+
121149
rlEnd();
150+
#endif
122151
}
123152

124153
// Draw a line

0 commit comments

Comments
 (0)