0
votes

So here is my code:

void Game::init()
{
    SDL_Init(SDL_INIT_EVERYTHING);

    _window = SDL_CreateWindow("Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _screenWidth, _screenHeight, SDL_WINDOW_OPENGL);
}

This isn't working for some reason, but it works fine when I replace SDL_WINDOW_OPENGL with something like SDL_WINDOW_RESIZABLE or SDL_WINDOW_FULLSCREEN. It also doesn't work when I use SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN. Anything I can do?

I'm using Kdevelop with Ubuntu, if that makes any difference.

Update:

So I figured out what was wrong. It turns out that when you build SDL with both GLX and EGL support, it always uses EGL. I had to compile it with --disable-video-opengles

2
What does SDL_GetError() say? - Tristan Brindle
@TristanBrindle it says "No OpenGL support in video driver"... That's weird since I know my driver supports it. - Kash
well, that gives you your answer as to why it's not working... I'd check the installation of your video drivers, or the compilation flags of your SDL library - Tristan Brindle
@TristanBrindle alright, thanks! - Kash

2 Answers

2
votes

Yes, you most likely do support OpenGL, but which version? On Ubuntu, you can get this information by opening the terminal and typing glxinfo | grep OpenGL, which should give you the highest supported version. After that, you need to set those attributes in SDL. For example, to create an OpenGL 3.3 context:

SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

Make sure you do this before creating the context or the window.

0
votes

Do you have dual graphics setup like e.g. Nvidia Optimus? Maybe the reason why program cannot start propertly is that your driver dosen't switch from integrated Intel GPU to dedicated AMD or NVidia GPU.

I met with this issue at least once in my friend's laptop.