I am using SDL2 for OS interfacing and GLEW for OpenGL function loading. Initially I had my SDL_GL_SetAttribute() calls in-between window creation and context creation. I noticed that my SDL_GL_SetAttribute() calls made little effect, so I re-read the documentation and it states "The requested attributes should be set before creating an OpenGL window". If I try this, I only manage to get an OpenGL 1.1 context (the one Microsoft ships). If I don't call SDL_GL_SetAttribute() at all I get a 4.4 context with no issue.
One strange thing I've noted is my calls to SDL_GL_GetAttribute() after I create the context seem to return inaccurate values. If I don't set any attributes I get:
SDL GL Context Major Version: 2
SDL GL Context Minor Version: 1
SDL GL Context Profile: Unknown
SDL GL Accelerated Visuals: True
SDL GL Double Buffering: True
SDL GL Depth Size: 24
----------------------------------------------------------------
Graphics Successfully Initialized
OpenGL Info
Version: 4.4.0
Vendor: NVIDIA Corporation
Renderer: GeForce GT 650M/PCIe/SSE2
Shading: 4.40 NVIDIA via Cg compiler
----------------------------------------------------------------
If I do set all the attributes I get:
SDL GL Context Major Version: 3
SDL GL Context Minor Version: 1
SDL GL Context Profile: Compatibility
SDL GL Accelerated Visuals: True
SDL GL Double Buffering: True
SDL GL Depth Size: 32
----------------------------------------------------------------
Graphics Successfully Initialized
OpenGL Info
Version: 1.1.0
Vendor: Microsoft Corporation
Renderer: GDI Generic
Shading: (null)
----------------------------------------------------------------
Note how in the first case, SDL says I have a 2.1 context, while I actually get a 4.4. In the second case it says I have a 3.1 context (what I requested), when I actually have a 1.1.
My current setup code (which follows what is outlined in this tutorial). Error checking omitted for brevity.
SDL
SDL_Init(SDL_INIT_VIDEO);
// Request compatibility because GLEW doesn't play well with core contexts.
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
SDL_Window * window = SDL_CreateWindow("Title", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_OPENGL);
SDL_GLContext context = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, context)
// Print what the OS actually gave us for each value we requested.
SDL_GL_GetAttribute(/* ... */);
Directly followed by GLEW
glewExperimental = GL_TRUE;
GLenum result = glewInit();
if(result != GLEW_OK)
{
// Handle & print error
}
if(GLEW_VERSION_1_1)
{
printf("----------------------------------------------------------------\n");
printf("Graphics Successfully Initialized\n");
printf("OpenGL Info\n");
printf(" Version: %s\n", glGetString(GL_VERSION));
printf(" Vendor: %s\n", glGetString(GL_VENDOR));
printf(" Renderer: %s\n", glGetString(GL_RENDERER));
printf(" Shading: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
printf("----------------------------------------------------------------\n");
}
else
{
printf("Unable to get any OpenGL version from GLEW!");
}
if(!GLEW_VERSION_3_1)
{
// Handle & print error
}