Search code examples
openglframebufferglewfboglfw

glGenFramebuffers() access violation when using GLFW + GLEW


I am getting this error:

"Access violation executing location 0x00000000."

when I use GLFW + GLEW on Windows.

I am using Windows 7. I also have my own implementation (from scratch) that that creates a window, initializes OpenGL context, initializes GLEW, etc... and everything works fine. So of course my video card has the Frame Buffer capability and everything is pretty fine with the drivers... the problem only happens when I try to use GLFW.

Any suggestion?

The code:

void start()
{
    if( !glfwInit() )
    {
        glfwTerminate();
        throw exception( "Failed to initialize GLFW" );
    }

    glfwOpenWindowHint( GLFW_FSAA_SAMPLES, 4 );
    glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 );
    glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 3 );
    glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );

    if( !glfwOpenWindow( m_width, m_height, 0, 0, 0, 0, 32, 0, GLFW_WINDOW ) )
    {
        throw exception( "Failed to open GLFW window." );
        glfwTerminate();
    }

    if ( glewInit() != GLEW_OK )
    {
        throw exception( "Failed to initialize GLEW" );
    }

    // texture
    glGenTextures( 1, &m_texture );
    glBindTexture( GL_TEXTURE_2D, m_texture );

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

    // frame buffer
    glGenFramebuffers( 1, &m_frameBuffer ); // IT CRASHES HERE! :-(
    glBindFramebuffer( GL_FRAMEBUFFER, m_frameBuffer );

    glBindTexture( GL_TEXTURE_2D, m_texture );

    ...
}

Solution

  • GLEW has known problems when working with a core OpenGL profile. You can either use the GLEW workaround or abandon GLEW for extension loaders that actually work.