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 › 2D overlay over opengl
Page Index Toggle Pages: 1
2D overlay over opengl (Read 4871 times)
2D overlay over opengl
Jan 18th, 2008, 9:25am
 
i'd like to do a 2D overlay/gui/etc. type thing over some opengl.  i imagine this is real simple, i'm just kind of dense right now ...
first figured you could reset the camera to an ortho view and draw on top, but that didn't work so good; next tried to use a PGraphics to offscreen render the 3D and then copy to the main screen, but you can't do that; then tried various tomfoolery with frustum() but no dice.  

thanks for any suggestions
Re: 2D overlay over opengl
Reply #1 - Jan 18th, 2008, 10:43am
 
I use this and it works great :

Code:
// your 3D stuff

// reset camera and disable depth test and blending
camera();
javax.media.opengl.GL gl=((PGraphicsOpenGL)g).beginGL();
gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
gl.glDisable(javax.media.opengl.GL.GL_BLEND);
((PGraphicsOpenGL)g).endGL();

// your 2D/gui stuff
Re: 2D overlay over opengl
Reply #2 - Jan 18th, 2008, 11:55am
 
This is also very easy:

void draw() {

 unhint(DISABLE_DEPTH_TEST);
 // 3D OpenGL stuff

 hint(DISABLE_DEPTH_TEST);
 // 2D OpenGL UI

}

with hint(DISABLE_DEPTH_TEST); you just switch off the z-sorting
Re: 2D overlay over opengl
Reply #3 - Mar 13th, 2009, 5:19am
 
just wanted to chime in and say thanks for this...turned out to be the solution to a similar problem i was having trying to draw 2d in opengl. I was running loadPixels(); doing stuff w/ pixels array, then updatePixels(), then trying to draw on top. It wasn't working, whatever ran after updatePixels wasn't showing up on screen. Now with this it does.

thanks!


ascorbin wrote on Jan 18th, 2008, 11:55am:
This is also very easy:

void draw() {

 unhint(DISABLE_DEPTH_TEST);
 // 3D OpenGL stuff

 hint(DISABLE_DEPTH_TEST);
 // 2D OpenGL UI

}

with hint(DISABLE_DEPTH_TEST); you just switch off the z-sorting

Re: 2D overlay over opengl
Reply #4 - Apr 28th, 2009, 2:34am
 
Wow. Reset the camera. Duh.

Thanks, I was also wondering how to do this. The simplest solutions are always the best!
Re: 2D overlay over opengl
Reply #5 - Aug 14th, 2009, 10:54pm
 
Hi!
Does this only work for OpenGL?
(In reference to the 'Very Easy' code, of course)

I had a large project I was working on and I've left it for a while because of this hurdle, so I'll have to go over all my code again to remind myself of what I was doing but...
I can get it all to work (using PeasyCam) but the overlay only happens while I'm rotating the scene with the mouse. Once the 3d camera stops moving the 3d scene jumps to (what I assume is) a 0,0,0 style orientation with my 3d stuff up in the top left corner. Very strange. Everything works fine while my 3d camera is in motion.

Any ideas?
Re: 2D overlay over opengl
Reply #6 - Aug 17th, 2009, 12:20pm
 
Sounds like you're setting the camera position every time the mouse moves.  If you have camera settings in your draw() loop, they'll overwrite the previous settings.  That might be PeasyCam's fault; I don't know what it's doing.  Try storing the camera settings as global variables and using them to set camera() in the draw() loop.  (And using the mouse position to change the variables rather than set the camera position directly.)
Page Index Toggle Pages: 1