LWJGL Forum

Archive => DevIL => Topic started by: sir_wojciech on January 12, 2006, 18:10:48

Title: DevIL texture quality issue?
Post by: sir_wojciech on January 12, 2006, 18:10:48
I have the same problem (at least I think so) as 1 thread on this forum, but still after reading it I couldn't solve the problem.
This is the texture viewed in lets say Paint Shop Pro:
(http://img191.imageshack.us/img191/1810/tex19sj.jpg)
And this is the same texture but viewed in my application:
(http://img65.imageshack.us/img65/3207/tex22kp.jpg)
As you see there's a mayor difference.
My loading code:

package game;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import org.lwjgl.devil.IL;
import org.lwjgl.devil.ILU;
import org.lwjgl.opengl.GL11;


public class TextureLoader
{
   public static int load(String path)
   {
       int pixelFormat = 0;
       IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
       IL.ilGenImages(image);
       IL.ilBindImage(image.get(0));
       IL.ilLoadImage(path);
       IL.ilConvertImage(IL.ilGetInteger(IL.IL_IMAGE_FORMAT), 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.ilGetInteger(IL.IL_IMAGE_FORMAT), 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);
       if(IL.ilGetInteger(IL.IL_IMAGE_FORMAT) == IL.IL_RGB)
           pixelFormat = GL11.GL_RGB;
       else if(IL.ilGetInteger(IL.IL_IMAGE_FORMAT) == IL.IL_RGBA)
           pixelFormat = GL11.GL_RGBA;
       GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, pixelFormat, IL.ilGetInteger(IL.IL_IMAGE_WIDTH),
               IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 0, pixelFormat, GL11.GL_UNSIGNED_BYTE, scratch);
       return buf.get(0);
   }
}

Any solution?

Thanks in advance!
Title: hmmmmmm...
Post by: Fool Running on January 12, 2006, 20:32:22
That looks like 16 bit color.
What are you passing into the PixelFormat constructor that you are giving to the Display.create() method?
Its also possible that your video card automatically compreses(sp) the texture in OpenGL and turns it into 16 bit color format because of this.

EDIT: Its also possible (if you are running in a window) that your current desktop bpp is set to 16 bit and Paint Shop Pro dithers the image. If you need to use 16bpp try turning dithering "on" in OpenGL. That should help a little.  :P
Title: DevIL texture quality issue?
Post by: sir_wojciech on January 12, 2006, 21:32:56
Nah, it's almost 100% that my app is set to 32 bpp (and desktop :D). Don't know actually about the Graphics Card changing anything, though all games opengl and nonopengl work properly.

My PixelFormat looks like:

new PixelFormat(8, 24, 0, samples);


BTW. How can you set dithering in OpenGL?

Thanks anyways :)
Title: DevIL texture quality issue?
Post by: sir_wojciech on January 12, 2006, 21:36:47
If you set dithering with
GL11.glEnable(GL11.GL_DITHER);
than it doesn't work (change).
Title: hmmmmm...
Post by: Fool Running on January 13, 2006, 15:59:21
QuoteIf you set dithering with
Code:
GL11.glEnable(GL11.GL_DITHER);

than it doesn't work (change).
That's what I meant. Too bad it doesn't work. :?
I'm almost positive that what you are seeing is the result of 16bit color (or some other loss of color data)...

What about the image file? Is it possible that you are losing color data in your image format (i.e. By using JPEG images or something)?
Although I've never seen JPEG mess with an image that badly :lol:

EDIT: Someone else can chime in here  :D
Title: DevIL texture quality issue?
Post by: tomb on January 14, 2006, 12:39:27
It's defenetly because the texture or display is 16 bit.

Go to your Display Properties and make sure that the texture preferences is set to high quality in OpenGL.
Title: DevIL texture quality issue?
Post by: sir_wojciech on January 22, 2006, 10:04:04
Ok. I made some tests and it came out that the problem was caused by the ATI Catalyst drivers (had 5.13). When I updated them to the newest 6.1 version everything looked and worked fine.