glReadPixels, glDrawPixels / Overlay crash

Good morning :slight_smile:

I try to create a zoom function that magnifies the content of the screensection where the mouse is being dragged over and draws it in a corner.

Since I am fairly new in the Jogl world, I tried to do sth basic. I get the content with

			gl.glReadPixels(0, 0, this.width, this.height, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, buffer );

(where width/height are the current width and height of the canvas) and buffer is the ByteBuffer).

Then I draw the buffer content with

			gl.glWindowPos2i(0,0);
			gl.glPixelZoom(0.25f, 0.25f);
			gl.glDrawPixels(this.width, this.height, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, buffer);

Okay, no problem until now and I have got a small screen which shows me the content of the canvas 1:1.

But here is my problem: The GLCanvas is embedded on a JFrame with a Menu/Toolbar.
The toolbar is dragable. When I place it over the Canvas I get a

 java.lang.IndexOutOfBoundsException

So from what I have read, glReadPixels can only be called on a Canvas that is in the front.

What different approach can I use to reach the same result?

Take care
randy

If you are using Swing you should really use GLJPanel.

Hi zingbat,

thank you for your input. I tried it with GLJPanel aswell, but it still gives me that Exception :โ€™(
The reason I was using GLCanvas in the first place was because it gave me 10+fps more than a GLJPanel.

Could you please explain to me why a GLJPanel is better in my Swing Application?

Check this thread. Maybe it helps.
http://java.sun.com/products/jfc/tsc/articles/mixing/

What is throwing the exception?

What is the full stack-trace? JOGL would not be throwing an exception of that type if itโ€™s because of glReadPixels. Then itโ€™d be a GLException, or the JVM would crash.

Itโ€™s more likely the case that your code that drags the menu, or sets up your frames is the cause.

Check the variable values on drag or post the trace bcuz as lhkbob said its mostly a problem in the code not regarding OpenGL calls