Resize canvas


My current project requires me to put an jmecanvas into a swing frame.

I have been able to do that but i have a problem during resize.

I understand that during resizecanvas, the renderer and the camera reinits and creates

a new camera of the correct size. But what happens is that the objects in the scene will lose their

aspect ratios. I mean, for example a square quad will look like a rectangle.

I wonder if anyone have such problems or if anyone have a suggestion on how to solve the problem.

Basically I wish to resize the window while maintaining the "correct look"…


In openGL there is a resize() callback, however I don't think jME exposes it.  What I would do is in my 'main' update method I would check to see if the display width and height matched a saved variable, if not:

        cam.setFrustumPerspective( 45.0f, (float) DisplaySystem.getDisplaySystem().getRenderer().getWidth()
        / (float) DisplaySystem.getDisplaySystem().getRenderer().getHeight(), 1, 1000 );

This is actually just taken from the method cameraPerspective() in BaseGame, so you may be able to call that also; which would probably be the recommended way.

(Actually now that I look at it, I think there is a possible error here; there should be a check for improper division.  If the height is greater than the width it should be Height/Width, also there is the slim possibility of a divide by zero error.)

Thanks basixs  :slight_smile: for your fast reply and solution.

It worked pretty well in my case, no problems were posed when the height is greater than the width so i presume i didnt have to change it to height/width… I did limit the minimum size of the window, so i shdnt have problems with a divide-by-zero error.

Once again thanks a lot. i can continue on …  :slight_smile:

no problemo :slight_smile:

That's exactly how RenParticleEditor does it. :slight_smile:

Also, divide by zero is not an issue as long as resizeCanvas is first called because it ensures width and height are at least 1.

That's exactly how RenParticleEditor does it.

Sweet, I actually gave correct advice :D

As for the Height/Width or Width/Height, I remember ALWAYS doing this check for resizing a pure OpenGL application.  Is it not required??