2D overlay for Canvas3D - window resize problem
I have overridden the Canvas3D class to add capability to draw in 2D. I'm using a J3DGraphics2D object. I draw to a buffer and finally do a drawAndFlushImage to draw 2D graphics over a Canvas3D. (I'm placing the 2D entities relative to the bounds of the J3DGraphics2D.)
Works fine until I manually resize the host JFrame. The 3D part draws as expected in the resized window, but the 2D stuff is drawn stretched (if the window was expanded). I am using theView.setWindowResizePolicy(View.VIRTUAL_WORLD) which seems to affect only the 3D part.
Grasping at straws I drew a rectangle (not part of the scene) to the Graphics2D object (not the buffer) obtained from the overridden Canvas3d; THEN the 2D stuff is drawn as expected (not stretched or compressed) BUT it is drawn in its original location (relative to the original Bounds of the J3DGraphics2D object). The Bounds of the J3DGraphics2D are unchanged despite the fact that the JFrame holding the overridden Canvas3D was resized.
So, there are two issues.
1. How to get the 2D entities to draw without distortion after a resize (without drawing the unwanted rectangle to the J3DGraphics2D object).
2. How to obtain a new J3DGraphics2D object that reflects the new size of the window. (A new J3DGraphics2D obtained after the resize still has the old size.)
And a general question...at what point is a View object available? (Not when the constructor for the overridden class runs, but only apparently after something has actually been rendered.) I ask because it is the View object that has the setWindowResizePolicy method that I use. It seems that I can't set the policy before the first render. This can't be so.