TextRenderer overlaped

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

TextRenderer overlaped

elseine
This post was updated on .
Hello!.

I am using TextRenderer to render a text in my world.

This is my code:



if(r)
            {
            tr = new TextRenderer(new java.awt.Font("Calibri", java.awt.Font.BOLD, 16), true, false, null, false);
            tr.setColor(1,1,0,1);
            r = false;
            }
            ///
            tr.beginRendering(viewportMatrix[2], viewportMatrix[3]);
            tr.draw( nombreRepresentacion, ((Double)result[0]).intValue(), ((Double)result[1]).intValue());
            tr.endRendering();

ViewportMatrix has the viewportl given by my GL2 object. result contains the position in world space. The problem is when I execute my program, my text is behind my rectangle like this image:



This rectangle is created with this code:

 public void draw(GL2 gl) {
        //gl.glDisable(GL.GL_LIGHTING);
      //if (color!=null) gl.glColor3f(color.getRed(),color.getGreen(),color.getBlue());
           // gl.glEnable(GL.GL_LINE_STIPPLE);
        //gl.glLineStipple(1, (short) 255);
        if (fill) gl.glBegin(GL2.GL_POLYGON); else
            gl.glBegin(GL2.GL_LINE_LOOP);
        gl.glVertex3d(p1.x, p1.y, p1.z);
        gl.glVertex3d(p2.x, p1.y, p1.z);
        gl.glVertex3d(p2.x, p2.y, p2.z);
        gl.glVertex3d(p1.x, p2.y, p1.z);
      gl.glEnd();
         //gl.glDisable(GL.GL_LINE_STIPPLE);
    }

And in my code, I put the coordinates and calls to rect.render();

public void render(GL2 gl){
        gl.glDisable(GL2.GL_LIGHTING);

      if (isSelected()){
                        JSelectionModel.selectedColor.setColor(gl);

                      }
      if (isMouseOver()){
          JSelectionModel.mouseOverColor.setColor(gl);
                  } else
       if (!isSelected() && getColor()!=null ) getColor().setColor(gl);
       
       
      setStriple(gl);
      gl.glLineWidth(getWidth());
     
      gl.glPushMatrix();
          if (haveTransformation()) getTransformation().ApplyTransformation(gl);
             if (isPack)
                 gl.glCallList (this.hashCode()); //si esta empaquetado
             else {
                 draw(gl);   //si no esta empaquetado
             }
     
      gl.glPopMatrix();
    }


How can I make that the letters are in front on my rectangle instead of behind?

Thanks for your time!

Art
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer overlaped

Art
I created a custom text renderer. However, my initialization logic may still apply. Generally you want to disable depth test when rendering things on top of, or very close to, other things. This also means that you will have to control the rendering order.  Here's my initialization logic before text rendering.


        // setup drawing environment
        gl.glPushAttrib(GL2.GL_ENABLE_BIT | GL2.GL_TEXTURE_BIT | GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL2.GL_TRANSFORM_BIT);
        gl.glDisable(GLLightingFunc.GL_LIGHTING);
        gl.glDisable(GLLightingFunc.GL_COLOR_MATERIAL);
        gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_EMISSION, Color.TRANSPARENT.toRgbArray(), 0);
        gl.glDisable(GL.GL_DEPTH_TEST);
        gl.glEnable(GL.GL_BLEND);
        gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_ALPHA);

and then cleanup after rendering:

        gl.glPopAttrib();