Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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 2264 times)
0 Members and 1 Guest are viewing this topic.
Offline Cinem

Senior Newbie





« Posted 2013-03-04 14: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
« Reply #1 - Posted 2013-03-06 01: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.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 133
Projects: 4
Exp: 3 years



« Reply #2 - Posted 2013-03-06 05: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
« Reply #3 - Posted 2013-03-06 05: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

JGO Coder


Medals: 30



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

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

Senior Newbie





« Reply #5 - Posted 2013-03-06 21: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 21: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

Senior Newbie





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

Ok thx !

But why my color is stange whereas I just try to load a Texture(without displaying it) ?
Offline relminator
« Reply #8 - Posted 2013-03-06 23: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
« Reply #9 - Posted 2013-03-07 03: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();

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

Senior Newbie





« Reply #10 - Posted 2013-03-07 21: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 18: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  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (41 views)
2014-09-24 16:13:29

Pippogeek (32 views)
2014-09-24 16:12:22

Pippogeek (22 views)
2014-09-24 16:12:06

Grunnt (47 views)
2014-09-23 14:38:19

radar3301 (30 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (44 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06

BurntPizza (55 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!