LWJGL中的黑屏

时间:2013-05-12 21:48:41

标签: opengl lwjgl

我目前正在移植一款游戏,由于从C移植到Java,代码非常模糊。

我的问题是有些用户报告黑屏而没有其他问题(声音工作正常,例如),没有错误显示问题。在我的电脑上它运行正常,这使得调试很糟糕。

我想知道是否有人可以发布可能正在发生的(原因列表)原因。我读过某个问题,其中一个问题可能是在64位系统上使用32位Java。

我的代码如下,也是开源的:https://code.google.com/p/jake2t/

    private void renderSideBySide() {
        glBindTexture(GL_TEXTURE_2D, 0);
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, sbsFboId);

        // Render side by side
        glPushAttrib(GL_ALL_ATTRIB_BITS);
        glPushMatrix();

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(0, width, 0, height);
        glMatrixMode (GL_MODELVIEW);
        glLoadIdentity ();

        glViewport(0,0,width,height);


        glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
        glDisable(GL_BLEND);
        glDisable(GL_ALPHA_TEST);
        glDisable(GL_CULL_FACE);

        int shaderId = sbsShader.getId();
        glDisable(GL_TEXTURE_2D);

        ARBShaderObjects.glUseProgramObjectARB(shaderId);

        if (postFboTextureLocation[0] < 0) {
            postFboTextureLocation[0] = ARBShaderObjects.glGetUniformLocationARB(shaderId, "leftTexture");
        }
        if (postFboTextureLocation[1] < 0) {
            postFboTextureLocation[1] = ARBShaderObjects.glGetUniformLocationARB(shaderId, "rightTexture");
        }
        if (postFboDepthTextureLocation[0] < 0) {
            postFboDepthTextureLocation[0] = ARBShaderObjects.glGetUniformLocationARB(shaderId, "leftDepthTexture");
        }
        if (postFboDepthTextureLocation[1] < 0) {
            postFboDepthTextureLocation[1] = ARBShaderObjects.glGetUniformLocationARB(shaderId, "rightDepthTexture");
        }

        // Load the images with the colors and the depth values
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, postFboTextureId[0]);
        ARBShaderObjects.glUniform1iARB(postFboTextureLocation[0], 0); 
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, postFboTextureId[1]);
        ARBShaderObjects.glUniform1iARB(postFboTextureLocation[1], 1); 
        glActiveTexture(GL_TEXTURE2);
        glBindTexture(GL_TEXTURE_2D, postFboDepthTexture[0]);
        ARBShaderObjects.glUniform1iARB(postFboDepthTextureLocation[0], 2); 
        glActiveTexture(GL_TEXTURE3);
        glBindTexture(GL_TEXTURE_2D, postFboDepthTexture[1]);
        ARBShaderObjects.glUniform1iARB(postFboDepthTextureLocation[1], 3); 

        glBegin (GL_QUADS);
        glTexCoord2f(0.0f, 0.0f);
        glVertex2i (0, 0);
        glTexCoord2f(1.0f, 0.0f);
        glVertex2i (width, 0);
        glTexCoord2f(1.0f, 1.0f);
        glVertex2i (width, height);
        glTexCoord2f(0.0f, 1.0f);
        glVertex2i (0, height); 
        glEnd();                                                    

        ARBShaderObjects.glUseProgramObjectARB(0);

        // Rendering with warping
        glPopMatrix();
        glPopAttrib();

        unbindFBO();
    }

    public void drawPostFBOs() {
        renderSideBySide();

        glPushAttrib(GL_ALL_ATTRIB_BITS);
        glPushMatrix();

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(0, width, 0, height);
        glMatrixMode (GL_MODELVIEW);
        glLoadIdentity ();

        glViewport(0,0,width,height);


        glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
        glClear (GL_COLOR_BUFFER_BIT);

        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
        glDisable(GL_BLEND);
        glDisable(GL_ALPHA_TEST);
        glDisable(GL_CULL_FACE);
        glDisable(GL_TEXTURE_2D);

        int shaderId = riftShader.getId();

        ARBShaderObjects.glUseProgramObjectARB(shaderId);

        if (sbsFboTextureLocation < 0) {
            sbsFboTextureLocation = ARBShaderObjects.glGetUniformLocationARB(shaderId, "tex");
        }

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, sbsFboTextureId);
        ARBShaderObjects.glUniform1iARB(sbsFboTextureLocation, 0); 

        glBegin (GL_QUADS);
        glTexCoord2f(0.0f, 0.0f);
        glVertex2i (0, 0);
        glTexCoord2f(1.0f, 0.0f);
        glVertex2i (width, 0);
        glTexCoord2f(1.0f, 1.0f);
        glVertex2i (width, height);
        glTexCoord2f(0.0f, 1.0f);
        glVertex2i (0, height); 
        glEnd();                                                    

        ARBShaderObjects.glUseProgramObjectARB(0);


        glPopMatrix();
        glPopAttrib();
    }

1 个答案:

答案 0 :(得分:0)

OpenGL 3+程序员在编码时不考虑的常见问题是:

OpenGL Extensions

  • 使用 ARB EXT 扩展程序。
  • 使用正确的OGL扩展名。
  • 使用不同OGL扩展的多个实现。以下是使用C ++的示例:

    #ifndef _MESA_INVERT_
        /*** ... some codes here ... ***/ 
    #else
        /*** ... alt some codes here ... ***/ 
    #endif
    

使用以下方法检查视频卡是否支持以下扩展名:

  • glxinfo - 基于Linux和MacOS X的系统。
  • glview - 基于Windows的系统。