Nehe Lesson 6 with transparent images (DevIL question)

Started by baegsi, January 24, 2005, 13:25:36

Previous topic - Next topic

baegsi

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!

baegsi

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:

Matzon

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.

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)
        );

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
The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities.  We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)
8)

K.I.L.E.R

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.

baegsi