Android NDK OpenGL ES 1.0简单渲染 [英] Android NDK OpenGL ES 1.0 Simple Rendering

查看:226
本文介绍了Android NDK OpenGL ES 1.0简单渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Android NDK和OpenGL开始.我知道我在这里做某事(可能是几处)错了,并且由于我在测试时一直显示黑屏,所以我知道渲染没有发送到屏幕上.

I'm starting out with the Android NDK and OpenGL. I know I'm doing something (probably a few) things wrong here and since I keep getting a black screen when I test I know the rendering isn't being sent to the screen.

在Java中,我有一个GLSurfaceView.Renderer来调用这两个本机方法.它们已被正确调用,但没有绘制到设备屏幕上.

In the Java I have a GLSurfaceView.Renderer that calls these two native methods. They are being called correctly but not drawing to the device screen.

有人可以为此指向我正确的方向吗?

Could someone point me in the right direction with this?

以下是本机方法的实现:

Here are the native method implementations:

int init()
{
    sendMessage("init()");

    glGenFramebuffersOES(1, &framebuffer);
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);

    glGenRenderbuffersOES(1, &colorRenderbuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
    glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_RGBA8_OES, 854, 480);
    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);

    GLuint depthRenderbuffer;
    glGenRenderbuffersOES(1, &depthRenderbuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
    glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, 854, 480);
    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);

    GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES);
    if(status != GL_FRAMEBUFFER_COMPLETE_OES)
        sendMessage("Failed to make complete framebuffer object");

    return 0;
}

void draw()
{
    sendMessage("draw()");

    GLfloat vertices[] = {1,0,0, 0,1,0, -1,0,0};
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, vertices);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glDisableClientState(GL_VERTEX_ARRAY);

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, framebuffer);
    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
}

日志输出为:

init() 画() 画() 画() 等.

init() draw() draw() draw() etc..

推荐答案

在修修补补后,我终于找到了问题.

I finally found the problem after MUCH tinkering.

事实证明,因为我是从Java中的GLSurfaceView.Renderer调用代码的,所以帧缓冲区已经存在,因此可以调用:

Turns out that because I was calling the code from a GLSurfaceView.Renderer in Java the frame buffer already existed and so by calling:

glGenFramebuffersOES(1, &framebuffer);

我无意中分配了未附加到目标显示器的NEW缓冲区.通过删除此行并将其替换为:

I was unintentionally allocating a NEW buffer that was not attached to the target display. By removing this line and replacing it with:

framebuffer = (GLuint) 0;

现在它可以渲染到正确的缓冲区并在屏幕上正确显示.请注意,即使我并未在此代码段中真正使用缓冲区,但更改缓冲区还是弄乱了正确的显示.

It now renders to the correct buffer and displays properly on the screen. Note that even though I don't really use the buffer in this snippet, changing it is what messed up the proper display.

这篇关于Android NDK OpenGL ES 1.0简单渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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