在不同系统上使用 VBO 进行 LWJGL 渲染 [英] LWJGL rendering with VBO on different Systems

查看:64
本文介绍了在不同系统上使用 VBO 进行 LWJGL 渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Im creating a 2D SideScroller game for my thesis. For rendering the environment i want to use Vertex Buffer Objects. At home, everything works fine, but in University i get a similar error message:

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.

出现这个错误,当第一个关卡完成时,我调用下一个关卡加载

This error appears, when the first Level is complete, and the next Level is loaded here i call

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.

At home im using a Geforce gtx 750 ti twin frozr, here in university a Quadro 2000.

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

Nvidia Driver up-to-date, using immediate mode works fine, but thats no good solution =)

也许可以通过某种方式在错误报告文件的内容中获得更多信息:

Maybe somehow can get more information in the content of the error report file:

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

重新填充 VBO 是否有任何错误?

Are there any mistakes refilling the VBO?

推荐答案

您的问题很可能出现在这里:

Your problem is most likely here:

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

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

I believe landScapeArray.limit() is the number of float values in your buffer. The 3rd argument of glDrawArrays() is the number of vertices to be drawn. Since you have 2 floats per vertex, you need:

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

这篇关于在不同系统上使用 VBO 进行 LWJGL 渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆