Вопрос

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