glGenFramebuffers() access violation when using GLFW + GLEW

╄→гoц情女王★ 提交于 2021-02-19 03:39:07

问题


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 );

    ...
}

回答1:


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.




回答2:


I just stumbled over the same problem. Solution: instad of using glGenFramebuffers use "glGenFramebuffersEXT" and on any other function that has someting todo with the framebuffer always put "EXT" at the end of it and it should work. The problem is here, that there exist two version of the extension the ARB version and the EXT version and if you don't write "EXT" you use the "ARB" version which allmost does the same but is part of the core profile of newer gl versions. So to be compatible, allways use the "EXT" versions of the functions :-)



来源:https://stackoverflow.com/questions/15165863/glgenframebuffers-access-violation-when-using-glfw-glew

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!