OpenGL 3.x context creation

I’ve been working on an SDL2/OpenGL project in the D programming
language and I’m having a really nasty time trying to get an
accelerated OpenGL 3.x context. I’m using the following code:

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

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);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depthBufferSize);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencilBufferSize);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

window = SDL_CreateWindow(null, SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
width, height, SDL_WINDOW_OPENGL);

if(!window)
throw new Error("Unable to create SDL window: " ~
to!string(SDL_GetError()));

context = SDL_GL_CreateContext(window);
if(!context) {
throw new Error(“Unable to create OpenGL context”);
}
writeln(to!string(glGetString(GL_VERSION)));
writeln(to!string(glGetString(GL_VENDOR)));
writeln(to!string(SDL_GetError()));

The output I get says that I’m getting Microsoft’s OpenGL 1.1 driver
instead of a more modern one; I’ve updated my
drivers and tested on other machines, so I don’t think the issue is my
machine’s configuration. SDL_GetError()
returns a message about being unable to load RegisterTouchWindow, but
from what I understand, this is just a
common Windows XP issue that only affects multi-touch input code. I
don’t think it’s an issue with the language or
bindings, either, because others have gotten it to work just fine with
similar setups.
Can anyone see anything wrong with my code?

I think your setup code needs to be after you create the window, but before
you make the context.

-AlexOn Tue, May 29, 2012 at 3:19 AM, Ben Merritt wrote:

I’ve been working on an SDL2/OpenGL project in the D programming
language and I’m having a really nasty time trying to get an
accelerated OpenGL 3.x context. I’m using the following code:

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

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);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depthBufferSize);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, stencilBufferSize);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

window = SDL_CreateWindow(null, SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
width, height, SDL_WINDOW_OPENGL);

if(!window)
throw new Error("Unable to create SDL window: " ~
to!string(SDL_GetError()));

context = SDL_GL_CreateContext(window);
if(!context) {
throw new Error(“Unable to create OpenGL context”);
}
writeln(to!string(glGetString(GL_VERSION)));
writeln(to!string(glGetString(GL_VENDOR)));
writeln(to!string(SDL_GetError()));

The output I get says that I’m getting Microsoft’s OpenGL 1.1 driver
instead of a more modern one; I’ve updated my
drivers and tested on other machines, so I don’t think the issue is my
machine’s configuration. SDL_GetError()
returns a message about being unable to load RegisterTouchWindow, but
from what I understand, this is just a
common Windows XP issue that only affects multi-touch input code. I
don’t think it’s an issue with the language or
bindings, either, because others have gotten it to work just fine with
similar setups.
Can anyone see anything wrong with my code?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I’ve tried swapping the order; it doesn’t seem to affect it. I’m at a
bit of a loss as to what might be keeping this from working…
BTW, SDL_GetError() actually returns “GL 3.x is not supported;” when I
wrote the original post, I must have been thinking of
the last issue I had. Maybe SDL just doesn’t like my drivers… (I’m
using an NVIDIA GeForce 9400 GT with the latest drivers.)

I’ve done a bit of research, and some people who have been getting this error had a problem with how they had compiled the SDL2 DLL. I’m not sure if that’s the issue here, though, because I’ve tried several different builds from different sources. Might this be the issue, or is it a bug in my code (or maybe SDL2?)
I’ve also tried on other machines without any luck, so I’m starting to doubt that my drivers are causing the issue.

Just as a sanity check, how are you compiling/what are you linking against?
-AlexOn Thu, May 31, 2012 at 12:07 AM, Ben Merritt wrote:

I’ve done a bit of research, and some people who have been getting this
error had a problem with how they had compiled the SDL2 DLL. I’m not sure
if that’s the issue here, though, because I’ve tried several different
builds from different sources. Might this be the issue, or is it a bug in
my code (or maybe SDL2?)
I’ve also tried on other machines without any luck, so I’m starting to
doubt that my drivers are causing the issue.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Since I’m using D instead of C(++), I’m using a set of bindings that loads SDL and OpenGL symbols from their respective DLLs. I’m compiling it with D’s rdmd utility, which automatically compiles all the dependencies. Other than my code, the bindings, and the standard library, there’s nothing statically linked into my application.On May 30, 2012, at 9:46 PM, Alex Barry <alex.barry at gmail.com> wrote:

Just as a sanity check, how are you compiling/what are you linking against?
-Alex

In case it helps, the procedure for loading the bindings is as follows:

Load the basic (version-independent) OpenGL symbols.

Set up the SDL window and GL context. (I think that SDL loads its own GL symbols, so Step #1 is probably not relevant to this step’s success.)

Use the new context to load version-specific symbols.

Step #2 is the one that appears to fail.