简体   繁体   中英

android opengl ndk - unimplemented OpenGL ES API error

I am writing a pure c++ application for android using the NDK. I am trying to write a simple app that does 2D drawing with OpenGL, so no textures or anything like that.

I applied all the recommendations posted here and am still getting the

called unimplemented OpenGL ES API

messages in logcat

Here's my manifest file:

<?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> 

And here's the code:

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;

}

I removed all the error checking code to make the code easier to read. The Init function executes without there being any errors detected, it's only when I call the pixel or drawscreen (not sure which) function that the log fills up with the 'unimplemented OpenGL ES API' error

Can anyone help?

Your application is lacking of inclusions and we don't even know about possible errors during the building phase.

My suggestion is to look at the several samples in the NDK folder and learn from them.

Considering a native activity with OpenGL ES code you should at least include:

#include <jni.h>
#include <errno.h>

#include <EGL/egl.h>
#include <GLES/gl.h>

#include <android/log.h>
#include <android_native_app_glue.h>

but this is just to give you an idea, you probably want more than that.

您要的是gles 2,但您使用的是glMatrixMode之类的东西,而不是gles2 api-不包括gl.h,请改用gles2.h-里面有您要的api。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM