While loading the texture the following exception may occur: javax.media.opengl.GLException: java.lang.IndexOutOfBoundsException: Required 196608 remaining bytes in buffer, only had 0 at com.sun.gluegen.runtime.BufferFactory.rangeCheckBytes(BufferFactory.java:311) at com.sun.opengl.impl.gl2.GL2Impl.glTexImage2D(GL2Impl.java:18663) ... The following line cause the exception: gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, 3, img.getWidth(), img.getHeight(), 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, buffer); "buffer" is a ByteBuffer variable which holds data from a BufferedImage The whole code is attached Thanks
Created attachment 145 [details] Zip containing code that throws the exception and the Image file
Created attachment 146 [details] Exception Description
After minor test case fixes to allow it to run under JOGL2, plus adding trace and debug pipeline, the output is: +++ Info: XInitThreads() called for concurrent Thread support glGenTextures(<int> 0x1, <[I>, <int> 0x0) glBindTexture(<int> 0xDE1, <int> 0x1) glTexImage2D(<int> 0xDE1, <int> 0x0, <int> 0x3, <int> 0x100, <int> 0x100, <int> 0x0, <int> 0x1907, <int> 0x1401, <java.nio.Buffer> java.nio.DirectByteBuffer[pos=196608 lim=196608 cap=196608])Exception in thread "Timer-0" javax.media.opengl.GLException: java.lang.IndexOutOfBoundsException: Required 196608 remaining bytes in buffer, only had 0 +++ As you can see, we calculate the proper byte size of 196608, which is to be expected, but you buffer can't offer any - since it's position is at it's limit. A simple "buffer.rewind()" before passing it to the GL texture funtion solves your bug, so we can read all required bytes, Now the output is: +++ Info: XInitThreads() called for concurrent Thread support glGenTextures(<int> 0x1, <[I>, <int> 0x0) glBindTexture(<int> 0xDE1, <int> 0x1) glTexImage2D(<int> 0xDE1, <int> 0x0, <int> 0x3, <int> 0x100, <int> 0x100, <int> 0x0, <int> 0x1907, <int> 0x1401, <java.nio.Buffer> java.nio.DirectByteBuffer[pos=0 lim=196608 cap=196608]) glTexParameteri(<int> 0xDE1, <int> 0x2801, <int> 0x2601) glTexParameteri(<int> 0xDE1, <int> 0x2800, <int> 0x2600) glShadeModel(<int> 0x1D01) ... +++ And the cube is no more yellow :)