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?