LWJGL/Slick: Strange color state when loading/rendering textures

Started by
1 comment, last by larsbutler 11 years, 5 months ago
Hey guys,

I'm new to OpenGL and I've been playing with LWJGL, and now Slick (since it provides some utilities for loading textures).

I was experiencing a very strange issue in my project, and I was able to reproduce it by slightly modifying the sample code from here:
http://lwjgl.org/wiki/index.php?title=Slick-Util_Library_-_Part_1_-_Loading_Images_for_LWJGL

Here's the code which produces the error:
http://pastie.org/5179268

The important changes are:

  • line 81 (to specify a 16x16 solid red png)
  • lines 113-193 (to draw a 100x100 white rectangle)

Here's the really strange thing.

  • If I disable the texture loading (init()), skip drawing the texture, and go straight to drawing the white rectangle, I get what I expect: A white rectangle in the upper left corner. This is what it looks like: http://i.imgur.com/t4D8n.png
    (Modified code here, which the texture loading/drawing disabled: http://pastie.org/5179294.)
  • If I keep the texture loading/drawing, and then try to draw the same white rectangle, it draws a red rectangle instead.
    So with this code http://pastie.org/5179268, I get this: http://i.imgur.com/bU5pp.png
  • If I repeat step 2 with a 16x16 solid blue png, I get same result, except everything is blue instead of red.

Sample images:
blue - http://i.imgur.com/VjgR1.png
red - http://i.imgur.com/7DVqj.png

Anyone know why this is happening? It seems like some global state is being tainted, but I have no idea how to reset, clean, or avoid it. I've been banging my head against this for days, so any ideas would be greatly appreciated.

Thanks!
Advertisement
it does sound like a BGRA issue,
did you provide GL_BGRA when loading the texture?
i don't see any texture loading directly to OpenGL in the code, so i guess that's taken care of by 'slick' with TextureLoader

if you disable texture loading, you will get a "default" texture which has the color 1.0, 1.0, 1.0, 1.0 (full white, full alpha)

anyways, it seems like there's a problem with Slick-util, considering you are using tutorial code
unless there is a different color encoding scheme with your PNGs... who knows =)

you could try to load the textures yourself, and see what works and what doesn't

it does sound like a BGRA issue,
did you provide GL_BGRA when loading the texture?
i don't see any texture loading directly to OpenGL in the code, so i guess that's taken care of by 'slick' with TextureLoader


Sorry, I'm not quite following you on this one. Can you please elaborate on what you mean by "BGRA issue"? To which texture API functions are you referring? glTexEnv? glTexParameter? glTexImage? (Again, I'm new to OpenGL.)

About the texture loading, you're right; Slick is handling that, because I'd rather not write that part myself... but I actually already did, following this thread as an example: http://stackoverflow.com/questions/10801016/lwjgl-textures-and-strings

Following this example, I get pretty much the same kind of side effect, where all quads drawn after the image loading have a bugged color.


if you disable texture loading, you will get a "default" texture which has the color 1.0, 1.0, 1.0, 1.0 (full white, full alpha)
[/quote]

Yep, that's true; if I omit

GL11.glEnable(GL11.GL_TEXTURE_2D);

it just draws white in place of the texture. I can still draw other color quads just fine, and there are no weird side effects.


anyways, it seems like there's a problem with Slick-util, considering you are using tutorial code
unless there is a different color encoding scheme with your PNGs... who knows =)

you could try to load the textures yourself, and see what works and what doesn't
[/quote]

I have tried loading the textures myself, using more or less the SO thread code (http://stackoverflow.com/questions/10801016/lwjgl-textures-and-strings), and it had basically the same problem. That's why I tried Slick in the first place; because I thought it might do a better job of loading the textures.

This topic is closed to new replies.

Advertisement