Nothing is rendering

I recently re coded my chunk class because it badly needed it. I only got through the basics of the class before realizing it wasn’t rendering anything! I make a new VBO, store 16^3 cubes in it, then translate the VBO to its render position. Here’s the chunk class:

package com.mime.skyfox.Level;

import static org.lwjgl.opengl.GL11.GL_COLOR_ARRAY;
import static org.lwjgl.opengl.GL11.GL_FLOAT;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.GL_VERTEX_ARRAY;
import static org.lwjgl.opengl.GL11.glColorPointer;
import static org.lwjgl.opengl.GL11.glDisableClientState;
import static org.lwjgl.opengl.GL11.glDrawArrays;
import static org.lwjgl.opengl.GL11.glEnableClientState;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glTranslatef;
import static org.lwjgl.opengl.GL11.glVertexPointer;
import static org.lwjgl.opengl.GL15.GL_ARRAY_BUFFER;
import static org.lwjgl.opengl.GL15.glBindBuffer;

import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL15;

import com.mime.skyfox.Blocks.Block;

public class BaseChunk {

	// x - left/right y - up/down y - forward/backward

	public static final int CHUNK_X = 16;
	public static final int CHUNK_Y = 16;
	public static final int CHUNK_Z = 16;

	public boolean rebuild = false;

	FloatBuffer blockPositionData;
	FloatBuffer vertexColorData;

	private Block[][][] blocks;
	private int vboBlockData;
	private int vboColorData;

	private int chunkStartX;
	private int chunkStartY;
	private int chunkStartZ;

	public BaseChunk(int x, int z, int y) {
		chunkStartX = x;
		chunkStartY = y;
		chunkStartZ = z;

		blocks = new Block[CHUNK_X][CHUNK_Z][CHUNK_Y];

		for (int xx = 0; xx < CHUNK_X; xx++) {
			for (int zz = 0; zz < CHUNK_Z; zz++) {
				for (int yy = 0; yy < CHUNK_Y; yy++) {
					blocks[xx][zz][yy] = Block.Grass;
				}
			}
		}
	}

	public void rebuildChunk() {
		vboBlockData = GL15.glGenBuffers();
		blockPositionData = BufferUtils.createFloatBuffer((CHUNK_X * CHUNK_Z * CHUNK_Y) * 6 * 12);

		vboColorData = GL15.glGenBuffers();
		vertexColorData = BufferUtils.createFloatBuffer((CHUNK_X * CHUNK_Z * CHUNK_Y) * 6 * 12);

		for (int xx = 0; xx < CHUNK_X; xx++) {
			for (int zz = 0; zz < CHUNK_Z; zz++) {
				for (int yy = 0; yy < CHUNK_Y; yy++) {
					blockPositionData.put(makeCube((float) chunkStartX + xx, (float) chunkStartZ + zz, chunkStartY + yy));
					vertexColorData.put(getColor(Block.Grass));
				}
			}
		}
		vertexColorData.flip();
		blockPositionData.flip();
	}

	private float[] makeCube(float x, float z, float y) {
		int offset = Block.size / 2;

		return new float[] { x + offset, y + offset, z, x - offset, y + offset, z, x - offset, y + offset, z - Block.size, x + offset, y + offset, z - Block.size, x + offset, y - offset, z - Block.size, x - offset, y - offset, z - Block.size, x - offset, y - offset, z, x + offset, y - offset, z, x + offset, y + offset, z - Block.size, x - offset, y + offset, z - Block.size, x - offset, y - offset, z - Block.size, x + offset, y - offset, z - Block.size, x + offset, y - offset, z, x - offset, y - offset, z, x - offset, y + offset, z, x + offset, y + offset, z, x - offset, y + offset, z - Block.size, x - offset, y + offset, z, x - offset, y - offset, z, x - offset, y - offset, z - Block.size, x + offset, y + offset, z, x + offset, y + offset, z - Block.size, x + offset, y - offset,
				z - Block.size, x + offset, y - offset, z };
	}

	private int getColor(Block block) {
		return block.color;
	}

	public void render(int x, int z, int y) {
		glBindBuffer(GL_ARRAY_BUFFER, vboBlockData);
		glVertexPointer(3, GL_FLOAT, 0, 0L);

		glBindBuffer(GL_ARRAY_BUFFER, vboColorData);
		glColorPointer(3, GL_FLOAT, 0, 0L);

		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_COLOR_ARRAY);
		for (int yy = 0; yy < y; yy++) {
			for (int xx = 0; xx < x; xx++) {
				for (int zz = 0; zz < z; zz++) {
					glPushMatrix();
					glTranslatef(xx, zz, yy);
					glDrawArrays(GL_QUADS, 0, 24);
					glPopMatrix();
				}
			}

		}
		glDisableClientState(GL_VERTEX_ARRAY);
		glDisableClientState(GL_COLOR_ARRAY);
	}
}

And I call it like this:

baseChunk = new BaseChunk(16, 16, 16);
		baseChunk.rebuildChunk();
		baseChunk.render(16, 16, 16);

Could it have something to do with my offsets in the make cube method?

Correct me if I´m wrong, but I can´t see that you´re binding “vboBlockData” to “blockPositionData”.

Try to add

glBindBuffer(GL_ARRAY_BUFFER, vboBlockData);
glBufferData(GL_ARRAY_BUFFER, blockPositionData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

glBindBuffer(GL_ARRAY_BUFFER, vboColorData);
glBufferData(GL_ARRAY_BUFFER, vertexColorData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);

in your rebuildChunk()

On a side note to anyone who might know: Do you need to “unbind” with “glBindBuffer(GL_ARRAY_BUFFER, 0)” or does it suffice to just bind another buffer…?

You can just directly bind another buffer.

I thought so but it´s always good to know. :slight_smile: Thanks, AgentD!

Well I tried to do that and for some reason its just not working :confused: Its getting very frustrating now…
Here’s my current code:

package com.mime.skyfox.Level;

import static org.lwjgl.opengl.GL15.GL_STATIC_DRAW;
import static org.lwjgl.opengl.GL11.GL_COLOR_ARRAY;
import static org.lwjgl.opengl.GL11.GL_FLOAT;
import static org.lwjgl.opengl.GL11.GL_QUADS;
import static org.lwjgl.opengl.GL11.GL_VERTEX_ARRAY;
import static org.lwjgl.opengl.GL11.glColorPointer;
import static org.lwjgl.opengl.GL11.glDisableClientState;
import static org.lwjgl.opengl.GL11.glDrawArrays;
import static org.lwjgl.opengl.GL11.glEnableClientState;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glTranslatef;
import static org.lwjgl.opengl.GL11.glVertexPointer;
import static org.lwjgl.opengl.GL15.GL_ARRAY_BUFFER;
import static org.lwjgl.opengl.GL15.glBindBuffer;

import java.nio.FloatBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL15;

import com.mime.skyfox.Blocks.Block;

public class BaseChunk {

	   // x - left/right y - up/down y - forward/backward

	   public static final int CHUNK_X = 16;
	   public static final int CHUNK_Y = 16;
	   public static final int CHUNK_Z = 16;

	   public boolean rebuild = false;

	   FloatBuffer blockPositionData;
	   FloatBuffer vertexColorData;

	   private Block[][][] blocks;
	   private int vboBlockData;
	   private int vboColorData;

	   private int chunkStartX;
	   private int chunkStartY;
	   private int chunkStartZ;

	   public BaseChunk(int x, int z, int y) {
	      chunkStartX = x;
	      chunkStartY = y;
	      chunkStartZ = z;

	      blocks = new Block[CHUNK_X][CHUNK_Z][CHUNK_Y];

	      for (int xx = 0; xx < CHUNK_X; xx++) {
	         for (int zz = 0; zz < CHUNK_Z; zz++) {
	            for (int yy = 0; yy < CHUNK_Y; yy++) {
	               blocks[xx][zz][yy] = Block.Grass;
	            }
	         }
	      }
	   }

	   public void rebuildChunk() {
	      vboBlockData = GL15.glGenBuffers();
	      blockPositionData = BufferUtils.createFloatBuffer((CHUNK_X * CHUNK_Z * CHUNK_Y) * 6 * 12);

	      vboColorData = GL15.glGenBuffers();
	      vertexColorData = BufferUtils.createFloatBuffer((CHUNK_X * CHUNK_Z * CHUNK_Y) * 6 * 12);

	      for (int xx = 0; xx < CHUNK_X; xx++) {
	         for (int zz = 0; zz < CHUNK_Z; zz++) {
	            for (int yy = 0; yy < CHUNK_Y; yy++) {
	               blockPositionData.put(makeCube((float) chunkStartX + xx, (float) chunkStartZ + zz, chunkStartY + yy));
	               vertexColorData.put(getColor(Block.Grass));
	            }
	         }
	      }
	      glBindBuffer(GL_ARRAY_BUFFER, vboBlockData);
	      GL15.glBufferData(GL_ARRAY_BUFFER, blockPositionData, GL_STATIC_DRAW);
	      glBindBuffer(GL_ARRAY_BUFFER, 0);

	      glBindBuffer(GL_ARRAY_BUFFER, vboColorData);
	      GL15.glBufferData(GL_ARRAY_BUFFER, vertexColorData, GL_STATIC_DRAW);
	      glBindBuffer(GL_ARRAY_BUFFER, 0);

	      vertexColorData.flip();
	      blockPositionData.flip();
	   }

	   private float[] makeCube(float x, float z, float y) {
	      int offset = Block.size / 2;

	      return new float[] { x + offset, y + offset, z, x - offset, y + offset, z, x - offset, y + offset, z - Block.size, x + offset, y + offset, z - Block.size, x + offset, y - offset, z - Block.size, x - offset, y - offset, z - Block.size, x - offset, y - offset, z, x + offset, y - offset, z, x + offset, y + offset, z - Block.size, x - offset, y + offset, z - Block.size, x - offset, y - offset, z - Block.size, x + offset, y - offset, z - Block.size, x + offset, y - offset, z, x - offset, y - offset, z, x - offset, y + offset, z, x + offset, y + offset, z, x - offset, y + offset, z - Block.size, x - offset, y + offset, z, x - offset, y - offset, z, x - offset, y - offset, z - Block.size, x + offset, y + offset, z, x + offset, y + offset, z - Block.size, x + offset, y - offset,
	            z - Block.size, x + offset, y - offset, z };
	   }

	   private int getColor(Block block) {
	      return block.color;
	   }

	   public void render(int x, int z, int y) {
	      glBindBuffer(GL_ARRAY_BUFFER, vboBlockData);
	      glVertexPointer(3, GL_FLOAT, 0, 0L);

	      glBindBuffer(GL_ARRAY_BUFFER, vboColorData);
	      glColorPointer(3, GL_FLOAT, 0, 0L);

	      glEnableClientState(GL_VERTEX_ARRAY);
	      glEnableClientState(GL_COLOR_ARRAY);
	      for (int yy = 0; yy < y; yy++) {
	         for (int xx = 0; xx < x; xx++) {
	            for (int zz = 0; zz < z; zz++) {
	               glPushMatrix();
	               glTranslatef(xx, zz, yy);
	               glDrawArrays(GL_QUADS, 0, 24);
	               glPopMatrix();
	            }
	         }

	      }
	      glDisableClientState(GL_VERTEX_ARRAY);
	      glDisableClientState(GL_COLOR_ARRAY);
	   }
	}

I call a new instance of the chunk with the parameters 0, 0, 0 as the starting point for the chunk to generate. Then I call the rebuildChunk method, and then the render method with parameters of 16, 16, 16. Still just a blank screen.