Weird pixel stretching?

Hey, i got the ‘hard pixel’ effect working, but now on two sides of my cube it has become stretched!
photo Untitled_zps890b9821.png

Doees anyone know what the problem is or how i can fix it?
[java] public void drawTop() {
Mesh mesh = new Mesh();

int x = Mx + 0;
int y = My + 3;
int z = Mz + 0;    
Texture tex = assetManager.loadTexture("Textures/Terrain/brick.png");
tex.setMagFilter(Texture.MagFilter.Nearest);    

Vector3f [] vertices = new Vector3f[4];
vertices[0] = new Vector3f(x,y,z);
vertices[1] = new Vector3f(x+3,y,z);
vertices[2] = new Vector3f(x,y,z-3);
vertices[3] = new Vector3f(x+3,y,z-3);

Vector2f[] texCoord = new Vector2f[4];
texCoord[0] = new Vector2f(x,y);
texCoord[1] = new Vector2f(x+1,y);
texCoord[2] = new Vector2f(x,y+1);
texCoord[3] = new Vector2f(x+1,y+1);

int [] indexes = {2,0,1, 1,3,2};

mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
mesh.setBuffer(Type.Index,    3, BufferUtils.createIntBuffer(indexes));
mesh.updateBound();

Geometry geo = new Geometry("OurMesh", mesh);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", tex);
geo.setMaterial(mat);
rootNode.attachChild(geo);
}[/java]

Turn wrapping on for the texture.

Actually, that’s not it.

Y is the same for all points on the top. X is the same for all points on the stretched side.

So you are giving one edge and the other the same texture coordinates.

@pspeed said: Actually, that's not it.

Y is the same for all points on the top. X is the same for all points on the stretched side.

So you are giving one edge and the other the same texture coordinates.

Actually, it’s kind of both. You are giving the top texture coordinates 1 and 2 for the second value… so repeating would make it look right… but it’s probably also not what you want.

Okay, i understand but don’t know how to apply, just tried playing around with it and i cant get it to work!

Set a breakpoint and look at your texture coordinates… or log them.

Then make them right. They should be between 0 and 1 for what you are trying to do. You could get around it by turning on texture wrap but that’s not really what you want.

My guess is that for the top, you really wanted to use z instead of y as the texture coordinate basis… but really using x or y in them at all is not right.

You might consider whether or not your are in over your head. Block worlds are the harder type of engine to write and you are getting stuck on the easy parts.

Okay, i see where i went wrong, for the texCoords i used y which was being edited to move the starting vertex, so i changed the y to 0 and it wokrks :slight_smile:

And i know, but coding is more of a hobby for me, i don’t intend on doing anything with it, so i want to gradually build something/have something to work on in my spare time and make it good :slight_smile: