(Solved)LWJGL 3D Tile map

Okay i am following TheBennyBox from Youtube I skipped most of the videos as I already had my own engine ready and I could convert most of the things he was saying into my engine but anyway lets get to the point I am trying to make the map and there are spaces inbetween each tile in like a diagonal way image below would explain better but I want it to not have those spaces

Also I cannot figure out how I would texture it all I could do was that little square

Not sure if this will help but I am using Open Gl 3+ from the YouTube tutorial from ThinMatrix

Map Code

public class Map {

	public static final int WIDTH = 1;
	public static final int HEIGHT = 1;
	public static final int LENGTH = 1;
	
	private TexturedModel mapModel;
	private VertexArray rawModel;
	private Bitmap mapImage;
	
	public Map() {
		mapImage = new Bitmap("res/levelTest.png");
	
		ArrayList<Float> verticesArray = new ArrayList<>();
		ArrayList<Integer> indicesArray = new ArrayList<>();
		
		for(int x = 0;x < mapImage.getWidth();x++){
			for(int z = 0; z < mapImage.getHeight();z++){
//				if((mapImage.getPixel(x,z) & 0xFFFFFF) == 0){
//					continue;
//				}
				
				indicesArray.add(verticesArray.size() + 0);
				indicesArray.add(verticesArray.size() + 1);
				indicesArray.add(verticesArray.size() + 2);
				
				indicesArray.add(verticesArray.size() + 2);
				indicesArray.add(verticesArray.size() + 3);
				indicesArray.add(verticesArray.size() + 0);
				
				addVertex(verticesArray, x*WIDTH, 0, z*LENGTH);
				addVertex(verticesArray, x*WIDTH, 0, (z+1)*LENGTH);
				addVertex(verticesArray, (x+1)*WIDTH, 0, (z+1)*LENGTH);
				addVertex(verticesArray, (x+1)*WIDTH, 0, z*LENGTH);
				
			}
		}
		
		float[] vertices = new float[verticesArray.size()];
		int[] indices = new int[indicesArray.size()];
		
		for(int i = 0;i < verticesArray.size();i++){
			vertices[i] = verticesArray.get(i);
		}
		for(int i = 0;i < indicesArray.size();i++){
			indices[i] = indicesArray.get(i);
		}
		
		float[] normals = {
				0,1,0
		};
		float[] textureCoords = {
			0,0,
			0,1,
			1,1,
			1,0
		};
		
		rawModel = new VertexArray(vertices, indices, textureCoords, normals);
		
		Texture grassTexture = Utils.loadTexture("grass");
		mapModel = new TexturedModel(new Model(rawModel), grassTexture);
		
	}
	private void addVertex(ArrayList<Float> vertices,float x,float y,float z){
		vertices.add(x);
		vertices.add(y);
		vertices.add(z);
	}
	
	public TexturedModel getModel(){
		return mapModel;
	}
	
	
}

I’ll just make one quick observation to get you started. This:

verticesArray.size()

Actually gives you the number of vertex elements so far, not the number of vertices (because verticesArray is a container of floats, not vectors). Since each vertex position has three elements, you’re effectively only adding indices for every third tile, and if you look at your rendering you’ll see that indeed it’s every third tile that’s being rendered.

To fix that particular problem (at least as an initial solution), try this (untested):


            
            final int currentVert = verticesArray.size() / 3;

            indicesArray.add(currentVert + 0);
            indicesArray.add(currentVert + 1);
            indicesArray.add(currentVert + 2);
            
            indicesArray.add(currentVert + 2);
            indicesArray.add(currentVert + 3);
            indicesArray.add(currentVert + 0);

There are probably other improvements that could be made there, but I’d start with that, just to get things working.

Thanks dude but I just figured it out!!! I am glad that I worked it out myself but thanks because thats the same way i got it working

Thanks anyway :slight_smile: