0
votes

I'm trying to get a simple test app going that I've built using the San Angeles demo as a reference. Currently (in my native/cpp code) I'm only calling glViewport on resize, and glClearColor and glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) when rendering a frame. Problems occur when loading the opengl lib dynamically (via dlopen("libGLESv1_CM.so", RTLD_NOW)); dl open is successful and I find the symbols, however the screen stays black even though I've set my clear colour to green. On the other hand, if I don't import the symbols, things seem to work fine.

I've gone through the San Angeles demo a few times now and can't see what I might have missed. Any ideas/advice are much appreciated. My import code is below:

uint32 ImportOpenGL()
{
    uint32 uResult = 0;

    glesLib = dlopen("libGLESv1_CM.so", RTLD_NOW);

    if (!glesLib)
        return 1;

#define GL_IMPORT_FUNC(funcName)                                                    \
    {                                                                               \
        *((void **)&(funcPtr_##funcName)) = (void *)dlsym(glesLib, #funcName);  \
        if(!funcPtr_##funcName)                                                     \
        {                                                                           \
            LOGW("Could not load OpenGL symbol: %s", #funcName);                    \
            uResult = (!uResult ? 2 : uResult);                                     \
        }                                                                           \
    }

    GL_IMPORT_FUNC(glBlendFunc);
    GL_IMPORT_FUNC(glClear);
    GL_IMPORT_FUNC(glClearColorx);
    GL_IMPORT_FUNC(glClearColor);
    GL_IMPORT_FUNC(glColor4x);
    GL_IMPORT_FUNC(glColorPointer);
    GL_IMPORT_FUNC(glDisable);
    GL_IMPORT_FUNC(glDisableClientState);
    GL_IMPORT_FUNC(glDrawArrays);
    GL_IMPORT_FUNC(glEnable);
    GL_IMPORT_FUNC(glEnableClientState);
    GL_IMPORT_FUNC(glFrustumx);
    GL_IMPORT_FUNC(glGetError);
    GL_IMPORT_FUNC(glLightxv);
    GL_IMPORT_FUNC(glLoadIdentity);
    GL_IMPORT_FUNC(glMaterialx);
    GL_IMPORT_FUNC(glMaterialxv);
    GL_IMPORT_FUNC(glMatrixMode);
    GL_IMPORT_FUNC(glMultMatrixx);
    GL_IMPORT_FUNC(glNormalPointer);
    GL_IMPORT_FUNC(glPopMatrix);
    GL_IMPORT_FUNC(glPushMatrix);
    GL_IMPORT_FUNC(glRotatex);
    GL_IMPORT_FUNC(glScalex);
    GL_IMPORT_FUNC(glShadeModel);
    GL_IMPORT_FUNC(glTranslatex);
    GL_IMPORT_FUNC(glVertexPointer);
    GL_IMPORT_FUNC(glViewport);

#undef GL_IMPORT_FUNC

    if(!uResult)
    {
        LOGI("Successfully imported OpenGL symbols");
    }

    return uResult;
}
2

2 Answers

1
votes

Are you sure that you defined the ponters correctly? (i mean the method how the arguments are passed to a function)

For instance, the glEnable is defined this way:

GL_API void GL_APIENTRY glEnable (GLenum cap);

where GL_API is KHRONOS_APICALL:

#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
#   define KHRONOS_APICALL __declspec(dllimport)
#elif defined (__SYMBIAN32__)
#   define KHRONOS_APICALL IMPORT_C
#elif defined(__ANDROID__)
#   define KHRONOS_APICALL __attribute__((visibility("default")))
#else
#   define KHRONOS_APICALL
#endif

and GL_APIENTRY is KHRONOS_APIENTRY:

#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
/* Win32 but not WinCE */
#   define KHRONOS_APIENTRY __stdcall
#else
#   define KHRONOS_APIENTRY
#endif

Thus, you must not add __stdcall to your pointer declarations, i.e. GLES functions uses default __cdecl convention (and not the __fastcall).

0
votes

I haven't tried creating a GLES context from native code myself, I just let Android do that and then go native to do the rendering.

Have you checked that your context is working? Maybe you should to call eglGetError() and/or glGetError() to see if there's anything wrong.