我試圖實現一種方法來繪製一堆使用OpenGL和Java中的vertexBufferObjects的多維數據集,但在調用glDrawArrays命令時遇到問題。glDrawArrays Exception_Access_Violation
本質上,該程序所做的是循環通過x,y,z座標,並從那裏計算以該座標爲中心的立方體的頂點,然後將這些頂點輸入到浮點緩衝區。 (請注意,我只是在一瞬間進入了一個面的頂點數據,以保持代碼的簡潔,同時它完善)
出現的錯誤是:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006056ec90, pid=6424, tid=7696
int verticesPerObject = 12; //number of vertices per square
int chunkSizeX = 4; //number of cubes in x direction
int chunkSizeY = 4; //number of cubes in y direction
int chunkSizeZ = 4; //number of cubes in z direction
FloatBuffer vertexData = BufferUtils.createFloatBuffer(chunkSizeX * chunkSizeY * chunkSizeZ * verticesPerObject);
for (int x = 0; x < chunkSizeX; x++) {
for (int y = 0; y < chunkSizeY; y++) {
for (int z = 0; z < chunkSizeZ; z++) {
vertexData.put(new float[]{
(float)x * blockWidth - blockWidth/2, (float)y * blockHeight - blockHeight/2, (float)z * blockDepth + blockDepth/2,
(float)x * blockWidth + blockWidth/2, (float)y * blockHeight - blockHeight/2, (float)z * blockDepth + blockDepth/2,
(float)x * blockWidth + blockWidth/2, (float)y * blockHeight + blockHeight/2, (float)z * blockDepth + blockDepth/2,
(float)x * blockWidth - blockWidth/2, (float)y * blockHeight + blockHeight/2, (float)z * blockDepth + blockDepth/2
});
}
}
}
vertexData.flip();
int vboVertexHandle = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
glVertexPointer(verticesPerObject, GL_FLOAT, 0, 0L);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_QUADS, 0, verticesPerObject);
glDisableClientState(GL_VERTEX_ARRAY);
我來這裏不期待這個回答我的問題。非常感謝:D –