Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 thok   Members   -  Reputation: 693

Like
0Likes
Like

Posted 03 November 2012 - 08:51 PM

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!

Sponsor:

#2 Kaptein   Prime Members   -  Reputation: 2174

Like
0Likes
Like

Posted 03 November 2012 - 11:33 PM

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

Edited by Kaptein, 03 November 2012 - 11:33 PM.


#3 thok   Members   -  Reputation: 693

Like
0Likes
Like

Posted 04 November 2012 - 03:42 AM

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)


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


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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS