I've been trying to use OpenGL 4 and the first obstacle was actually loading GL4 instead of the disgusting software-only GL 1.1 that comes with MS Windows. I tried using GLEW and then updated my drivers a second time, and still GL continued putting the version as 1.1.0
. It turns out that it was not a problem with GLEW (nor did it even require GLEW, it seems), nor was it SDL breaking something internally (which I considered since that is what I use to create the context). Andon M. Coleman brought up the issue of pixel format, which is something I had totally overlooked to begin with. It turns out that I'd been using 8 bits for each of red, green, blue, and alpha, plus 32 bits for depth. I thought that was a nice even 64 bits, with 32 for the color and 32 for the distance. However, since SDL assumes you want a stencil buffer too (which I realize now is actually needed), it was actually making the pixel format 72 bits, which is not allowed for an accelerated context, since GPUs typically handle 64 bits at most. So, it was defaulting to the ancient GL 1.1 support provided by Windows for use in the absence of drivers, also making it software-only.
The code has a lot of other stuff in it, so I have put together a basic sample of what I was trying to do. It is valid C++ and compiles on MinGW, assuming you link it properly.
#include <gl\gl.h>
#include <SDL2\SDL.h>
#include <stdio.h>
#define SDL_main main
int main ()
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,8);
/// What I *was* doing...
/* SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,32); */
// And then I didn't even set SDL_STENCIL_SIZE at all.
// Results in the entire size for each pixel being more than 64.
/// What I *am* doing...
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,8);
// Nice even 32 bits for this and 32 bits for the color is 64.
SDL_Window* window = SDL_CreateWindow(
"Hay GPU y is u no taek pixelz ovar 64 bitz?",
SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,
1024,768,
SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL
);
SDL_GLContext context = SDL_GL_CreateContext(window);
printf("GL Version [%s]\n",glGetString(GL_VERSION));
SDL_DestroyWindow(window);
SDL_GL_DeleteContext(context);
SDL_Quit();
return 0;
};
Hopefully other people who have been having a similar issue can learn from my mistake, or at least be able to mark it off a list of possible problems.