DevIL invert the textures

Started by Vifani83, March 14, 2005, 16:50:46

Previous topic - Next topic

Vifani83

Hi guys,

I am some trouble with DevIL library. When I load a texture with the following code I have an invert texture on X axis.

This is the code I use to load:

IL.create();
IL.ilInit();
IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
IL.ilGenImages(1, image);
IL.ilBindImage(image.get(0));
IL.ilLoadImage(JConfig.imageDir+fileName);
IL.ilConvertImage(IL.IL_RGB, IL.IL_BYTE);
format=GL11.GL_RGB;
data = IL.ilGetData();
height=IL.ilGetInteger(IL.IL_IMAGE_HEIGHT);
width=IL.ilGetInteger(IL.IL_IMAGE_WIDTH);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D,0,texTool.getFormat(),texTool.getWidth(),texTool.getHeight(),0,texTool.getFormat(),GL11.GL_UNSIGNED_BYTE,texTool.getData());


If I look the code to load a texture  using AWT I have seen the following instructions:
AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
tx.translate(0, -tmpImg.getHeight(null));
final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
tmpImg = op.filter(tmpImg, null);


So, why I need to flip the image also with DevIL library? I have read the Chman tutorial and he doesn't flip the texture with DevIL library.

tomb

The opengl coordinate system is up side down. You can fix that with the following code. It makes (0, 0) be the upper left corner instead of lower left. Then you don't have to flip your textures. I think :?:
// setup ortho mode.
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, width, height, 0);
GL11.glMatrixMode(GL11.GL_MODELVIEW);

CaptainJester

Quote from: "Vifani83"Hi guys,

I am some trouble with DevIL library. When I load a texture with the following code I have an invert texture on X axis.

This is the code I use to load:


If I look the code to load a texture  using AWT I have seen the following instructions:

So, why I need to flip the image also with DevIL library? I have read the Chman tutorial and he doesn't flip the texture with DevIL library.
It depends on the image type you are using.  Some images store the image backwards, some store it forwards.  DevIL just gets the data, it does not convert it for you automatically.

I haven't spent time yet to try and figure out an easy way to flip it with DevIL, so I don't know how.  I just make sure I use and image type that store the image data in a forward order.  PNG does this.
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)

jam007

I use ILU in 0.95

Quote
if (!IL.ilLoadImage(filename)) {
          System.out.println("File not found "+filename);
          throw new TextureNotFoundException(filename);
}
ILU.iluFlipImage();

BUT
I have problems with some image formats.
.jpg works perfectly
.gif  crashes the VM with an ati-driver error
.png and .tif turns into some strange striped version of the original.

Anders