Jarann Jarann - 1 month ago 37
C++ Question

Changing OpenGL anti aliasing after SDL window creation?

I've ran into a problem where I want to be able to change anti aliasing while the window is open. SDL2 only allows for anti aliasing (sampling) to be set before the window is created and I was wondering if there's a way to no have to recreate the window every time I change the sample level.

Example:

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); // Before the window
SDL_Window* window = SDL_CreateWindow("title", 0, 0, 960, 540, SDL_WINDOW_OPENGL);

Answer

So after some more testing I found that anti aliasing can be enabled and disabled through a glenable/disable function call. All you have to do is set the AA level compile time but use opengl to choose whether to use it. The only catch is that you can't change the level, but this solution works for my case

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
glDisable(GL_MULTISAMPLE);
// When you want to enable it
glEnable(GL_MULTISAMPLE);