安卓opengl ndk-未实现的opengl ES API错误



我正在使用NDK为android编写一个纯c++应用程序。我正在尝试写一个简单的应用程序,用OpenGL进行2D绘图,所以没有纹理或类似的东西。

我应用了这里发布的所有建议,现在仍在获得

调用未实现的OpenGL ES API

logcat 中的消息

这是我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<!-- BEGIN_INCLUDE(manifest) -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.native_activity"
        android:versionCode="1"
        android:versionName="1.0">
    <uses-feature android:glEsVersion="0x00020000"></uses-feature>
    <!-- This is the platform API where NativeActivity was introduced. -->
    <uses-sdk android:minSdkVersion="9" />
    <!-- This .apk has no Java code itself, so set hasCode to false. -->
    <application android:label="@string/app_name" android:hasCode="false">
        <!-- Our activity is the built-in NativeActivity framework class.
             This will take care of integrating with our NDK code. -->
        <activity android:name="android.app.NativeActivity"
                android:label="@string/app_name"
                android:configChanges="orientation|keyboardHidden">
            <!-- Tell NativeActivity the name of or .so -->
            <meta-data android:name="android.app.lib_name"
                    android:value="native-activity" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest> 

这是代码:

EGLDisplay dpy;
EGLSurface surface;
EGLContext context;
static void android_handle_cmd( struct android_app * app, int32_t cmd ) {
    switch (cmd) {
        case APP_CMD_INIT_WINDOW:
            // The window is being shown, get it ready.
            if ( NULL != app->window ) {
                Init( app );
                drawscreen();
            }
            break;
    }
}

void pixel( int x, int y ) {
    if ( NULL == GLapp.surface ) {
        return;
    }    
    glColor4f( 1.0, 1.0, 1.0, 0 );
    glVertexAttrib2f( 0, x + 0.5, y + 0.5 );
}

void drawscreen( void ) {
    if ( NULL == GLapp.surface ) {
        return;
    }
    eglSwapBuffers( GLapp.dpy, GLapp.surface );
}

int Init( struct android_app * app ) {
    dpy = eglGetDisplay( EGL_DEFAULT_DISPLAY );
    eglInitialize( dpy, 0, 0 );
    const EGLint attribs[] = {
        EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, // <--- OpenGL ES 2.0
        EGL_BLUE_SIZE,       8,
        EGL_GREEN_SIZE,      8,
        EGL_RED_SIZE,        8,
        EGL_NONE
    };
    EGLConfig config;
    EGLint numConfigs;
    eglChooseConfig( dpy, attribs, &config, 1, &numConfigs );
    EGLint format;
    eglGetConfigAttrib( dpy, config, EGL_NATIVE_VISUAL_ID, &format );
    ANativeWindow_setBuffersGeometry( app->window, 0, 0, format );
    surface = eglCreateWindowSurface( dpy, config, app->window, NULL );
    const EGLint ContextAttribList[] = {
        EGL_CONTEXT_CLIENT_VERSION, 2,
        EGL_NONE
    };
    context = eglCreateContext( GLapp.dpy, config, EGL_NO_CONTEXT, ContextAttribList );
    eglMakeCurrent( dpy, surface, surface, context );
    int XSize;
    eglQuerySurface( GLapp.dpy, GLapp.surface, EGL_WIDTH, &XSize );
    int YSize;
    eglQuerySurface( GLapp.dpy, GLapp.surface, EGL_HEIGHT, &YSize );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrthof( 0, XSize, YSize, 0, 0, 1 );
    glMatrixMode( GL_MODELVIEW );
    /* Displacement trick for exact pixelization */
    glTranslatef( 0.375, 0.375, 0 );
    glDisable( GL_DEPTH_TEST );
    glClear( GL_COLOR_BUFFER_BIT );
    return 0;
}

我删除了所有的错误检查代码,使代码更易于阅读。Init函数在没有检测到任何错误的情况下执行,只有当我调用像素或drawscreen(不确定是哪个)函数时,日志才会填充"未实现的OpenGL ES API"错误

有人能帮忙吗?

您的应用程序缺少包含,我们甚至不知道构建阶段可能出现的错误。

我的建议是查看NDK文件夹中的几个示例并从中学习。

考虑到OpenGL ES代码的本地活动,您至少应该包括:

#include <jni.h>
#include <errno.h>
#include <EGL/egl.h>
#include <GLES/gl.h>
#include <android/log.h>
#include <android_native_app_glue.h>

但这只是给你一个想法,你可能想要更多。

您要的是gles 2,但您使用的是不是gles2 api的glMatrixMode之类的东西-不包括gl.h,而是使用gles2.h-其中包含您要的api。

最新更新