LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: baegsi on January 24, 2005, 13:25:36

Title: Nehe Lesson 6 with transparent images (DevIL question)
Post by: baegsi on January 24, 2005, 13:25:36
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!
Title: Nehe Lesson 6 with transparent images (DevIL question)
Post by: baegsi on January 24, 2005, 13:36:22
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:
Title: Nehe Lesson 6 with transparent images (DevIL question)
Post by: Matzon on January 24, 2005, 14:12:33
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.
Title: Nehe Lesson 6 with transparent images (DevIL question)
Post by: K.I.L.E.R on January 26, 2005, 11:43:28
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)
       );
Title: Nehe Lesson 6 with transparent images (DevIL question)
Post by: CaptainJester on January 26, 2005, 12:15:41
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
Title: Nehe Lesson 6 with transparent images (DevIL question)
Post by: K.I.L.E.R on January 26, 2005, 14:16:20
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.
Title: Nehe Lesson 6 with transparent images (DevIL question)
Post by: baegsi on January 26, 2005, 20:01:22
Thanks, that's a better solution of course  :)