We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to make an experimental level editor in Processing, and I want to display a level mini-map using points while playing the level. I can't get it to work, because the points appear in 3D space rather than 2D. How do I make them appear in 2D? I tried the old methods but none of them works (can't clear the zbuffer as it doesn't exist as a variable, etc.)
Answers
If you use peasycam, you have available HUD mode. Would that do the trick for you? Google the library and you will see the function calls.
Kf
Peasycam has beginhud endhud iirc
For an approach without peasy
Place the hud at the end of draw()
// start hud
camera ();
noLights();
textMode(.....);
text(......
@theliquu69 --
One method is to create an OpenGL P2D sketch and then draw two images() into the sketch surface -- a PGraphics(P3D) with your 3D sketch content, and a PGraphics(P2D or JAVA2D) with your HUD content.
Here is a simple example combining JAVA2D, P2D, and P3D graphics buffers into one sketch window composition:
Here the sphere layer (P3D) and color bar (P2D) are arranged next to each other; the HUD rect layer (JAVA2D) is partially transparent and overlays them both. Most of the sketch is defining the layer contents -- the actual layout is just a correct
size()
, a fewcreateGraphics()
calls, and then multipleimage()
calls indraw()
.If you try to draw 3D content into the main sketch window, on the other hand, this won't work. It works because this is a 2D layout with some of the elements containing 3D content.
For an example of drawing a HUD with the peasycam library's
beginHUD()
/endHUD()
-- as mentioned by @kfrajer and @Chrisir -- see:The example code looks like this:
Jeremy, your example is awesome! I simply was not aware that I can use different Renderers in different PGraphics-objects! Thank you very much! Jens
You are welcome! It is not necessarily clear, as the familiar
size()
command seems to imply that there is only one renderer for an entire sketch - but that is not true, it is only for the main sketch canvas. You can see documentation about choosing a per-PGraphics renderer on thecreateGraphics()
reference page:There is an easier way which allows you to use the P3D directly without having to create off-screen buffers.
Thanks, @quark. Interesting! Is there any documentation that could help explain what is happening here, e.g. with the call in setup? For example,
getGraphics()
isn't in the reference and the entry in the developer's API seems to be blank:AFAIK, it makes no diff. directly invoking hint() or via getGraphics().
B/c all PApplet methods related to canvas are already routed to variable g, which is the sketch's PGraphics.
Yes you can get rid of the
getGraphics().
and thePConstants.
from lines 23 & 28 because thehint()
method in the PApplet class will do this for you. ThegetGraphics()
method returns the PGraphics object used for rendering the sketch so can be used to access any methods not available to PApplet.Line 5 is not needed and should be deleted.
So the actual working sketch is
Got it.
Is there documentation for
hint()
somewhere in the javadocs? I've seen it mentioned many times for passing arguments to the renderer, but I wouldn't know where to point someone in teaching them how to use it -- all I have is lore.Edit
Never mind, I was looking in the wrong place. Extensive
PGraphics.hint()
docs here:From the docs: