I can't get the lwjgl-ported Nehe Lesson 6 with alpha transparency running :oops: .
This is the original code
..
IL.ilCopyPixels(0, 0, 0, 256, 256, 1, IL.IL_RGB, IL.IL_BYTE, scratch);
...
// Generate The Texture
GL11.glTexImage2D(
GL11.GL_TEXTURE_2D,
0,
GL11.GL_RGB,
IL.ilGetInteger(IL.IL_IMAGE_WIDTH),
IL.ilGetInteger(IL.IL_IMAGE_HEIGHT),
0,
GL11.GL_RGB,
GL11.GL_UNSIGNED_BYTE,
scratch);
...
Now I just changed the format settings:
...
IL.ilCopyPixels(0, 0, 0, 256, 256, 1, IL.IL_RGBA/*<==*/, IL.IL_BYTE, scratch);
...
// Generate The Texture
GL11.glTexImage2D(
GL11.GL_TEXTURE_2D,
0,
GL11.GL_RGBA, /*<==*/
IL.ilGetInteger(IL.IL_IMAGE_WIDTH),
IL.ilGetInteger(IL.IL_IMAGE_HEIGHT),
0,
GL11.GL_RGBA, /*<==*/
GL11.GL_UNSIGNED_BYTE,
scratch);
...
and loaded the example with a png with transparency, but it crashes with an exception.
What do I wrong? Any help very appreciated!
Found the problem: "scratch" buffer too small. Instead of
QuoteByteBuffer scratch = ByteBuffer.allocateDirect(IL.ilGetInteger(IL.IL_IMAGE_WIDTH) * IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 3);
I used:
QuoteByteBuffer scratch = ByteBuffer.allocateDirect(IL.ilGetInteger(IL.IL_IMAGE_WIDTH) * IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 4 /*<==*/);
Hmh, I think I have to understand the whole xyBuffer stuff properly... :oops:
makes sense...
using RGB (no transparency) you use 3 Bytes per pixel (hence the 3) - adding the alpha channel (8 more bits, total 32) increases the size needed per pixel to 4 bytes.
Why not just use this?
ByteBuffer scratch = ByteBuffer.allocateDirect
(
IL.ilGetInteger(IL.IL_IMAGE_BITS_PER_PIXEL) *
IL.ilGetInteger(IL.IL_IMAGE_DEPTH) *
IL.ilGetInteger(IL.IL_IMAGE_WIDTH) *
IL.ilGetInteger(IL.IL_IMAGE_HEIGHT)
);
Quote from: "K.I.L.E.R"Why not just use this?
ByteBuffer scratch = ByteBuffer.allocateDirect
(
IL.ilGetInteger(IL.IL_IMAGE_BITS_PER_PIXEL) *
IL.ilGetInteger(IL.IL_IMAGE_DEPTH) *
IL.ilGetInteger(IL.IL_IMAGE_WIDTH) *
IL.ilGetInteger(IL.IL_IMAGE_HEIGHT)
);
You mean
IL_IMAGE_BYTES_PER_PIXEL
Quote from: "CaptainJester"Quote from: "K.I.L.E.R"Why not just use this?
ByteBuffer scratch = ByteBuffer.allocateDirect
(
IL.ilGetInteger(IL.IL_IMAGE_BITS_PER_PIXEL) *
IL.ilGetInteger(IL.IL_IMAGE_DEPTH) *
IL.ilGetInteger(IL.IL_IMAGE_WIDTH) *
IL.ilGetInteger(IL.IL_IMAGE_HEIGHT)
);
You mean IL_IMAGE_BYTES_PER_PIXEL
WHOOPS!
I'm an idiot. Sorry.
Thanks, that's a better solution of course :)