Re: Text without AWT?
Posted by adi on Mar 02, 2017; 4:56pm
URL: https://forum.jogamp.org/Text-without-AWT-tp4037684p4037722.html
Hi Ranby
I use Shader (#version 450 core), Scenegraph and my own mathe library
so i can my scene change between a 3D and 2D environment with a simple key.
The TextRegionUtil doesn't work. (see nothing)
(The com.jogamp.opengl.util.awt.TextRenderer works correct)
What i want is using 'distance field fonts' with a shader, that relies not on 'libgdx environment'.
(I use the libgdx Hiero Bitmap converter to get distance field fonts)
I see, is must write my own *.fnt Reader class and a Textobject that can work without
fixed pipeline.
Here are a little code snipped from my Textrender class that doesn't work with TextRegionUtil :
......
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.Serializable;
import com.jogamp.graph.curve.Region;
import com.jogamp.graph.curve.opengl.RegionRenderer;
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.curve.opengl.TextRegionUtil;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;
import com.jogamp.graph.geom.SVertex;
import com.jogamp.opengl.GL4;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.util.PMVMatrix;
import com.lib.jengine.scene.animation.Positioner;
import com.lib.jengine.scene.animation.Transformer;
import com.lib.jengine.system.GlobalHelper;
public class TextRender3D implements Serializable
{
private static final long serialVersionUID = 863154778010270389L;
private Font font = null;
private float fontSize = 10.0f;
private volatile float weight = 1.0f;
private RenderState renderState = null;
private float red = 1.0f;
private float green = 0.0f;
private float blue = 0.0f;
private float alpha = 1.0f;
private int[] sampleCount = new int[] { 4 };
private int renderQuality = RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED;
private RegionRenderer regionRenderer = null;
private TextRegionUtil textRegionUtil = null;
private int renderModes = Region.VARWEIGHT_RENDERING_BIT;
// for own movings
private int transformers[] = null;
// for positioning
private Positioner pos = new Positioner();
public TextRender3D( String name ) throws Exception
{
renderState = RenderState.createRenderState(SVertex.factory());
renderState.setColorStatic( red, green, blue, alpha);
renderState.setHintMask( renderQuality );
regionRenderer = RegionRenderer.create(renderState, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable);
textRegionUtil = new TextRegionUtil(renderModes);
InputStream stream = new FileInputStream( GlobalHelper.getInstance().getFontPath()+"/"+name );
font = FontFactory.get ( stream, true ) ;
}
public void init(GLAutoDrawable glDrawable)
{
final GL4 gl = glDrawable.getGL().getGL4();
regionRenderer.init(gl, renderModes);
regionRenderer.enable(gl, false);
}
public void display(GLAutoDrawable glDrawable)
{
final GL4 gl = glDrawable.getGL().getGL4();
action( gl );
if( weight != regionRenderer.getRenderState().getWeight() )
regionRenderer.getRenderState().setWeight(weight);
// That can be a problem in my environment
final PMVMatrix Pmv = regionRenderer.getMatrix();
Pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
Pmv.glLoadIdentity();
Pmv.glTranslatef( (float)pos.tX, (float)pos.tY, (float)pos.tZ);
//Pmv.glRotatef((float)Math.PI, 0, 1, 0);
regionRenderer.enable(gl, true);
textRegionUtil.drawString3D(gl, regionRenderer, font, fontSize, "Hello", null, sampleCount);
regionRenderer.enable(gl, false);
}
public void dispose(GLAutoDrawable glDrawable)
{
final GL4 gl = glDrawable.getGL().getGL4();
renderState.destroy(gl);
}
...........................