I tried interleaving the vertex array, but to no avail.
Here's my new interleaved code:
public static void generateVertexData(){
levelVertexHandle = glGenBuffers();
float[] vertexArray = new float[]{
//Point One
//Vertex
0f, 1f, 0f,
//Color
1f, 1f, 1f,
//Point Two
//Vertex
1f, 1f, 0f,
//Color
1f, 1f, 1f,
//Point Three
//Vertex
1f, 0f, 0f,
//Color
1f, 1f, 1f,
//Point Four
//Vertex
0f, 0f, 0f,
//Color
1f, 1f, 1f};
amountOfVertices = 4;
FloatBuffer vertexData = BufferUtils.createFloatBuffer(vertexArray.length);
vertexData.put(vertexArray);
vertexData.flip();
glBindBuffer(GL_ARRAY_BUFFER, levelVertexHandle);
glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
//TODO
public static void drawLevelVBO(){
int vertexSize = 3;
int colorSize = 3;
int stride = (vertexSize + colorSize) * 4;
glBindBuffer(GL_ARRAY_BUFFER, levelVertexHandle);
glVertexPointer(vertexSize, GL_FLOAT, stride, 0L);
glColorPointer(colorSize,GL_FLOAT,stride, (3 * 4));
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_QUADS, 0, amountOfVertices);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
And here's my "practice code" that works like a champ:
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
public class VertexBufferObjectDemo {
public VertexBufferObjectDemo() {
try {
Display.setDisplayMode(new DisplayMode(640, 480));
Display.setTitle("Vertex Buffer Object Demo");
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(1, 1, 1, 1, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
int amountOfVertices = 4;
int vertexSize = 3;
int colorSize = 3;
int stride = (vertexSize + colorSize) * 4;
float[] vertexArray = new float[]{-0.5f, -0.5f, 0, 1,0,0, 0.5f, -0.5f, 0, 0,1,0, 0.5f, 0.5f, 0, 0,0,1, -0.5f, 0.5f, 0, 1,1,1};
FloatBuffer vertexData = BufferUtils.createFloatBuffer(vertexArray.length);
vertexData.put(vertexArray);
vertexData.flip();
int vboVertexHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
int offset = 12;
while (!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT);
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glVertexPointer(vertexSize, GL_FLOAT, stride, 0L);
glColorPointer(colorSize,GL_FLOAT,stride,offset);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_QUADS, 0, amountOfVertices);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
Display.update();
Display.sync(60);
}
glDeleteBuffers(vboVertexHandle);
Display.destroy();
System.exit(0);
}
public static void main(String[] args) {
new VertexBufferObjectDemo();
}
}
I don't understand why the practice code works perfectly fine (Both interleaved and not), but the actual code doesn't.