We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Text not working with OpenGL
Page Index Toggle Pages: 1
Text not working with OpenGL (Read 1717 times)
Text not working with OpenGL
Oct 25th, 2006, 5:34am
 
When I try to show text in the overlay using the OpenGL renderer, it does not show up. When I use the P3D renderer it works fine.

Does anyone have any suggestions?

code would go something like this:

g.textMode(PConstants.SCREEN);

g.textFont(font);

g.text("some text", 20, 20);

Re: Text not working with OpenGL
Reply #1 - Oct 26th, 2006, 7:54pm
 
I filed a bug for this problem: http://dev.processing.org/bugs/show_bug.cgi?id=426
Re: Text not working with OpenGL
Reply #2 - Oct 26th, 2006, 8:27pm
 
If you remove the textMode(SCREEN); line it works fine. (at least in 0119)

If you want to emulate the SCREEN mode, you could clear the z-buffer, and reset the camera before doing the text:

Code:
import javax.media.opengl.*;

//...

((PGraphicsOpenGL)g).gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
camera();
perspective();

text(...);
Re: Text not working with OpenGL
Reply #3 - Oct 29th, 2006, 5:47am
 
Thanks for the advice.

Your method does make the text appear, but it also makes the 3D scene disappear. I'm trying to have text in the overlay with a 3D scene behind.

Is this possible, or do I need to stick to the P3D renderer?

Thanks.
Re: Text not working with OpenGL
Reply #4 - Oct 29th, 2006, 1:46pm
 
you might try calling camera() as suggested, but use hint(DISABLE_DEPTH_TEST) to turn off the z-ordering. not sure if that would work, but it may.
Re: Text not working with OpenGL
Reply #5 - Oct 29th, 2006, 3:17pm
 
I'm already using the DISABLE_DEPTH_TEST hint. Guess I'll just have to stick to P3D.
Re: Text not working with OpenGL
Reply #6 - Nov 7th, 2006, 12:02am
 
The only way I was able to get it to work, was to essentially position the text in world coordinates in such a way that after the projection they are in the correct position in screen coordinates.

This in combination with clearing the Z-Buffer allowed me to display my text over the 3D scene. This would be much more difficult if you are performing rotations.

I tried to get all this working by using the push and pop matrix stack modifiers, but I'm pretty certain text does not correctly use these functions as far as I can tell.

Since my game is just a half pipe simulator, you just linearly follow the snowboarder down the pipe, and I just needed to display some information in the top left of the screen, so I passed the current z position to the score manager.

My [horribly hacked up] code:

   ((PGraphicsOpenGL)g).gl.glClear(GL.GL_DEPTH_BUFFER_BIT);

   text("Score: " + m_currentScore, -350, -240, z - 2000);
   text("Coins Collected: " + m_coinsCollected, -350, -200, z - 2000);


Page Index Toggle Pages: 1