LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Skatty on July 07, 2013, 19:23:15

Title: Texture size (int)
Post by: Skatty on July 07, 2013, 19:23:15
Hi

I have textures 256x256 in 1 big texture file(spritesheet).

I define size of texture:

public static int textureSize = 256;

and got method which sets correct coords for texture(it get x, y from block classes which sent coords in on example: 0,1 ; 0,0 ; 2,3):

public void setSpriteCoords(int x, int y) {

spriteX = x * textureSize;
spriteY = y * textureSize;

}

But in game it print me not the only 1 correct texture but all textures file (4096x4096 px) per 1 wall of my cube ; /. Idk why. shouldn't it work fine? 256 int = 256px so when method get coords: 2,3 it calculate and use 512 and 768.
Title: Re: Texture size (int)
Post by: Cornix on July 07, 2013, 19:28:40
The texture coords are normalized. The range for texture coords is [0, 1] by default.
Title: Re: Texture size (int)
Post by: Skatty on July 07, 2013, 19:35:20
? But i wanna calculate pixels in .png texture file for the correct one.
Title: Re: Texture size (int)
Post by: Cornix on July 07, 2013, 19:36:47
Divide your pixel coordinates by the overall texture size.
Title: Re: Texture size (int)
Post by: Skatty on July 07, 2013, 19:43:38
spriteX = x * textureSize / pngSize;
spriteY = y * textureSize / pngSize;


pngSize = 4096 but it still print all texture file on 1 wall ; /

P.S spriteX and Y are floats

Screen:
http://scr.hu/19cj/dvda1
Title: Re: Texture size (int)
Post by: quew8 on July 08, 2013, 07:52:31
Probably float casting problem.

spriteX = ( (float) x * (float) textureSize ) / pngSize;
spriteY = ( (float) y * (float) textureSize ) / pngSize;
Title: Re: Texture size (int)
Post by: Skatty on July 08, 2013, 08:28:35
Still same bug ..
Title: Re: Texture size (int)
Post by: Skatty on July 08, 2013, 08:58:45
Lol.
Fixed.

public static float textureSize = 0.0625f;

public void setSpriteCoords(int x, int y) {

spriteX = x * textureSize;
spriteY = y * textureSize;
}