Windows xp, lwjgl 0.98
I've created some icons for use with my app; they're standard windows ".ico" icons as far as i can tell, one is 16x16 and the other is 32x32, both with 32 bit depth.
I'm calling setIcon() after create() though it doesn't work before it either - I get zero as return value. I must be doing something wrong, but I can't figure it out and I've tried a lot of things. The loading code, which is almost the same as my texture loading code, is this:
ByteBuffer[] getIcons() throws FileNotFoundException, IOException{
ByteBuffer[] icons = new ByteBuffer[2];
IntBuffer image = BufferUtils.createIntBuffer(1);
IL.ilGenImages(image);
IL.ilBindImage(image.get(0));
InputStream is1 = Kernel.vfs.load("gui/icons/display16.ico");
// load the texture into DevIL
IL.ilLoadFromStream(is1, IL.IL_ICO);
is1.close(); // dont forget to free the handle
IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);
// create a scratch buffer to hold the image data
icons[0] = BufferUtils.createByteBuffer(IL.ilGetInteger(IL.IL_IMAGE_WIDTH) * IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 4);
// copy the image data into our scratch buffer
IL.ilCopyPixels(0, 0, 0, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 1, IL.IL_RGBA, IL.IL_BYTE, icons[0]);
IL.ilDeleteImages(image);
IntBuffer image2 = BufferUtils.createIntBuffer(1);
IL.ilGenImages(image2);
IL.ilBindImage(image2.get(0));
InputStream is2 = Kernel.vfs.load("gui/icons/display32.ico");
// load the texture into DevIL
IL.ilLoadFromStream(is2, IL.IL_ICO);
is2.close(); // dont forget to free the handle
IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);
// create a scratch buffer to hold the image data
icons[1] = BufferUtils.createByteBuffer(IL.ilGetInteger(IL.IL_IMAGE_WIDTH) * IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 4);
// copy the image data into our scratch buffer
IL.ilCopyPixels(0, 0, 0, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 1, IL.IL_RGBA, IL.IL_BYTE, icons[1]);
IL.ilDeleteImages(image2);
return icons;
}
Someone please tell me that I'm overlooking something trivially obvious ^_^. Am I supposed to use a different image format, or is the conversion call wrong?
Edit: I wasn't sure if I should stick this to DevIL forums instead, please move it if it's misplaced.
Make sure that "icons[0].remaining()" returns 1024 (16*16*4) and "icons[1].remaining()" returns 4096 (32*32*4). If it do not, you might need to rewind the buffers, or make sure the icons is read correctly be IL.
edit: 16x16 icons should be 1024 bytes and nothing else. Using the windows calculator sucks by the way. Always some number that is not registered :x
Well, they turned out to return 4. After rewinding, too :S
I tried out the code with png files instead and it worked. In retrospect I should have done that to begin with, though it's still annoying as to why it won't work with icons. Tho the numbers returned are 1024, and rewinding has no effect, but at least Display swallows them. Might be a problem with windows icon files inherent to DevIL or the bindings?
Anyway, thanks for your help.