grabScreenContents throws IndexOutOfBoundsException

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

grabScreenContents throws IndexOutOfBoundsException

runiter
When I called renderer.grabScreenContents() in Ardor3D with canvas size of 800 X 600 it works great. But for random sizes such as 926 X 487 it throws the following exception:

java.lang.IndexOutOfBoundsException: Required 1353858 remaining bytes in buffer, only had 1352886
   at com.jogamp.common.nio.Buffers.rangeCheckBytes(Buffers.java:980)
   at jogamp.opengl.gl4.GL4bcImpl.glReadPixels(GL4bcImpl.java:22356)
   at com.ardor3d.renderer.jogl.JoglRenderer.grabScreenContents(JoglRenderer.java:284)


After reading about it in JOGL forum I realized the buffer size needed is not as simple as width*height*pixel_bytes. So I simply increased the size of buffer by some arbitrary number.
But now the resulting image is stretched and is in black & white.

What's the proper way of doing this?
Saeid Nourian, Ph.D. Eng. | Graphing Calculator 3D
Reply | Threaded
Open this post in threaded view
|

Re: grabScreenContents throws IndexOutOfBoundsException

runiter
I remembered gouessej told me a while ago that the size passed to glReadPixels needs to be even.
However I noticed it's not enough that the size be even. It should be multiple of 4. Is this documented somewhere in OpenGL spec?
Saeid Nourian, Ph.D. Eng. | Graphing Calculator 3D
Reply | Threaded
Open this post in threaded view
|

Re: grabScreenContents throws IndexOutOfBoundsException

gouessej
Administrator
Try a multiple of a power of 2. Yes I already talked to you about that but I didn't remember when.
Julien Gouesse | Personal blog | Website