Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LWJGL] Color problem when I load a Texture ...  (Read 962 times)
0 Members and 1 Guest are viewing this topic.
Offline Cinem

Junior Newbie





« Posted 2013-03-04 15:42:04 »

Hi,

When I try to load a Texture with slick-util, colors changes without any reasons...

Example :



Code:

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

Thank for your help Smiley


Sorry  Cheesy 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:



When I load one:



Thank Smiley
Offline Vladiedoo

Senior Member


Medals: 11



« Reply #1 - Posted 2013-03-06 02:41:36 »

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.
Online Jimmt
« Reply #2 - Posted 2013-03-06 06:26:10 »

I don't use Slick or LWJGL but this
1  
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?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Vladiedoo

Senior Member


Medals: 11



« Reply #3 - Posted 2013-03-06 06:31:39 »

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.
Offline quew8

Junior Member


Medals: 3



« Reply #4 - Posted 2013-03-06 19:30:06 »

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

Junior Newbie





« Reply #5 - Posted 2013-03-06 22:13:18 »

Sorry  Cheesy 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:



When I load one:



Thank Smiley
Offline davedes
« Reply #6 - Posted 2013-03-06 22:32:36 »

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
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:
https://github.com/mattdesl/lwjgl-basics/wiki/Display

Then you can move on to writing your own texture loader:
https://github.com/mattdesl/lwjgl-basics/wiki/Textures

You can see other tutorials here:
https://github.com/mattdesl/lwjgl-basics/wiki

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.
 

Offline Cinem

Junior Newbie





« Reply #7 - Posted 2013-03-06 22:43:09 »

Ok thx !

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

Senior Member


Medals: 3
Projects: 1



« Reply #8 - Posted 2013-03-07 00:58:46 »

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.
Offline Longarmx

Senior Member


Medals: 4
Projects: 1



« Reply #9 - Posted 2013-03-07 04:16:08 »

Try this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
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();

Thread.sleep(∞);

Color Game
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cinem

Junior Newbie





« Reply #10 - Posted 2013-03-07 22:55:45 »

Longarmx --> Too late :p

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
Offline davedes
« Reply #11 - Posted 2013-03-08 19:38:38 »

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

https://github.com/mattdesl/lwjgl-basics/wiki/Textures

Smiley

Pages: [1]
  ignore  |  Print  
 
 

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (136 views)
2013-05-17 21:29:12

alaslipknot (145 views)
2013-05-16 21:24:48

gouessej (175 views)
2013-05-16 00:53:38

gouessej (169 views)
2013-05-16 00:17:58

theagentd (179 views)
2013-05-15 15:01:13

theagentd (163 views)
2013-05-15 15:00:54

StreetDoggy (208 views)
2013-05-14 15:56:26

kutucuk (232 views)
2013-05-12 17:10:36

kutucuk (231 views)
2013-05-12 15:36:09

UnluckyDevil (236 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.166 seconds with 21 queries.