简体   繁体   English

JVM使用LWJGL与VBO崩溃

[英]JVM crashing with VBOs using LWJGL

Every time I try to run my LWJGL application the JVM crashes. 每次我尝试运行我的LWJGL应用程序时,JVM都会崩溃。 It seems to be related to adding multiple triangles to my VBO. 这似乎与向我的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. 当我删除顶点数组中的最后9个值时,它工作正常,但如果我保留这些值,或者添加更多,JVM将崩溃。

The first argument to glVertexPointer is the number of coordinates per vertex, not the number of vertices. glVertexPointer的第一个参数是每个顶点的坐标数,而不是顶点数。 So change that line to this: 所以改变这一行:

glVertexPointer(3, GL_FLOAT, 0, 0L);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM