Text without AWT?

classic Classic list List threaded Threaded
28 messages Options
12
adi
Reply | Threaded
Open this post in threaded view
|

Text without AWT?

adi
Hello

I use jogl version 2.3.2 (opengl 4.5).
Is there something to draw text without the AWT Textrenderer?
I have not found one or some class/es in the graph library.
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

gouessej
Administrator
Hi

You should have looked at our API documentation:
http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/graph/curve/opengl/TextRegionUtil.html

There are some examples in jogl-demos and in our unit tests.

You can modify Xerxes' example to draw some text:
http://forum.jogamp.org/How-to-Draw-a-Smooth-Curve-through-a-Set-of-2D-Points-tp4037677p4037685.html
Julien Gouesse | Personal blog | Website
adi
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

adi
This post was updated on .
Thanks,
i use shader with
#version 450 core
no fixed pipeline.
Does this also work?
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

Xerxes Rånby
adi wrote
Thanks,
i use shader with
#version 450 core
no fixed pipeline.
Does this also work?
It will work.
The Graph API TextRegionUtil only work on modern OpenGL/ES systems with a programmable pipeline like your system.
OpenGL 2 / OpenGL ES 2 and above, desktop and mobile, is supported.
adi
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

adi
Is this a separate Renderer?
Or is this an Overlay over a running Renderer?
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

Xerxes Rånby
This post was updated on .
I have implemented a single class that demo the Graph API for text rendering without using AWT.

you can checkout this code using git and test it:
git clone https://github.com/xranby/jogamp-forum-examples
cd jogamp-forum-examples/xranby
sh fetch-jogamp-build-and-run.sh


https://twitter.com/xranby/status/836946773637738497

package com.gudinna;

import com.jogamp.graph.curve.Region;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;

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.geom.SVertex;

import com.jogamp.newt.opengl.GLWindow;

import com.jogamp.opengl.*;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.PMVMatrix;

import java.io.IOException;

/**
 * <pre>
 *   __ __|_  ___________________________________________________________________________  ___|__ __
 *  //    /\                                           _                                  /\    \\
 * //____/  \__     __ _____ _____ _____ _____ _____  | |     __ _____ _____ __        __/  \____\\
 *  \    \  / /  __|  |     |   __|  _  |     |  _  | | |  __|  |     |   __|  |      /\ \  /    /
 *   \____\/_/  |  |  |  |  |  |  |     | | | |   __| | | |  |  |  |  |  |  |  |__   "  \_\/____/
 *  /\    \     |_____|_____|_____|__|__|_|_|_|__|    | | |_____|_____|_____|_____|  _  /    /\
 * /  \____\                       http://jogamp.org  |_|                              /____/  \
 * \  /   "' _________________________________________________________________________ `"   \  /
 *  \/____.                                                                             .____\/
 * </pre>
 *
 * <p>
 * JogAmp JOGL OpenGL ES 2 graph text demo to expose and learn how to use the graph API to draw text.
 *
 * Inside the main JOGL source tree we have the "Graph" API that is what we consider
 * the *best* way to render text using nurbs on all GPU's.
 * Graph is using a patent free shaders implementation.
 * Graph is suitable for both desktop and mobile GPU processors.
 *
 * NOTE: This demo is using jogamp.graph.font.fonts.ubuntu is found inside jogl-fonts-p0.jar
 * you may need to add this jar to your classpath
 * http://jogamp.org/deployment/jogamp-current/jar/atomic/jogl-fonts-p0.jar
 *
 * In a nutshell the JogAmp Graph API enable you to define nurbs shapes
 * Outline → OutlineShapes → GLRegion
 * and then render the shapes using a Renderer
 * RegionRenderer
 * TextRegionUtil (same as RegionRender with Helper methods for texts and fonts.)
 *
 * To load a Font you need to implement your own FontSet
 * The JogAmp JOGL source tree contains two FontSet's
 * One for loading Ubuntu true type fonts bundled with JogAmp
 * One for loading "Java" true type fonts bundled with the JRE
 * http://jogamp.org/git/?p=jogl.git;a=blob;f=src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java;hb=HEAD
 * http://jogamp.org/git/?p=jogl.git;a=blob;f=src/jogl/classes/jogamp/graph/font/JavaFontLoader.java;hb=HEAD
 * The FontFactory class can be used to load a default JogAmp FontSet Font.
 *
 * The graph API is using the math by Rami Santina introduced in 2011
 * https://jogamp.org/doc/gpunurbs2011/p70-santina.pdf
 * https://jogamp.org/doc/gpunurbs2011/graphicon2011-slides.pdf
 *
 * The best documentation for the graph API is found in the JOGL junit tests
 * http://jogamp.org/git/?p=jogl.git;a=tree;f=src/test/com/jogamp/opengl/test/junit/graph;hb=HEAD
 *
 * and javadoc for Outline and OutlineShape .. and all classes i mentioned above..
 * https://www.jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/graph/geom/Outline.html
 * https://www.jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/graph/curve/OutlineShape.html
 * </p>
 *
 * @author Xerxes Rånby (xranby)
 */

public class JogAmpGraphAPITextDemo {

    static Animator animator;

    public static void main(String[] args) {

        // Enable JOGL debugging of GLSL shader compilation and GL calls
        //System.setProperty( "jogl.debug.GLSLCode", "");
        //System.setProperty( "jogl.debug.DebugGL", "");

        GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2ES2));
        caps.setAlphaBits(4);
        GLWindow glWindow = GLWindow.create(caps);
        glWindow.setSize(800,400);
        glWindow.setTitle("JogAmp JOGL Graph API text demo");
        glWindow.setVisible(true);

        glWindow.addGLEventListener(new GraphText() /* GLEventListener */);

        animator = new Animator();
        animator.add(glWindow);
        animator.start();
    }

    private static class GraphText implements GLEventListener{

        TextRegionUtil textRegionUtil;
        RenderState renderState;
        RegionRenderer regionRenderer;

        Font font;
        static int fontSet = FontFactory.UBUNTU;
        static int fontFamily = 0; // default
        static int fontStyleBits = 0; // default

        volatile float weight = 1.0f;
        volatile double lastTime = com.jogamp.common.os.Platform.currentTimeMicros();

        final float fontSize = 10.0f;

        final float zNear = 0.1f, zFar = 7000f;

        /* 2nd pass texture size antialias SampleCount
           4 is usually enough */
        private final int[] sampleCount = new int[] { 4 };

        /* variables used to update the PMVMatrix before rendering */
        private float xTranslate = -40f;
        private float yTranslate =  0f;
        private float zTranslate = -100f;
        private float angleRotate = 0f;

        private final int renderModes = Region.VARWEIGHT_RENDERING_BIT;

        double fpsHuman;

        @Override
        public void init(GLAutoDrawable drawable) {

            final GL2ES2 gl = drawable.getGL().getGL2ES2();

            /* SwapInterval 1 makes the demo run at 60 fps
            use SwapInterval 0 here to get ... hundreds ... sometimes thousands of fps!
            SwapInterval 0 can cause stuttering due to thermal throttling of your GPU */
            gl.setSwapInterval(1);

            gl.glEnable(GL.GL_DEPTH_TEST);
            gl.glEnable(GL.GL_BLEND);
            gl.glClearColor(1.0f, 0.0f, 1.0f, 1.0f);

            /* load a ttf font */
            try {
                /* JogAmp FontFactory will load a true type font
                 *
                 * fontSet == 0 loads
                 * jogamp.graph.font.fonts.ubuntu found inside jogl-fonts-p0.jar
                 * http://jogamp.org/deployment/jogamp-current/jar/atomic/jogl-fonts-p0.jar
                 *
                 * fontSet == 1 tries loads LucidaBrightRegular from the JRE.
                 */

                font = FontFactory.get(fontSet).get(fontFamily, fontStyleBits);
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }


            /* initialize OpenGL specific classes that know how to render the graph API shapes */
            renderState = RenderState.createRenderState(SVertex.factory());
            // define a RED colour to render our shape with
            renderState.setColorStatic(1.0f, 0.0f, 0.0f, 1.0f);
            renderState.setHintMask(RenderState.BITHINT_GLOBAL_DEPTH_TEST_ENABLED);

            regionRenderer = RegionRenderer.create(renderState, /* GLCallback */ RegionRenderer.defaultBlendEnable, /* GLCallback */ RegionRenderer.defaultBlendDisable);

            textRegionUtil = new TextRegionUtil(renderModes);

            regionRenderer.init(gl, renderModes);
            regionRenderer.enable(gl, false);
        }

        @Override
        public void dispose(GLAutoDrawable drawable) {
            final GL2ES2 gl = drawable.getGL().getGL2ES2();
            //stop the animator thread when user close the window
            animator.stop();
            // it is important to free memory allocated no the GPU!
            // this memory cant be garbage collected by the JVM
            renderState.destroy(gl);
        }

        @Override
        public void display(GLAutoDrawable drawable) {
            final GL2ES2 gl = drawable.getGL().getGL2ES2();

            // use JogAmp high resolution timer for smooth animations!
            double time = com.jogamp.common.os.Platform.currentTimeMicros();
            double fps = Math.floor(1000000f/(time-lastTime));
            lastTime = time;

            // fps updates too fast for humans to read... sample an fps at some frames.
            if(time%100==0) {
                fpsHuman = fps;
            }

            float sinusAnimationRotate = (float) (Math.sin(time/1000000f));

            String text = "JogAmp GRAPH API Text demo\nFPS: "+fps+"\nFPS human readable: "+fpsHuman;

            // clear screen
            gl.glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
            gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

            float offsetX = -30;
            float offsetY = 30;

            // When rendering text we need to account for newlines inside the text.
            final int newLineCount = TextRegionUtil.getCharCount(text, '\n');

            final float lineHeight = font.getLineHeight(fontSize);
            offsetX += font.getAdvanceWidth('X', fontSize);
            offsetY -= lineHeight * newLineCount;

            // the RegionRenderer PMVMatrix define where we want to render our shape
            final PMVMatrix Pmv = regionRenderer.getMatrix();
            Pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
            Pmv.glLoadIdentity();
            Pmv.glTranslatef(xTranslate+offsetX, yTranslate+offsetY, zTranslate);
            Pmv.glRotatef(angleRotate+ 10f * sinusAnimationRotate, 0, 0, 1);

            if( weight != regionRenderer.getRenderState().getWeight() ) {
                regionRenderer.getRenderState().setWeight(weight);
            }

            // Draw the  shape using RegionRenderer and TextRegionUtil
            regionRenderer.enable(gl, true);
            textRegionUtil.drawString3D(gl, regionRenderer, font, fontSize, text, null, sampleCount);
            regionRenderer.enable(gl, false);
        }

        @Override
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
            final PMVMatrix Pmv = regionRenderer.getMatrix();
            regionRenderer.reshapePerspective(45.0f, width, height, zNear, zFar);
            Pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
            Pmv.glLoadIdentity();
        }
    }
}
adi
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

adi
Thanks

I have seen it. But there are only two fonts therein, JAVA and UBUNTU.
And why is 'weight' used with volatile? Other
Threads working in the background?
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

Xerxes Rånby
This post was updated on .
adi wrote
I have seen it. But there are only two fonts therein, JAVA and UBUNTU.
To load a custom Font you simply need to know where you have your true type .ttf files stored, in a jar or on disk, and then implement your own FontSet.
Indeed the JogAmp JOGL source tree contains only two FontSet's however you can look at the source code to load your own font!
 * http://jogamp.org/git/?p=jogl.git;a=blob;f=src/jogl/classes/jogamp/graph/font/UbuntuFontLoader.java;hb=HEAD
 * http://jogamp.org/git/?p=jogl.git;a=blob;f=src/jogl/classes/jogamp/graph/font/JavaFontLoader.java;hb=HEAD

You may also use FontFactory.get to load a Font from a InputStream that supports random-access.
Font f= FontFactory.get ( stream /*InputStream*/, true /* close stream */) ;
or use FontFactory to load a Font from a File
Font f= FontFactory.get ( file /*File*/) ;

Example on my Linux system I can use:
font = FontFactory.get(new File("/usr/share/fonts/truetype/freefont/FreeMono.ttf"));



adi wrote
And why is 'weight' used with volatile?
In the original junit demo  weight was changed at runtime from keyboard input that is running on a differnt thread compared to rendering.
It is volatile as a leftover from the junit test demo code when i flattened it into only one class.

adi
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

adi
This post was updated on .
Thanks für your Hints.
I will test the TextRegionUtil than as a separate 3D Object
in a scenegraph in my own opengl 4.5 Renderer, so i need no
old fixed pipeline commands for positioning.

The TextRegionUtil class ist only für 3D and not for 2D designed?
What does is the variable 'sampleCount' do?

I have loaded an own ttf font,
but with maven dependencies for Ubunto font there are problems to load with maven:
I use this:
<dependency>
 <groupId>org.jogamp.jogl</groupId>
 <artifactId>jogl-all-main</artifactId>
 <version>2.3.2</version>
</dependency>

an got the error:
File not found in maven Repo org\jogamp\jogl\jogl-all\2.3.2\atomic\jogl-fonts-p0.jar


 
 
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

Xerxes Rånby
This post was updated on .
adi wrote
Thanks für your Hints.
I will test the TextRegionUtil than as a separate 3D Object
in a scenegraph in my own opengl 4.5 Renderer, so i need no
old fixed pipeline commands for positioning.
Neat, do you have a project homepage for your scenegraph?

adi wrote
The TextRegionUtil class ist only für 3D and not for 2D designed?
All JogAmp JOGL API follow Mathematics and is using Cartesian coordinate systems.
We think 2D designs should use Cartesian coordinate systems as well hence no need to have a special 2D version of the API with a what we think is crazy "inverted TV scan-line" coordinate system.
Programmer friendly 2D API's should use:
• 2D regular Cartesian grid
• Origin (0, 0) at the lower left (OpenGL convention)
• Pixels are defined at intersections

adi wrote
What does is the variable 'sampleCount' do?
If you read the paper
https://jogamp.org/doc/gpunurbs2011/p70-santina.pdf
5.  ANTI-ALIASING
In what follows,  we will present a View Based Anti Alias-
ing (VBAA) technique for dealing with skinny small shapes,
such as tiny text and condensed P&ID cad drawings.  This
step is optional since a one pass rendering will provide good
results,  but to get a crisp overall image an additional ren-
dering pass is required.
sampleCount is used for this additional rendering pass to produce the VBAA technique.

adi wrote
I have loaded an own ttf font,
but with maven dependencies for Ubunto font there are problems to load with maven:
I use this:
<dependency>
 <groupId>org.jogamp.jogl</groupId>
 <artifactId>jogl-all-main</artifactId>
 <version>2.3.2</version>
</dependency>

an got the error:
File not found in maven Repo org\jogamp\jogl\jogl-all\2.3.2\atomic\jogl-fonts-p0.jar
jogl-fonts-p0.jar is part of jogl test package containing the junit tests
unfortunately I do not know what maven dependency and artiactId you need to add to have the test packages added. I hope someone with more maven expertise can help you locate the right depencency and artifactId to include this jar containing the fonts. At least it is correct that it is not intended to be included the the jogl-all-main since jogl-fonts-p0.jar is part of the junit tests.
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

jmaasing
In reply to this post by adi
adi wrote
Thanks für your Hints.
I will test the TextRegionUtil than as a separate 3D Object
in a scenegraph in my own opengl 4.5 Renderer, so i need no
old fixed pipeline commands for positioning.

The TextRegionUtil class ist only für 3D and not for 2D designed?
What does is the variable 'sampleCount' do?

I have loaded an own ttf font,
but with maven dependencies for Ubunto font there are problems to load with maven:
I use this:
<dependency>
 <groupId>org.jogamp.jogl</groupId>
 <artifactId>jogl-all-main</artifactId>
 <version>2.3.2</version>
</dependency>

an got the error:
File not found in maven Repo org\jogamp\jogl\jogl-all\2.3.2\atomic\jogl-fonts-p0.jar
Your POM file is broken but we can't help you fix it because you don't show it to us.

These are the dependecies from jogl-all-main

[INFO] +- org.jogamp.jogl:jogl-all-main:jar:2.3.2:compile
[INFO] |  +- org.jogamp.jogl:jogl-all:jar:2.3.2:compile
[INFO] |  +- org.jogamp.jogl:jogl-all:jar:natives-android-aarch64:2.3.2:compile
[INFO] |  +- org.jogamp.jogl:jogl-all:jar:natives-android-armv6:2.3.2:compile
[INFO] |  +- org.jogamp.jogl:jogl-all:jar:natives-linux-amd64:2.3.2:compile
[INFO] |  +- org.jogamp.jogl:jogl-all:jar:natives-linux-armv6:2.3.2:compile
[INFO] |  +- org.jogamp.jogl:jogl-all:jar:natives-linux-armv6hf:2.3.2:compile
[INFO] |  +- org.jogamp.jogl:jogl-all:jar:natives-linux-i586:2.3.2:compile
[INFO] |  +- org.jogamp.jogl:jogl-all:jar:natives-macosx-universal:2.3.2:compile
[INFO] |  +- org.jogamp.jogl:jogl-all:jar:natives-solaris-amd64:2.3.2:compile
[INFO] |  +- org.jogamp.jogl:jogl-all:jar:natives-solaris-i586:2.3.2:compile
[INFO] |  +- org.jogamp.jogl:jogl-all:jar:natives-windows-amd64:2.3.2:compile
[INFO] |  \- org.jogamp.jogl:jogl-all:jar:natives-windows-i586:2.3.2:compile
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

Xerxes Rånby
In reply to this post by adi
adi wrote
but with maven dependencies for Ubunto font there are problems to load with maven:
I use this:
<dependency>
 <groupId>org.jogamp.jogl</groupId>
 <artifactId>jogl-all-main</artifactId>
 <version>2.3.2</version>
</dependency>

an got the error:
File not found in maven Repo org\jogamp\jogl\jogl-all\2.3.2\atomic\jogl-fonts-p0.jar

If you use gradle then you can add one extra compile line to build.gradle in order to only fetch the fonts-p0.jar that is part of org.jogamp.org jogl 2.3.2
https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.jogamp.jogl%22

Thus the solution if using gradle to download and build a working example using the maven artifacts can be seen here:
https://raw.githubusercontent.com/xranby/jogamp-forum-examples/master/build.gradle

I am sure something similar can be added to a maven pom.

and be used like this:
git clone https://github.com/xranby/jogamp-forum-examples/
cd jogamp-forum-examples
./gradlew run
adi
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

adi
In reply to this post by jmaasing
Hi
My pom works good.There is nothing broken.
I load

<dependencies>
                <dependency>
                        <groupId>org.jogamp.gluegen</groupId>
                        <artifactId>gluegen-rt-main</artifactId>
                        <version>2.3.2</version>
                </dependency>
        <dependency>
                        <groupId>org.jogamp.jogl</groupId>
                        <artifactId>jogl-all-main</artifactId>
                        <version>2.3.2</version>
                </dependency>
                <dependency>
                        <groupId>org.jogamp.jogl</groupId>
                        <artifactId>nativewindow-main</artifactId>
                        <version>2.3.2</version>
                </dependency>
                <dependency>
  <groupId>org.jogamp.joal</groupId>
  <artifactId>joal-main</artifactId>
  <version>2.3.2</version>
                </dependency>
 </dependencies>

But i have seen that the dependency path 'atomic' ist not
in the repository, so that jogl-fonts-p0.jar can't be loaded.
The rest is ok.


   
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

Xerxes Rånby
This post was updated on .
fonts-p0.jar is only included by the artifactId named jogl
 <artifactId>jogl</artifactId>

You can check which artifactId's contain fonts-p0.jar for yourself by
looking at the maven search page here:
https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.jogamp.jogl%22

i recommend you to still use
<artifactId>jogl-all-main</artifactId>
because that is the best artifactId to use to get jogamp runtime
however if you can tell maven to also cherry pick fonts-p0.jar from the
artifactId named jogl then that would be the best and would allow the code will find the fonts at runtime.

I consider it a bug that jogl-fonts-p0.jar have been renamed fonts-p0.jar when the jogamp-scripting maven build script uploaded the jar to the maven central. Not having the correct name jogl-fonts-p0.jar  at maven central will cause a warning at runtime before jogamp locate the font as a fallback inside the fonts-p0.jar on the classpath. The warning will not stop the application from working.
However if you include fonts-p0.jar despite the incorrect jar name your application will find the fonts!
adi
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

adi
In reply to this post by Xerxes Rånby
Hi Ranby

is use this dependencies:

<dependency>
        <groupId>org.jogamp.gluegen</groupId>
        <artifactId>gluegen-rt-main</artifactId>
        <version>2.3.2</version>
</dependency>
<dependency>
        <groupId>org.jogamp.jogl</groupId>
        <artifactId>jogl-all-main</artifactId>
        <version>2.3.2</version>
        </dependency>
<dependency>
       <groupId>org.jogamp.jogl</groupId>
        <artifactId>nativewindow-main</artifactId>
        <version>2.3.2</version>
</dependency>
<dependency>
        <groupId>org.jogamp.joal</groupId>
        <artifactId>joal-main</artifactId>
        <version>2.3.2</version>
</dependency>

adi
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

adi
In reply to this post by Xerxes Rånby
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);
     }
...........................
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

Xerxes Rånby
I need a complete compilable example most preferable a git source tree in ordet to understand why the integration between the TextRegionUtil class and your code do mix well. Since OpenGL is a statemachine require me to look and test the complete code on order to help locate the issue.

Den 2 mar 2017 17:56 skrev "adi [via jogamp]" <[hidden email]>:
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);
     }
...........................



If you reply to this email, your message will be added to the discussion below:
http://forum.jogamp.org/Text-without-AWT-tp4037684p4037722.html
To start a new topic under jogl, email [hidden email]
To unsubscribe from jogamp, click here.
NAML
adi
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

adi
The code is embedded in a complete and complex 3D scenegraph library,
an very good testet. I think mixing fixed and programmable pipeline is not a good design.
Here ist a screenshot from that. Runs with my library. But no text


 
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

Xerxes Rånby
If you want an expert to work with your closedsource codebase then contact us directly. We can help!
http://jogamp.org/wiki/index.php/Maintainer_and_Contacts#Contact_Maintainer

Cheers
Xerxes and the JogAmp team.

torsdag 2 mars 2017 skrev adi [via jogamp] <[hidden email]>:
The code is embedded in a complet and complex 3D scenegraph library,
an very good testet. I think mixing fixed and programmable pipeline is not a good design.
Here ist a screenshot from that runs with my library.  


 


If you reply to this email, your message will be added to the discussion below:
http://forum.jogamp.org/Text-without-AWT-tp4037684p4037724.html
To start a new topic under jogl, email <a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;ml-node%2Bs762907n782158h61@n3.nabble.com&#39;);" target="_blank">ml-node+s762907n782158h61@n3.nabble.com
To unsubscribe from jogamp, click here.
NAML
adi
Reply | Threaded
Open this post in threaded view
|

Re: Text without AWT?

adi
Hi Ranby

No, my sources are not a closedsource codebase, but
to big and complex to describing i a single message.
I think in the moment i can't found somewhere who can
help me with that.
I think i will write code that can read in
'distance field fonts' an than can display the text with
shaders without using old fixed pipeline code.
 
     
12