Loading...
Logo
Processing Forum
Hey all, quick question (i hope)

I have a sketch that uses P3D to render a 3D cube which can be rotated an translated. I also have a small menu with two buttons. The buttons are drawn with rect(). Now, this all goes well, untill the cube is becoming to close to the menu, than it overlaps the menu. To be more clear, here's an image:


As you can see, the cube is now over the button. For text I have the option to set textmode(SCREEN) which will render text flat on top of anything else.This is why button 2 is in front of the cube Basically I'd like the same behavior for rect. Also, at a later stage I want to double the width of the sketch and the right part should sho a 2D slice of the 3D cube. Again, I don't want the cube to overlap the slice in any case.

Replies(7)

I think you should use two buffers. P3D/OPENGL PApplet for the display, and P2D or JAVA2D PGraphics for the GUI. Probably you will have the same problems later, so you´ll have to disable depth test before drawing the GUI (and enable it again when rendering 3d shapes). I have to say, though, enabling+disabling the depth test is quite expensive sometimes.
From hint reference ( http://processing.org/reference/hint_.html):
"hint(DISABLE_DEPTH_TEST) - Disable the zbuffer, allowing you to draw on top of everything at will. When depth testing is disabled, items will be drawn to the screen sequentially, like a painting. This hint is most often used to draw in 3D, then draw in 2D on top of it (for instance, to draw GUI controls in 2D on top of a 3D interface). Starting in release 0149, this will also clear the depth buffer. Restore the default with hint(ENABLE_DEPTH_TEST), but note that with the depth buffer cleared, any 3D drawing that happens later in draw() will ignore existing shapes on the screen."

Ale · 60rpm.tv/i
This does exactly what I want (for now). Thank you very much!
You could try using PGraphics http://processing.org/reference/PGraphics.html

or

Do your GUI in the primary sketch and create a class like this one

class My3dStuff extends PApplet implements PConstants
{
   public void setup()
   {
      // your code
   }
   public void draw()
   {
      // your code
   }
}

and add it to your sketch like this

  // Creating class
  sketch = new My3dStuff(this, mywidth, myheight);                                     
  sketch.init();
  sketch.setBounds(20, 30, sketch.width, sketch.height);
 
  // Adding 3D stuff to the current sketch
  this.setLayout(null);
  this.add(sketch); //this adds the embedded sketch to the main sketch
That might be even better. I will definitely check that out as well, probably later this weekend. Thanks!
Hi Handlewithcare, did you ever get this sorted out, and would you share your code/solution? I have the same problem. I want to draw a 2D CP5 interface to one side of a window displaying my rotatable 3D OpenGL object. My controls get drawn in 3D space and are rotated with the model.

Thanks in advance.
There are many ways to do this. As suggested you could use different PGraphics. Or if you want everything in the main sketch you could use something like below ( tip 9).
Copy code
  1.   // in setup()
  2.   cp5.setAutoDraw(false);

  3.   // at the end of draw()
  4.   camera();
  5.   cp5.draw();
In the end I stayed with the solution Ale_ provided. I would look into PGraphics though, look promising.