-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GWT - pixmap.drawLine() produces "antialias like" artifacts #6019
Comments
I have done some investigation and this seems to be a problem with the html canvas API, which is used under the hood and does not actually define how lines should be rendered. A quick search through Stack Overflow reveals, that the only reliable workaround would be to render the geometry pixel-by-pixel. For anyone wondering: The correct (but slow) fix would be to port the C code to Java(Script) to do this kind of drawing pixel by pixel. |
Ah that's interesting and quite a bummer. Since I'm luckily need to only draw really small lines (2-5px) I think I'll work around this by implementing a basic line drawer myself by setting each pixel manually. Since imo it's only a problem in certain scenario (e.g. if you need pixel precise placement with a small pixmap) I could imagine that some sort of toggle could be done in the pixmap which switches algorithms? |
Yes, that would be one way to do it, but making it nicely compatible with all other platforms could be tricky. |
another way is to use FBO (probably faster in most cases). FrameBuffer on WebGL 1.0 doesn't have antialiasing at all, and WebGL 2.0 has configurable antialiasing. |
Here's the code I wrote a couple months ago. If I remember correctly it's based on Bresenham's line algorithm. public void drawLine(int x0, int y0, int x1, int y1) {
boolean steep = Math.abs(y1 - y0) > Math.abs(x1 - x0);
if (steep) {
x0 += y0;
y0 = x0 - y0;
x0 -= y0;
x1 += y1;
y1 = x1 - y1;
x1 -= y1;
}
if (x0 > x1) {
x0 += x1;
x1 = x0 - x1;
x0 -= x1;
y0 += y1;
y1 = y0 - y1;
y0 -= y1;
}
int dX = (x1 - x0),
dY = Math.abs(y1 - y0),
err = (dX / 2),
ystep = (y0 < y1 ? 1 : -1),
y = y0;
for (int x = x0; x <= x1; ++x) {
if (steep)
drawPixel(y, x);
else
drawPixel(x, y);
err = err - dY;
if (err < 0) {
y += ystep;
err += dX;
}
}
} |
Since there is no general solution about this (drawing pixel by pixel may have performance cost), i'm closing it. I added a note about it in the wiki with a reference to last @lyze237 comment. |
Please ensure you have given all the following requested information in your report.
Issue details
I have a basic pixmap (e.g. 8x8 px), when I draw a line from 0,0 to 8,8 the line produces half transparent pixels at positions where there should be no line.
I've tried it with with both blending modes (none, source over) as well with both filtering modes.
Also I've verified that this is a pixmap problem and not a texture problem since the color at 0,1 should be white but it isn't.
Other methods which work fine: pixmap.drawPixel(), pixmap.fillRect()
Other methods which don't work: pixmap.drawRect()
Reproduction steps/code
Version of LibGDX and/or relevant dependencies
Please select the affected platforms
The text was updated successfully, but these errors were encountered: