glGenFramebuffers无法在VS 2019中与本机Android项目一起使用

时间:2019-10-31 00:50:18

标签: c++ opengl-es android-ndk visual-studio-2019 egl

我一直在尝试渲染纹理,但是glGenFramebuffers没有给我有效的帧缓冲区对象。

我尝试在各个位置调用glGenFramebuffers,以防OpenGL ES API未完全初始化。然后我尝试使用Visual Studio 2019创建一个全新的本机Android项目,并以相同的结果调用`glGenFramebuffers'。

在本机Android模板内engine_init_display的最底部,我正在调用以下代码。

uint nFrameBufferID = 0;
glGenFramebuffers(1, &nFrameBufferID);

结果始终为0。我无法获得有效的帧缓冲区ID。我在做什么错了?

更新-重制步骤:

使用Visual Studio创建一个Native-Android Application项目 enter image description here

将上面的代码添加到函数最底部engine_init_displaymain.cpp的底部。另外,请确保将#include <GLES2/gl2.h>添加到文件顶部。 enter image description here

进一步澄清

static int engine_init_display(struct engine* engine) {
    // initialize OpenGL ES and EGL

    const EGLint attribs[] = {
        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
        EGL_BLUE_SIZE, 8,
        EGL_GREEN_SIZE, 8,
        EGL_RED_SIZE, 8,
        EGL_NONE
    };
    EGLint w, h, format;
    EGLint numConfigs;
    EGLConfig config;
    EGLSurface surface;
    EGLContext context;

    EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    eglInitialize(display, 0, 0);
    eglChooseConfig(display, attribs, &config, 1, &numConfigs);
    eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
    ANativeWindow_setBuffersGeometry(engine->app->window, 0, 0, format);

    surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
    context = eglCreateContext(display, config, NULL, NULL);

    if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
        LOGW("Unable to eglMakeCurrent");
        return -1;
    }

    eglQuerySurface(display, surface, EGL_WIDTH, &w);
    eglQuerySurface(display, surface, EGL_HEIGHT, &h);

    engine->display = display;
    engine->context = context;
    engine->surface = surface;
    engine->width = w;
    engine->height = h;
    engine->state.angle = 0;

    // Initialize GL state.
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
    glEnable(GL_CULL_FACE);
    glShadeModel(GL_SMOOTH);
    glDisable(GL_DEPTH_TEST);

    uint nFrameBufferID = 0;
    glGenFramebuffers(1, &nFrameBufferID);

    return 0;
}

0 个答案:

没有答案