Texture size (int)

Started by Skatty, July 07, 2013, 19:23:15

Previous topic - Next topic

Skatty

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.

Cornix

The texture coords are normalized. The range for texture coords is [0, 1] by default.

Skatty

? But i wanna calculate pixels in .png texture file for the correct one.

Cornix

Divide your pixel coordinates by the overall texture size.

Skatty

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

quew8

Probably float casting problem.
spriteX = ( (float) x * (float) textureSize ) / pngSize;
spriteY = ( (float) y * (float) textureSize ) / pngSize;

Skatty


Skatty

Lol.
Fixed.

public static float textureSize = 0.0625f;

	public void setSpriteCoords(int x, int y) {

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