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
P2D low quality text rendering #1972
Comments
Perhaps Signed Distance Fields can be used to render higher quality text in OpenGL. See: https://github.com/paulhoux/Cinder-Samples/tree/master/TextRendering |
Hello, the solution would be to create a different font for each text size: String s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
int smoothLevel = 8;
int[] sizes = { 10, 13, 20, 25, 30 };
PGraphics p2d, j2d;
PFont[] fonts;
void setup() {
size(600, 600, P2D);
p2d = createGraphics(width, height, P2D);
j2d = createGraphics(width, height, JAVA2D);
fonts = new PFont[sizes.length];
for (int i = 0; i < sizes.length; i++) {
fonts[i] = createFont("Arial", sizes[i], true);
}
p2d.beginDraw();
p2d.smooth(smoothLevel);
p2d.endDraw();
}
void draw() {
if (!mousePressed) {
drawText(p2d);
image(p2d, 0, 0);
frame.setTitle("P2D");
} else {
drawText(j2d);
image(j2d, 0, 0);
frame.setTitle("JAVA2D");
}
}
void drawText(PGraphics pg) {
pg.beginDraw();
pg.background(255);
for (int i=0; i<sizes.length; i++) {
int x = 10;
int y = 10+i*(pg.height-10)/sizes.length;
int w = pg.width-20;
int h = (pg.height-40)/sizes.length;
pg.fill(0, 25);
pg.noStroke();
pg.rect(x, y, w, h);
pg.textFont(fonts[i]);
pg.textSize(sizes[i]);
pg.fill(0);
pg.text(s, x, y, w, h);
}
pg.endDraw();
} Also, commit b064bb2 makes sure that text ascent, descent, and width are calculated in the same way as in JAVA2D. Something like Distance Fields should be implemented as a library. |
Nice, that works indeed. Thanks! |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
The text quality in the P2D renderer is very low at all smoothing levels. It's fuzzy, has varying letter width (thin to fat within a single font) and there are lots of additional pixel dots attached to the letters. At this quality level the text rendering of P2D is unusable in actual projects.
Code Example:
The text was updated successfully, but these errors were encountered: