putting a border around a GLViewport

Hi,

In my project I would like a border of 10 pixels to be around my GLJPanel.

Is there a way to set an option in OpenGL (or even just swing for that matter?) that would add a white border of 10 pixels around the outside of my entire GLViewport? or a way to set the coordinate system so that the farthest left point (top, bottom, right, etc…) are 10 pixels inside from the very edge of the GLJPanel.

I’d rather do it in OpenGL, since some things are going to be drawn right at the border, and it would be good if there is any overlap that they could still be displayed, but any ideas are more than welcome.

If you’re using a GLJPanel rather than a GLCanvas you can do this with straight Swing by installing a Border (javax.swing.border) in your GLJPanel. However you can also change the viewport in your reshape callback by doing something like


  gl.glViewport(x + 10, y + 10, w - 20, h - 20);

You will probably also need to use glScissor to set up a scissor region to prevent your border from being cleared once drawn. You can probably draw it by changing the clear color, clearing to the border color, setting up the scissor region and clearing the background to the real background color.

I’m trying to do the same thing as mentioned here… but while swing is able to put a border around my JPanel, and it draws itself correctly, my GLContext still seems to include the area used by the border. Is this intentional?

I think so. I don’t think a Border changes the component’s notion of how big it is.

In your reshape() implementation when setting up the viewport and scissors, take into account the component Insets.
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JComponent.html#getInsets()

that takes care of it; thanks!