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 & HelpPrograms › mixing text and open gl
Page Index Toggle Pages: 1
mixing text and open gl (Read 335 times)
mixing text and open gl
Oct 5th, 2008, 12:23pm
 
hi all,

i am trying to mix normal processsing text rendering and open GL.

the problem i have is that i only works when i call the background() function right before rendering the text like here :


 //some opengl stuff (masked by the background() function
 ...
 ...

 background(0);
 fill(255);
 text("whaoo",WIDTH/2,HEIGHT/2);

 //some more opengl stuff (visible)
 ...
 ...

i am not against the use of the this function, but it has the side effect of masking all the previous opengl rendering i previously did for that frame :s

and if i don't call this background() function the text simply don't get drawn on screen.

any ideas ?

ideally i would like to be able to render the text in opengl by drawing it into a texture or something but could not get it to work. example of text rendering + opengl are then more than welcome ! Smiley

cheers

henri
Re: mixing text and open gl
Reply #1 - Oct 5th, 2008, 12:31pm
 
I'm guessing it might be a z-buffer issue.. your text is actually placed into the world in 3D, and so if it's behind other objects, you'll not be bale to see it.

One solution is to clear the z-buffer before drawing the text, but then your GL stuff after the text will not interact with any earlier 3D stuff.. so it's best to draw the text last.

You can clear the z-buffer in LG mode with:

Code:
import javax.media.opengl.*;
//add the above to the top.

//...
GL gl=((PGraphicsOpenGL)g).beginGL();
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
((PGraphicsOpenGL)g).endGL();
text(....);
Page Index Toggle Pages: 1