DevIL and ARBTextureRectangle.

Started by Funkapotamus, August 29, 2005, 03:20:34

Previous topic - Next topic

Funkapotamus

So I've got your typical DevIL texture loader straight from the wiki, but with one modification.  I've got it set to use GL_TEXTURE_RECTANGLE_ARB instead of GL_TEXTURE_2D.

This works fine if I only load one texture.  If I load multiple ones, each texture is set to the last one loaded.  I've tried enableing/disabling GL_TEXTURE_RECTANGLE_ARB in between each texture loading- but this is just a random attempt to fix the issue since I have no clue why it does it.

Any guesses on how to make things work?

public Texture loadTexture(String ref){
ByteBuffer imageData = null;
int ilImageHandle;
int oglImageHandle;
IntBuffer scratch = BufferUtils.createIntBuffer(1);

IL.ilGenImages(scratch);
IL.ilBindImage(scratch.get(0));
ilImageHandle = scratch.get(0);

IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);

int width = IL.ilGetInteger(IL.IL_IMAGE_WIDTH);
int height = IL.ilGetInteger(IL.IL_IMAGE_HEIGHT);          
imageData = IL.ilGetData();

GL11.glGenTextures(scratch);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, scratch.get(0));
oglImageHandle = scratch.get(0);  

GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexImage2D(ARBTextureRectangle.GL_TEXTURE_RECTANGLE_ARB, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, imageData);

scratch.put(0, ilImageHandle);
IL.ilDeleteImages(scratch);

return new Texture(scratch.get(0), width, height);
}

Matzon

return new Texture(scratch.get(0), width, height);
you keep returning a Texture with a DevIL handle instead of the oglImageHandle :)
try:
return new Texture(oglImageHandle, width, height);

Funkapotamus

Nope, still does it.  

It works fine without the GL_TEXTURE_RECTANGLE_ARB :/

Funkapotamus

I suppose it's not a huge deal.  I've got things working with the default 0.0f-1.0f coordinates.  

But it sure makes things a hell of a lot easier to use pixels for texture coordinates.

Funkapotamus

Round Two, same error:

public static Texture loadTexture(String ref){
IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
IL.ilGenImages(image);
IL.ilBindImage(image.get(0));
IL.ilLoadImage(ref);

IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);
ByteBuffer scratch = ByteBuffer.allocateDirect(IL.ilGetInteger(IL.IL_IMAGE_WIDTH) * IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 4);
IL.ilCopyPixels(0, 0, 0, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 1, IL.IL_RGBA, IL.IL_BYTE, scratch);

IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
GL11.glGenTextures(buf);

GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));

GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);      

// Generate Texture
GL11.glTexImage2D(ARBTextureRectangle.GL_TEXTURE_RECTANGLE_ARB, 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);

return new Texture(buf.get(0), IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL.ilGetInteger(IL.IL_IMAGE_HEIGHT));
}


Lets say I load two textures in this fashion.  If I draw the texture, it will always draw the file which was loaded last.

Texture green = loadTexture("green.png");
Texture blue= loadTexture("blue.png");

draw(green);  // If I draw "green", then "blue" shows up!


Things work fine if things are set to use GL_TEXTURE_2D instead of the rectangle.  Ex)

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

Funkapotamus

Oh, I should note too, I've enabled everything properly and I'm running a Radeon 9800 Pro.