[LWJGL] Color problem when I load a Texture ...

Hi,
[s]
When I try to load a Texture with slick-util, colors changes without any reasons…

Example :

http://image.noelshack.com/fichiers/2013/10/1362408230-capture.png

Code:

http://pastebin.java-gaming.org/26a65025f4f

Thank for your help :)[/s]

Sorry :smiley: I forget to clean my code so it’s a simplier code :

http://pastebin.java-gaming.org/2fff9515343

Square Class:

http://pastebin.java-gaming.org/fff9163534f

When I don’t load a texture:

http://image.noelshack.com/fichiers/2013/10/1362604538-capture1.png

When I load one:

http://image.noelshack.com/fichiers/2013/10/1362604539-capture2.png

Thank :slight_smile:

I’m no expert but loading and binding a white texture might fix your problem. Also from your source code I saw “Ciel.setColor(103,199,299);”, perhaps it’s different for your specific project but I have never seen color values go above 255.

I don’t use Slick or LWJGL but this

Ciel.setColor(103-Soleil.GetY(),199-Soleil.GetY(),299-Soleil.GetY());

interests me. How is the RGB of one square related to the y coordinate of another square?

Just to theorize before he answers:
103, 199, 299 gives the light blue color of his sky, perhaps Soleil is the sun block (sol in spanish is sun) and when the sun falls it gets darker representing night.

Better than loading a white texture into memory would be to disable textures for the duration.

Sorry :smiley: I forget to clean my code so it’s a simplier code :

http://pastebin.java-gaming.org/2fff9515343

Square Class:

http://pastebin.java-gaming.org/fff9163534f

When I don’t load a texture:

http://image.noelshack.com/fichiers/2013/10/1362604538-capture1.png

When I load one:

http://image.noelshack.com/fichiers/2013/10/1362604539-capture2.png

Thank :slight_smile:

If you are trying to draw a white rectangle, you need to either disable texturing or (preferably) use a white texture. Otherwise, your vertex color will be multiplied with the texture color, and you might end up with an unexpected result.

So it looks like this:

Texture white = TextureLoader.getTexture(... "white.png" ...); // a 2x2 opaque white texture
Texture myImg = TextureLoader.getTexture(... "img.png" ...); //a sprite

... in render ...

white.bind(); //bind the opaque white texture
//now you can render a square, using glColor3f to change its color
...

myImg.bind(); //bind your sprite.. 
//now you can render your sprites as normal...

The problem here, obviously, is that it leads to an extra texture bind. The solution is to use sprite sheets, which you should already be using, instead of a separate Texture for your white 2x2 rectangle.

I’d strongly recommend you to avoid using SlickUtil – it isn’t well maintained, it’s buggy, and it forces you into bad practices (i.e. immediate mode). Instead you should write your own texture loading code, through which you will learn a lot more than if you just continue to use SlickUtil.

Check out my display tutorial here to get a better idea of how to write your application lifecycle:

Then you can move on to writing your own texture loader:

You can see other tutorials here:

Feel free to use the API as a replacement to SlickUtil. It is more minimal and works better with modern GL, has better support for fonts, texture regions, shaders, etc.

Ok thx !

But why my color is stange whereas I just try to load a Texture(without displaying it) ?

Probably because a textureID has to be bound(bindtexture) before it can be loaded? slickUtil should automatically do that in order to load a texture.

Try this:


texture.bind();

GL11.glBegin(GL11.GL_QUADS);

GL11.glTextureCoord2f(0f, 0f);
GL11.glVertex2f(x, y);

GL11.glTextureCoord2f(texture.getWidth(), 0f);
GL11.glVertex2f(x + width, y));

GL11.glTextureCoord2f(texture.getWidth(), texture.getHeight());
GL11.glVertex2f(x + width, y + height);

GL11.glTextureCoord2f(0f, texture.getHeight());
Gl11.glVertex2f(x, y + height));

GL11.glEnd();

Longarmx --> Too late :stuck_out_tongue:

davedes -> I try to make a Texture class but I don’t understand how to bind the texture.
I am stuck here:

http://pastebin.java-gaming.org/ff913735f49

You bind a texture with glBindTexture, explained in the tutorial:

:slight_smile: