TextRenderer Problem - Missing Letters in Render

classic Classic list List threaded Threaded
6 messages Options
Ben
Reply | Threaded
Open this post in threaded view
|

TextRenderer Problem - Missing Letters in Render

Ben
This post was updated on .
Hello and thanks in advance for your help.  I am trying to use the text render with glList so that my text is loaded once and then displayed as needed, where needed, etc.  I am using

private TextRenderer TR = new TextRenderer( new Font("SansSerif", Font.PLAIN, 36));

for the renderer.  The list creation function (the returned integer is the list index):
        public int glListText3D(GL2 gl, int id, String text, float[] pos, float scale, float[] color) {
                int txt = gl.glGenLists(id);
                gl.glNewList(txt,GL2.GL_COMPILE);
                gl.glNormal3d(0.0, 0.0, 1.0);
                TR.setColor(color[0],color[1],color[2],color[3]);
                TR.begin3DRendering();
                TR.draw3D(text, pos[0], pos[1], pos[2], scale);
                TR.end3DRendering();
                gl.glEndList();
                return txt;
        }

I keep a list of indexes (TextGL) by textual keyword so I can reference the ID as required.  The display() code for publishing the text:
                                                gl.glPushMatrix();
                                                                                               
                                                // rotation and translation for camera viewing
                                                gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); // rotation
                                                gl.glTranslatef(coordinate_calculate(crds[0]),coordinate_calculate(crds[1]) + (0.5f * size[1]),coordinate_calculate(crds[2]));
                                               
                                                // Scale and Color
                            gl.glScalef((float)ES.font_scale()*world_size(true),(float)ES.font_scale()*world_size(true),(float)ES.font_scale()*world_size(true));
                                        gl.glColor4f(fnt_clr[0],fnt_clr[1],fnt_clr[2],fnt_clr[3]); // TODO - this does nothing
                                                 
                                                // Text
                                                gl.glCallList(TextGL.get(labels.get(i)));
                                                gl.glPopMatrix();


The problem I am having is that the results are missing letters.  Specifically, E,L,N (and some others).

Another side problem - if I try and use gl.glColor4f() prior to the CallList I get no change in color.  Scale and translation work fine.

Sorry this isn't a full code post - the full code is 10,000+ lines and not public.

=====================UPDATE================
Here is a full code example of what is happening.  Any help would be appreciated.

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Rectangle;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Random;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.FPSAnimator;
import com.jogamp.opengl.util.awt.TextRenderer;

public class figureText extends GLCanvas implements GLEventListener {
        private static final long serialVersionUID = 1L;
        private TextRenderer TR = new TextRenderer( new Font("SansSerif", Font.PLAIN, 12));
        private FPSAnimator animator = null;
        private Hashtable<String,Integer> TextGL = new Hashtable<String,Integer>();
        private Random random = new Random();
        private String[] names = new String[]{"Robert Smith","John Jones","Lawrence Spiegal","Maria Xenoblobazama","This is a really really long name"};
        private float view_x = 0.0f, view_y = 0.0f, view_z = 1.0f, world_size = 150.0f;
        private boolean start = false;
       
        public static void main(String[] args) {
                JFrame window = new JFrame(); window.setBounds(new Rectangle(200,200,800,800));
                GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); caps.setDoubleBuffered(true); caps.setHardwareAccelerated(true);
                JPanel ogwpanel = new JPanel(new BorderLayout()); final figureText OGW = new figureText(caps); ogwpanel.add(OGW,BorderLayout.CENTER);
                window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.getContentPane().add(ogwpanel); window.setVisible(true);
        }
               
        public figureText(GLCapabilities caps) {
                super(caps); addGLEventListener(this);
                animator = new FPSAnimator(this,60); animator.start();
                setVisible(true);
        }
       
        private void setup_data(GL2 gl) {
                for(int i=0;i<names.length;i++) {
                        float[] crds = new float[]{random.nextFloat()*100.0f,random.nextFloat()*100.0f,random.nextFloat()*100.0f};
                        TextGL.put(names[i],glListText3D(gl,(i+1),names[i],crds,1.0f,new float[]{1.0f,1.0f,1.0f,1.0f}));
                }
        }
       
        @Override public void display(GLAutoDrawable drawable) {
                GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
                if(!start) { setup_data(gl); start = true; }
                gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity();
                float vn = 2.0f * world_size * view_z; gl.glOrtho(-vn,vn,-vn,vn,-vn*3.0f,vn*3.0f); // uses world_size without ES.world_size() to allow visual scaling
                gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(view_x, view_y, -56.0f); // position change
               
                gl.glClearColor(0.0f,0.0f,0.0f,1.0f);
            gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
           
           gl.glPushMatrix();
            Enumeration<String> keys = TextGL.keys(); while(keys.hasMoreElements()) {
            gl.glCallList(TextGL.get(keys.nextElement()));
            }
            gl.glPopMatrix();
            gl.glFlush();
        }

        @Override public void dispose(GLAutoDrawable drawable) { }

        @Override public void init(GLAutoDrawable drawable) {
            GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context

            // Setup the environment
            gl.glEnable(GL2.GL_DEPTH_TEST); // enables depth testing
            gl.glDepthFunc(GL2.GL_LEQUAL);  // the type of depth test to do
            gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST); // best perspective correction
            gl.glShadeModel(GL2.GL_SMOOTH); // blends colors nicely, and smoothes out lighting
               
            gl.glEnable(GL2.GL_COLOR_MATERIAL);
               
                gl.glEnable(GL2.GL_LIGHTING);
                gl.glEnable(GL2.GL_LIGHT0);
                gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, new float[]{0.0f,0.0f,0.0f,0.0f},0);
            gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, new float[]{ 1.0f, 1.0f, 1.0f, 1.0f }, 0);
            gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, new float[]{ 1.0f, 1.0f, 1.0f, 1.0f }, 0);

            gl.glClearColor(0.0f,0.0f,0.0f,1.0f);
            gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
        }

        @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
                // This allows things to remain centered and square irrelevant of the window size
                int size = width; if (height < size) { size = height; }
                int cX = 0, cY = 0;
                if(width < height) { cY = (height - width) / 2; }
                else if (height < width) { cX = (width - height) / 2; }
               
                GL2 gl = drawable.getGL().getGL2(); gl.glViewport(cX,cY,size,size);
        }

        public int glListText3D(GL2 gl, int id, String text, float[] pos, float scale, float[] color) {
                int txt = gl.glGenLists(id);
                gl.glNewList(txt,GL2.GL_COMPILE);
                gl.glNormal3d(0.0, 0.0, 1.0);
                TR.setColor(color[0],color[1],color[2],color[3]);
                TR.begin3DRendering();
                TR.draw3D(text, pos[0], pos[1], pos[2], scale);
                TR.end3DRendering();
                gl.glEndList();
                return txt;
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer Problem - Missing Letters in Render

Xerxes Rånby
Please publish a link to a "git" repository containing the full code

2016-10-10 1:59 GMT+02:00 Ben [via jogamp] <[hidden email]>:
Hello and thanks in advance for your help.  I am trying to use the text render with glList so that my text is loaded once and then displayed as needed, where needed, etc.  I am using

private TextRenderer TR = new TextRenderer( new Font("SansSerif", Font.PLAIN, 36));

for the renderer.  The list creation function (the returned integer is the list index):
        public int glListText3D(GL2 gl, int id, String text, float[] pos, float scale, float[] color) {
                int txt = gl.glGenLists(id);
                gl.glNewList(txt,GL2.GL_COMPILE);
                gl.glNormal3d(0.0, 0.0, 1.0);
                TR.setColor(color[0],color[1],color[2],color[3]);
                TR.begin3DRendering();
                TR.draw3D(text, pos[0], pos[1], pos[2], scale);
                TR.end3DRendering();
                gl.glEndList();
                return txt;
        }

I keep a list of indexes (TextGL) by textual keyword so I can reference the ID as required.  The display() code for publishing the text:
                                                gl.glPushMatrix();
                                                                                               
                                                // rotation and translation for camera viewing
                                                gl.glRotatef(view_rotx, 1.0f, 0.0f, 0.0f); gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f); // rotation
                                                gl.glTranslatef(coordinate_calculate(crds[0]),coordinate_calculate(crds[1]) + (0.5f * size[1]),coordinate_calculate(crds[2]));
                                               
                                                // Scale and Color
                            gl.glScalef((float)ES.font_scale()*world_size(true),(float)ES.font_scale()*world_size(true),(float)ES.font_scale()*world_size(true));
                                        gl.glColor4f(fnt_clr[0],fnt_clr[1],fnt_clr[2],fnt_clr[3]); // TODO - this does nothing
                                                 
                                                // Text
                                                gl.glCallList(TextGL.get(labels.get(i)));
                                                gl.glPopMatrix();


The problem I am having is that the results are missing letters.  Specifically, E,L,N (and some others).

Another side problem - if I try and use gl.glColor4f() prior to the CallList I get no change in color.  Scale and translation work fine.

Sorry this isn't a full code post - the full code is 10,000+ lines and not public.


If you reply to this email, your message will be added to the discussion below:
http://forum.jogamp.org/TextRenderer-Problem-Missing-Letters-in-Render-tp4037297.html
To start a new topic under jogl, email [hidden email]
To unsubscribe from jogamp, click here.
NAML

Ben
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer Problem - Missing Letters in Render

Ben
In reply to this post by Ben
Hey, not sure how to do the Git stuff.  The updated code I posted does the same problem for me.  I'm on an iMac retina 5k, 27-inch Intel Core i5 3.3Ghz with 32 gb ram , Radeon R9 M395x 4GB video
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer Problem - Missing Letters in Render

gouessej
Administrator
Why do you use display lists? They are badly supported in numerous drivers. In my humble opinion, start from a working example, add your changes into it step by step to find the culprit but I don't see the interest of display lists over static VBOs.
Julien Gouesse | Personal blog | Website
Ben
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer Problem - Missing Letters in Render

Ben
Hi and thanks for the advice.  I am using primitives only to display scientific data and by using the lists with the objects I reduce memory / cpu - and it is noticeable.  Unfortunately I do not work on gaming / games and so my knowledge of OpenGL / JOGL is hacker at best.

The code I provided above and your comment suggests the use of Lists is my problem so I will research VBO and see if I can implement it.  This used to work fine in the past with earlier versions of JOGL.  This problem resulted from my update to the latest JOGL.

Thanks

Ben
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer Problem - Missing Letters in Render

gouessej
Administrator
There were already some unfixed bugs in this text renderer and there has been no noticeable change in it between JOGL 1 and JOGL 2. I'm a bit sceptical. Please find the latest working version and the oldest non working version so that we have a chance to find the culprit.
Julien Gouesse | Personal blog | Website