Better text resolution on texture
[sixth-3d.git] / src / main / java / eu / svjatoslav / sixth / e3d / renderer / raster / shapes / composite / ForwardOrientedTextBlock.java
1 /*
2  * Sixth 3D engine. Author: Svjatoslav Agejenko. 
3  * This project is released under Creative Commons Zero (CC0) license.
4  */
5 package eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite;
6
7 import eu.svjatoslav.sixth.e3d.geometry.Point3D;
8 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.basic.ForwardOrientedTexture;
9 import eu.svjatoslav.sixth.e3d.renderer.raster.shapes.composite.textcanvas.TextCanvas;
10 import eu.svjatoslav.sixth.e3d.renderer.raster.texture.Texture;
11
12 public class ForwardOrientedTextBlock extends ForwardOrientedTexture {
13
14     public ForwardOrientedTextBlock(final Point3D point, final double scale,
15                                     final int maxUpscaleFactor, final String text,
16                                     final eu.svjatoslav.sixth.e3d.renderer.raster.Color textColor) {
17         super(point, scale, getTexture(text, maxUpscaleFactor, textColor));
18
19     }
20
21     public static Texture getTexture(final String text,
22                                      final int maxUpscaleFactor,
23                                      final eu.svjatoslav.sixth.e3d.renderer.raster.Color textColor) {
24
25         final Texture texture = new Texture(text.length()
26                 * TextCanvas.FONT_CHAR_WIDTH_TEXTURE_PIXELS, TextCanvas.FONT_CHAR_HEIGHT_TEXTURE_PIXELS,
27                 maxUpscaleFactor);
28
29         // texture.graphics.setColor(Color.BLUE);
30         // texture.graphics.fillRect(0, 0, texture.primaryBitmap.width,
31         // texture.primaryBitmap.width);
32
33         texture.graphics.setFont(TextCanvas.FONT);
34         texture.graphics.setColor(textColor.toAwtColor());
35
36         for (int c = 0; c < text.length(); c++)
37             texture.graphics.drawChars(new char[]{text.charAt(c),}, 0, 1,
38                     (c * TextCanvas.FONT_CHAR_WIDTH_TEXTURE_PIXELS),
39                     (int) (TextCanvas.FONT_CHAR_HEIGHT_TEXTURE_PIXELS / 1.45));
40
41         return texture;
42     }
43 }