LWJGL在不同系统上使用VBO进行渲染

时间:2014-06-23 13:39:18

标签: java opengl vbo

我正在为我的论文创建一个2D SideScroller游戏。为了渲染环境,我想使用顶点缓冲对象。在家里,一切正常,但在大学我得到一个类似的错误信息:

A fatal error has been detected by the Java Runtime Environment:

  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x651e3435, pid=964, tid=2988

 JRE version: Java(TM) SE Runtime Environment (7.0_55-b13) (build 1.7.0_55-b13)
 Java VM: Java HotSpot(TM) Client VM (24.55-b03 mixed mode, sharing windows-x86 )
 Problematic frame:
 C  [nvoglv32.DLL+0xaf3435]

 Failed to write core dump. Minidumps are not enabled by default on client versions of Windows

 An error report file with more information is saved as:
 U:\Desktop\newWS\Bachelor\Bachelor\hs_err_pid964.log

 If you would like to submit a bug report, please visit:
   http://bugreport.sun.com/bugreport/crash.jsp
 The crash happened outside the Java Virtual Machine in native code.
 See problematic frame for where to report the bug.

当第一个级别完成时出现此错误,并且在此处加载下一个级别我打电话

private void init() {
    VBOLandScapeHandler = glGenBuffers();
    VBOTextureHandler = glGenBuffers();
    // VBOTextureHandler = glGenTextures()
    createBuffer();
}

private void createBuffer() {
    landScapeArray = BufferUtils
            .createFloatBuffer(level.getVerticeCount() * 2);
    textureArray = BufferUtils
            .createFloatBuffer(level.getVerticeCount() * 2);
    for (List<LandscapePart> landscapePart : level.getParts()) {
        for (LandscapePart cur : landscapePart) {
            if (cur instanceof Seesaw || cur.belongsToSeesaw()) {
                // landScapeArray.put(new float[] { ((Seesaw)
                // cur).getP5().getX(), ((Seesaw) cur).getP5().getY() });
                continue;
            }
            landScapeArray.put(new float[] { cur.getP1().getX(),
                    cur.getP1().getY() });
            landScapeArray.put(new float[] { cur.getP2().getX(),
                    cur.getP2().getY() });
            landScapeArray.put(new float[] { cur.getP3().getX(),
                    cur.getP3().getY() });
            landScapeArray.put(new float[] { cur.getP4().getX(),
                    cur.getP4().getY() });
            textureArray.put(new float[] { 0, 0 });
            textureArray.put(new float[] { 1, 0 });
            textureArray.put(new float[] { 1, 1 });
            textureArray.put(new float[] { 0, 1 });
        }
    }

    landScapeArray.flip();
    textureArray.flip();
}

public void draw() {
    earth.bind();
    // bind landScape data
    glBindBuffer(GL_ARRAY_BUFFER, VBOLandScapeHandler);
    glBufferData(GL_ARRAY_BUFFER, landScapeArray, GL_STATIC_DRAW);
    glVertexPointer(2, GL_FLOAT, 0, 0L);

    glBindBuffer(GL_ARRAY_BUFFER, VBOTextureHandler);
    glBufferData(GL_ARRAY_BUFFER, textureArray, GL_STATIC_DRAW);
    glTexCoordPointer(2, GL_FLOAT, 0, 0L);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glDrawArrays(GL_QUADS, 0, landScapeArray.limit());
    // // Unbind the VBO
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    // // Disable Vertex Arrays (VBOs)
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}

在家里我使用的是Geforce gtx 750 ti twin frozr,大学里有一台Quadro 2000.

Nvidia驱动程序是最新的,使用立即模式工作正常,但这没有好的解决方案=)

也许某种程度上可以在错误报告文件的内容中获得更多信息:

http://www.share-online.biz/dl/3BJUHM7NFGB

补充VBO是否有任何错误?

1 个答案:

答案 0 :(得分:0)

你的问题很可能在这里:

glDrawArrays(GL_QUADS, 0, landScapeArray.limit());

我相信landScapeArray.limit()是缓冲区中浮点值的数量。 glDrawArrays()的第三个参数是要绘制的顶点的数量。由于每个顶点有2个浮点数,因此需要:

glDrawArrays(GL_QUADS, 0, landScapeArray.limit() / 2);