LWJGL
May 17, 2012, 02:37:41 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL 2.8.3 released!
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: DevIL and ARBTextureRectangle.  (Read 4777 times)
Funkapotamus
Newbie
*
Posts: 25


« on: August 28, 2005, 20: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:
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);
}
Logged
Matzon
Administrator
Demigod
*****
Posts: 2177



« Reply #1 on: August 28, 2005, 22:59:43 »

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

http://certusgames.com (Free Online Multiplayer Java Games)
http://lwjgl.org (OpenGL/OpenAL for Java)
Funkapotamus
Newbie
*
Posts: 25


« Reply #2 on: August 29, 2005, 07:33:54 »

Nope, still does it.  

It works fine without the GL_TEXTURE_RECTANGLE_ARB :/
Logged
Funkapotamus
Newbie
*
Posts: 25


« Reply #3 on: August 29, 2005, 12: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.
Logged
Funkapotamus
Newbie
*
Posts: 25


« Reply #4 on: December 28, 2005, 19:42:08 »

Round Two, same error:

Code:

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:

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:

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);
Logged
Funkapotamus
Newbie
*
Posts: 25


« Reply #5 on: December 28, 2005, 19:51:32 »

Oh, I should note too, I've enabled everything properly and I'm running a Radeon 9800 Pro.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!