0
\$\begingroup\$

I am currently working on a C++ + SDL2 game engine and I am stuck on a problem. The problem is that whenever I pass SDL_WINDOW_OPENGL to SDL_CreateWindow(), it return null and so my program stops. But it works fine if I pass any other flag while not passing SDL_WINDOW_OPENGL. This is the function I am calling SDL_CreateWindow():

Game::Game(const char* title, int w, int h, int x, int y, int glmajversion, int glminversion, Uint32 flags){
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
        std::cout<<"[Error]: Unable to initialize SDL2."<<std::endl;
    }

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, glminversion);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, glmajversion);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
    window = SDL_CreateWindow(title, x, y, w, h, flags);
    if (!window){
        std::cout<<"[Error]: Unable to create SDL2 window."<<std::endl;
        exit(-1);
    }
    context = SDL_GL_CreateContext(window);
    SDL_GL_MakeCurrent(window, context);
}

If I call SDL_GetError() before exiting, it returns "Couldn't find matching GLX visual".

| improve this question | | | | |
\$\endgroup\$
1
\$\begingroup\$

It was my mistake. I set the depth buffer to 32 bit which my computer doesn't have a visual for. Changing depth buffer to 24 bit fixed the error.

| improve this answer | | | | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.