Hello Guest

DevIL and ARBTextureRectangle.

  • 5 Replies
  • 16622 Views
DevIL and ARBTextureRectangle.
« on: August 29, 2005, 03:20:34 »
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?

Code: [Select]
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);
}

*

Offline Matzon

  • *****
  • 2242
DevIL and ARBTextureRectangle.
« Reply #1 on: August 29, 2005, 05:59:43 »
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);

DevIL and ARBTextureRectangle.
« Reply #2 on: August 29, 2005, 14:33:54 »
Nope, still does it.  

It works fine without the GL_TEXTURE_RECTANGLE_ARB :/

DevIL and ARBTextureRectangle.
« Reply #3 on: August 29, 2005, 19:20:27 »
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.

DevIL and ARBTextureRectangle.
« Reply #4 on: December 29, 2005, 03:42:08 »
Round Two, same error:

Code: [Select]

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.

Code: [Select]

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)

Code: [Select]

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

DevIL and ARBTextureRectangle.
« Reply #5 on: December 29, 2005, 03:51:32 »
Oh, I should note too, I've enabled everything properly and I'm running a Radeon 9800 Pro.