문제

Every time I try to run my LWJGL application the JVM crashes. It seems to be related to adding multiple triangles to my VBO.

Here is my initialization code

float[] vertices = {
    -0.5f, 0.5f, 0f,
    -0.5f, -0.5f, 0f,
    0.5f, -0.5f, 0f,

    0.5f, -0.5f, 0f,
    0.5f, 0.5f, 0f,
    -0.5f, 0.5f, 0f
};

vertexCount = vertices.length / 3;

FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length);
verticesBuffer.put(vertices);
verticesBuffer.flip();

vboId = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboId);
glBufferData(GL_ARRAY_BUFFER, verticesBuffer, GL_STATIC_DRAW);
glVertexPointer(vertexCount, GL_FLOAT, 0, 0L);

glBindBuffer(GL_ARRAY_BUFFER, 0);

And this is my rendering code

glEnableClientState(GL_VERTEX_ARRAY);   
glDrawArrays(GL_TRIANGLES, 0, vertexCount);
glDisableClientState(GL_VERTEX_ARRAY);

When I remove the last 9 values in the vertices array it works fine, but if I keep those, or add more, the JVM will crash.

도움이 되었습니까?

해결책

The first argument to glVertexPointer is the number of coordinates per vertex, not the number of vertices. So change that line to this:

glVertexPointer(3, GL_FLOAT, 0, 0L);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top