# LWJGL VBO's funktionieren nicht, geben aber auch keinen Fehler



## TheCreeper202 (18. Jul 2014)

Hallo!

Nach langer Zeit habe ich mal wieder ein Problem:

Ich habe ein Mesh in VBO's gespeichert aber es wird nicht gerendert! (Die render-Methode wird schon aufgerufen.) Die VBO's sind als Vertex Shader Attribute gegeben und werden mit den folgenden Shadern gerendert:
Vertex Shader:

```
attribute vec4 dn_Vertex;
attribute vec4 dn_Color;

varying vec4 color;

void main() {
    gl_Position = gl_ModelViewProjectionMatrix * dn_Vertex;
    color = dn_Color;
}
```

Fragment Shader:

```
varying vec4 color;

void main() {
    gl_FragColor = color;
}
```

Mesh Renderer:

```
package denomination.client.shapes;

import java.nio.FloatBuffer;
import java.nio.IntBuffer;

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

import denomination.client.Shader;
import denomination.client.util.Renderable;
import denomination.common.shapes.Mesh;
import denomination.common.shapes.MeshIndex;
import denomination.common.util.Vertex;

public class MeshRenderer implements Renderable {

	private int vertexBuffer;
	private int normalBuffer;
	private int texCoordBuffer;
	private int colorBuffer;
	private int tangentBuffer;
	private int bitangentBuffer;
	private int indexBuffer;
	private int indexBufferSize;

	public MeshRenderer(Mesh mesh) {
		FloatBuffer buffer;
		MeshIndex[] indices = mesh.getIndices();
		Vertex[] vertices = mesh.getVertices();
		
		this.vertexBuffer = GL15.glGenBuffers();
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBuffer);
		buffer = BufferUtils.createFloatBuffer(vertices.length * 4);
		for (Vertex v : vertices) {
			buffer.put(new float[] {
					v.x, v.y, v.z, 1
			});
		}
		buffer.flip();
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
		
		this.normalBuffer = GL15.glGenBuffers();
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, normalBuffer);
		buffer = BufferUtils.createFloatBuffer(vertices.length * 3);
		for (Vertex v : vertices) {
			buffer.put(new float[] {
					v.normal.x, v.normal.y, v.normal.z
			});
		}
		buffer.flip();
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
		
		this.texCoordBuffer = GL15.glGenBuffers();
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texCoordBuffer);
		buffer = BufferUtils.createFloatBuffer(vertices.length * 4);
		for (Vertex v : vertices) {
			buffer.put(new float[] {
					v.texCoords.x, v.texCoords.y, 0, 0
			});
		}
		buffer.flip();
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
		
		this.colorBuffer = GL15.glGenBuffers();
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, colorBuffer);
		buffer = BufferUtils.createFloatBuffer(vertices.length * 4);
		for (Vertex v : vertices) {
			buffer.put(new float[] {
					v.color.x, v.color.y, v.color.z, v.color.w
			});
		}
		buffer.flip();
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
		
		this.tangentBuffer = GL15.glGenBuffers();
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tangentBuffer);
		buffer = BufferUtils.createFloatBuffer(vertices.length * 3);
		for (Vertex v : vertices) {
			buffer.put(new float[] {
					v.tangent.x, v.tangent.y, v.tangent.z
			});
		}
		buffer.flip();
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
		
		this.bitangentBuffer = GL15.glGenBuffers();
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, bitangentBuffer);
		buffer = BufferUtils.createFloatBuffer(vertices.length * 3);
		for (Vertex v : vertices) {
			buffer.put(new float[] {
					v.bitangent.x, v.bitangent.y, v.bitangent.z
			});
		}
		buffer.flip();
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW);
		
		this.indexBuffer = GL15.glGenBuffers();
		this.indexBufferSize = indices.length * 3;
		GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
		IntBuffer index = BufferUtils.createIntBuffer(indexBufferSize);
		for (MeshIndex i : indices) {
			index.put(new int[] {
					i.x, i.y, i.z
			});
		}
		index.flip();
		GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, index, GL15.GL_STATIC_DRAW);
		
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
		GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
	}

	@Override
	public void render() {
		int attrib;
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_Vertex");
		if (attrib >= 0) {
			GL20.glEnableVertexAttribArray(attrib);
			GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vertexBuffer);
			GL20.glVertexAttribPointer(attrib, 4, GL11.GL_FLOAT, false, 0, 0);
		}
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_Normal");
		if (attrib >= 0) {
			GL20.glEnableVertexAttribArray(attrib);
			GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, normalBuffer);
			GL20.glVertexAttribPointer(attrib, 3, GL11.GL_FLOAT, false, 0, 0);
		}
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_TexCoord");
		if (attrib >= 0) {
			GL20.glEnableVertexAttribArray(attrib);
			GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, texCoordBuffer);
			GL20.glVertexAttribPointer(attrib, 4, GL11.GL_FLOAT, false, 0, 0);
		}
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_Color");
		if (attrib >= 0) {
			GL20.glEnableVertexAttribArray(attrib);
			GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, colorBuffer);
			GL20.glVertexAttribPointer(attrib, 4, GL11.GL_FLOAT, false, 0, 0);
		}
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_Tangent");
		if (attrib >= 0) {
			GL20.glEnableVertexAttribArray(attrib);
			GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, tangentBuffer);
			GL20.glVertexAttribPointer(attrib, 3, GL11.GL_FLOAT, false, 0, 0);
		}
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_Bitangent");
		if (attrib >= 0) {
			GL20.glEnableVertexAttribArray(attrib);
			GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, bitangentBuffer);
			GL20.glVertexAttribPointer(attrib, 3, GL11.GL_FLOAT, false, 0, 0);
		}
		
		GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
		GL11.glDrawElements(GL11.GL_TRIANGLES, indexBufferSize, GL11.GL_UNSIGNED_INT, 0);
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_Vertex");
		if (attrib >= 0) {
			GL20.glDisableVertexAttribArray(attrib);
		}
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_Normal");
		if (attrib >= 0) {
			GL20.glDisableVertexAttribArray(attrib);
		}
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_TexCoord");
		if (attrib >= 0) {
			GL20.glDisableVertexAttribArray(attrib);
		}
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_Color");
		if (attrib >= 0) {
			GL20.glDisableVertexAttribArray(attrib);
		}
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_Tangent");
		if (attrib >= 0) {
			GL20.glDisableVertexAttribArray(attrib);
		}
		
		attrib = GL20.glGetAttribLocation(Shader.CURRENT, "dn_Bitangent");
		if (attrib >= 0) {
			GL20.glDisableVertexAttribArray(attrib);
		}
		
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
		GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
	}
}
```

Hat irgendwer 'ne Ahnung, wo der Fehler ist?

Danke im Voraus!

TheCreeper202


----------

