ByteBuffer Question

I’m trying create a texture in OGL that i can use to render on the fly too.


 int textureID = createTextureID();
 ByteBuffer imageBuffer = ByteBuffer.allocateDirect( sizeX * sizeY * channelsTrue );
    imageBuffer.order( ByteOrder.nativeOrder() );
    byte[] data = new byte[ sizeX * sizeX * channelsTrue ];
    imageBuffer.put( data, 0, data.length);
    imageBuffer.flip();

    // Create the texture and store it on the video card
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, channels, sizeX, sizeY, 0, type,    GL11.GL_UNSIGNED_INT, imageBuffer);

I am wondering if I am doing it corectally as whenever I try to execute this code I get a JVM crash.

Any help would be apreciated.

You’re passing a ByteBuffer telling OpenGL it is in the GL_UNSIGNED_INT format, so it tries to load 4 bytes where you supply only 1 per pixel.

So switch to GL_UNSIGNED_BYTE and it should work

…and that is why you don’t code at 4AM in the morning.

i tend to do that, and then find myself scratching my head the next day too… :wink:

Depends where on earth he is.
I mean, in germany it was just 21:55 :wink: