fb-based OpenGL ES2.0 application for i.MX6 crashing on glClear() call

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fb-based OpenGL ES2.0 application for i.MX6 crashing on glClear() call

Jump to solution
1,219 Views
scottvanderweid
Contributor II

I am attempting to write an fb-based OpenGL ES2.0 application for i.MX6 (specifically the BD Nitrogen6x). No matter what I try the application always crashes on the first glClear() call. I know this probably means the GL Context isn't current, but I don't know, beyond what I've already done, to make it current. Here is my sample application:

#include <GLES2/gl2.h>

#include <GLES2/gl2ext.h>

#include <EGL/egl.h>

#include <EGL/eglvivante.h>

#include <stdio.h>

#include <assert.h>

#include <stdlib.h>

#include <cstring>

#include <unistd.h>

//Configure window size here

#define WIDTH 1920

#define HEIGHT 1080

NativeDisplayType display;

NativeWindowType window;

EGLDisplay _eglDisplay;

EGLSurface _eglSurface;

EGLContext _eglContext;

EGLint numConfigs = 0;

EGLConfig eglConfig;

void init_egl()

{

    // setup attribs

    static const EGLint configAttribs[] =

    {

        EGL_SAMPLES,         0,

        EGL_RED_SIZE,        8,

        EGL_GREEN_SIZE,      8,

        EGL_BLUE_SIZE,       8,

        EGL_ALPHA_SIZE,      0,

        EGL_DEPTH_SIZE,      24,

        EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,

        EGL_NONE

    };

    // create a context

    EGLint contextAttribs[] =

    {

        EGL_CONTEXT_CLIENT_VERSION, 2,

        EGL_NONE

    };

    display = fbGetDisplayByIndex( 0 );

    assert( display );

    _eglDisplay = eglGetDisplay( display );

    assert( EGL_SUCCESS == eglGetError() );

    assert( 0 != _eglDisplay );

    eglInitialize( _eglDisplay, NULL, NULL );

    assert( EGL_SUCCESS == eglGetError() );

    eglBindAPI(EGL_OPENGL_ES_API);

    eglChooseConfig( _eglDisplay, configAttribs, &eglConfig, 1, &numConfigs );

    assert( EGL_SUCCESS == eglGetError() );

    assert( 1 == numConfigs );

    window = fbCreateWindow( display, 0, 0, WIDTH, HEIGHT );

    assert( window );

    _eglSurface = eglCreateWindowSurface( _eglDisplay, eglConfig, window, configAttribs );

    assert( EGL_SUCCESS == eglGetError() );

    _eglContext = eglCreateContext( _eglDisplay, eglConfig, NULL, contextAttribs );

    assert( EGL_SUCCESS == eglGetError() );

    eglMakeCurrent( _eglDisplay, _eglSurface, _eglSurface, _eglContext );

    assert( EGL_SUCCESS == eglGetError() );

    eglSwapInterval( _eglDisplay, 1 );

}

int main(int argc,char *argv[])

{

    init_egl();

    int ret = 0;

    while( running && ret != -1 )

    {

        glViewport( 0, 0, WIDTH, HEIGHT );

        glClearColor( 1.0, 1.0, 0.0, 1.0 );

        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

        eglSwapBuffers( _eglDisplay, _eglSurface );

    }

    return 0;

}

Any help is very much appreciated.

Labels (4)
1 Solution
733 Views
scottvanderweid
Contributor II

I finally got the follow EGL initialization code to work. I hope this helps others...

EGLNativeDisplayType m_hDisplayType = fbGetDisplayByIndex( 0 ); // between 0 and 3

static const EGLint m_finalConfigAttribs[] =
{
EGL_SAMPLES, 0,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8, // buffers with the smallest alpha component size are preferred
EGL_DEPTH_SIZE, 24,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};

m_hDisplay = eglGetDisplay( m_hDisplayType );
eglInitialize( m_hDisplay, nullptr, nullptr );
eglBindAPI( EGL_OPENGL_ES_API );

EGLint numConfigs;
EGLConfig m_hConfig;
eglChooseConfig( m_hDisplay, &m_finalConfigAttribs[0], &m_hConfig, 1, &numConfigs );


EGLNativeWindowType m_hWindow = fbCreateWindow( m_hDisplayType, 0, 0, WIDTH, HEIGHT );

EGLint contextAttribListES[] =
{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};

m_hSurface = eglCreateWindowSurface( m_hDisplay, m_hConfig, m_hWindow, nullptr );

EGLContext m_hContext = eglCreateContext( m_hDisplay, m_hConfig, EGL_NO_CONTEXT, contextAttribListES );

eglMakeCurrent( m_hDisplay, m_hSurface, m_hSurface, m_hContext );

View solution in original post

1 Reply
734 Views
scottvanderweid
Contributor II

I finally got the follow EGL initialization code to work. I hope this helps others...

EGLNativeDisplayType m_hDisplayType = fbGetDisplayByIndex( 0 ); // between 0 and 3

static const EGLint m_finalConfigAttribs[] =
{
EGL_SAMPLES, 0,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8, // buffers with the smallest alpha component size are preferred
EGL_DEPTH_SIZE, 24,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};

m_hDisplay = eglGetDisplay( m_hDisplayType );
eglInitialize( m_hDisplay, nullptr, nullptr );
eglBindAPI( EGL_OPENGL_ES_API );

EGLint numConfigs;
EGLConfig m_hConfig;
eglChooseConfig( m_hDisplay, &m_finalConfigAttribs[0], &m_hConfig, 1, &numConfigs );


EGLNativeWindowType m_hWindow = fbCreateWindow( m_hDisplayType, 0, 0, WIDTH, HEIGHT );

EGLint contextAttribListES[] =
{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};

m_hSurface = eglCreateWindowSurface( m_hDisplay, m_hConfig, m_hWindow, nullptr );

EGLContext m_hContext = eglCreateContext( m_hDisplay, m_hConfig, EGL_NO_CONTEXT, contextAttribListES );

eglMakeCurrent( m_hDisplay, m_hSurface, m_hSurface, m_hContext );