Results 1 to 2 of 2

Thread: Need help with Java OpenGL TextRenderer

  1. #1
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    Need help with Java OpenGL TextRenderer

    Hi all, how do I get the Java OpenGL TextRenderer to respect the depth buffer?

    I want my text drawn with depth (z) = 0 but to respect the depth function GL_LESS. That means it should not overwrite pixels already drawn with depth = 0 and not be overwritten by pixels drawn later with depth = 0.

    To be more specific, I am experimenting with OpenGL and was trying to build a basic GUI component (textbox/label) for my application. I have reached the point where I can do a box using gl.glBegin(GL_LINE_LOOP), fill in the background using gl.glBegin(GL_QUADS), and want to use a TextRenderer to render text. However, if I let it disable the depth test using textRenderer.Draw(...) the control's text draws on top of everthing, even if the box is hidden by something. If I allow depth testing it appears that the text is being drawn with a z value of -0.5 which is behind the control's background and other images. Neither of these results are desireable.

    I also tried using TextRenderer.Draw3D(x, y, z = 0...) and it seems to draw properly, but I get artifacts around the letters, like the letters are on a rectangle with a black background. If I could even get that background transparent that would help. That looks like something to do with drawing textures, but I barely understand textures and I can't see how to specify texture coordinates and bindings for the text from the TextRenderer.

    The code is below

    Code :
        /** Displays the control.
         * @param gl Reference to the OpenGL context.
         */
        public void Display(GL gl) {
     
            /* If control's border should be shown... */
            if (options.IsSet(OPTION_VISIBLE_BORDER)) {
     
                /* Set drawing colour for control's border. */
                gl.glColor4fv(currentBorderColour, 0);
     
                /* Draw control's borders. */
                gl.glBegin(GL.GL_LINE_LOOP);
                    gl.glVertex3d(left, bottom, 0);
                    gl.glVertex3d(right, bottom, 0);
                    gl.glVertex3d(right, top, 0);
                    gl.glVertex3d(left, top, 0);
                gl.glEnd();
     
            }
     
            /* If control's text should be shown... */
            if (options.IsSet(OPTION_VISIBLE_TEXT) && (null != textRenderer) && (null != text) && !text.equals("")) {
     
                /* Prepare text renderer to display text. */
                textRenderer.beginRendering(app.windowWidth, app.windowHeight);
     
                /* Set drawing colour for control's text. */
                textRenderer.setColor(currentTextColour[0], currentTextColour[1], currentTextColour[2], currentTextColour[3]);
     
                /* Draw control's text. */
                textRenderer.draw(text, (int)(left + margin), (int)(bottom + margin + textOffset));
     
                /* Complete text rendering. */
                textRenderer.endRendering();
     
            }
     
            /* If control's background should be shown... */
            if (options.IsSet(OPTION_VISIBLE_BACKGROUND)) {
     
                /* Set drawing colour for control's background. */
                gl.glColor4fv(currentBackgroundColour, 0);
     
                /* Draw control's background. */
                gl.glBegin(GL.GL_QUADS);
                    gl.glVertex3d(left, bottom, 0);
                    gl.glVertex3d(right, bottom, 0);
                    gl.glVertex3d(right, top, 0);
                    gl.glVertex3d(left, top, 0);
                gl.glEnd();
     
            }
     
            /* (TODO) complete drawing code. */
     
        }

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Need help with Java OpenGL TextRenderer

    Simple, draw text last, after everything has been drawn.
    Same problem as transluscent quads with blending, depth buffer only store nearest distance, so you can not "render behind".

Similar Threads

  1. opengl jogl problem with TextRenderer
    By thomasdk in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-03-2011, 05:54 AM
  2. OpenGL in Java
    By James Gilham in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-19-2002, 11:11 PM
  3. OpenGL for Java
    By imported_Mahesh in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-08-2002, 07:56 PM
  4. Java and OpenGL
    By Tone in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-04-2001, 08:47 PM
  5. Java and OpenGL
    By outlander78 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-03-2001, 09:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean