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