Err, lacking the ability to attach e-mails from the web interface, here is just
a blob of C-source:
add to src/video/x11/SDL_x11gl.c:
[source]
#ifndef GLX_CONTEXT_MAJOR_VERSION_ARB
#define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
#endif
#ifndef GLX_CONTEXT_MINOR_VERSION_ARB
#define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
#endif
typedef GLXContext (glXCreateContextAttribsARBProc)(Display, GLXFBConfig,
GLXContext, Bool, const int*);
void X11_GL_MakeGL30_Context(_THIS)
{
glXCreateContextAttribsARBProc glXCreateContextAttribsARB=NULL;
GLXContext null_context=NULL;
int glx_attribs[128];
int c=0;
GLXFBConfig *fbc;
int fbcount;
static int context_attribs[] =
{
GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
GLX_CONTEXT_MINOR_VERSION_ARB, 0,
None
};
//use gl_config to pack the necessary data:
glx_attribs[c++] = GLX_RED_SIZE;
glx_attribs[c++] = this->gl_config.red_size;
glx_attribs[c++] = GLX_GREEN_SIZE;
glx_attribs[c++] = this->gl_config.green_size;
glx_attribs[c++] = GLX_BLUE_SIZE;
glx_attribs[c++] = this->gl_config.blue_size;
if( this->gl_config.alpha_size )
{
glx_attribs[c++] = GLX_ALPHA_SIZE;
glx_attribs[c++] = this->gl_config.alpha_size;
}
glx_attribs[c++] = GLX_DEPTH_SIZE;
glx_attribs[c++] = this->gl_config.depth_size;
if( this->gl_config.stencil_size )
{
glx_attribs[c++] = GLX_STENCIL_SIZE;
glx_attribs[c++] = this->gl_config.stencil_size;
}
if( this->gl_config.double_buffer )
{
glx_attribs[c++] = GLX_DOUBLEBUFFER;
glx_attribs[c++] = True;
}
if( this->gl_config.accum_red_size )
{
glx_attribs[c++] = GLX_ACCUM_RED_SIZE;
glx_attribs[c++] = this->gl_config.accum_red_size;
}
if( this->gl_config.accum_green_size )
{
glx_attribs[c++] = GLX_ACCUM_GREEN_SIZE;
glx_attribs[c++] = this->gl_config.accum_green_size;
}
if( this->gl_config.accum_blue_size )
{
glx_attribs[c++] = GLX_ACCUM_BLUE_SIZE;
glx_attribs[c++] = this->gl_config.accum_blue_size;
}
if( this->gl_config.accum_alpha_size )
{
glx_attribs[c++] = GLX_ACCUM_ALPHA_SIZE;
glx_attribs[c++] = this->gl_config.accum_alpha_size;
}
//signals end of preferences to glXChooseFBConfig
glx_attribs[c++]=None;
//printf("\nGetting FBConfigs…"); fflush(stdout);
fbc=glXChooseFBConfig(SDL_Display, DefaultScreen(SDL_Display), glx_attribs,
&fbcount);
if(fbc==NULL)
{
//printf(“Done\nNo good FBC’s available, GL3.0 will not be possible\n”);
fflush(stdout);
return;
}
//printf(“Done\nGetting proc address…”); fflush(stdout);
glXCreateContextAttribsARB=this->gl_data->glXGetProcAddress((const
GLubyte*)“glXCreateContextAttribsARB”);
if(glXCreateContextAttribsARB==NULL)
{
//printf(“Done\nFunction pointer NULL, GL3.0 will not be possible\n”);
fflush(stdout);
return;
}
//printf(“Done.\nMaking empty context current…”); fflush(stdout);
glXMakeCurrent(GFX_Display, 0, 0);
//printf(“Done.\nDeleting old context…”); fflush(stdout);
glXDestroyContext(GFX_Display, glx_context);
//printf(“Done.\nCreating 3.0 context…”); fflush(stdout);
glx_context=glXCreateContextAttribsARB(GFX_Display, fbc[0], null_context,
True, context_attribs);
//printf(“Done.\nmaking new context current\n”); fflush(stdout);
X11_GL_MakeCurrent(this);
}
[/source]
then, this is the ickier part add to src/video/x11/SDL_x11video.c,
two bits:
at the top (better place would be in a header file I suppose)
[source]
void X11_GL_MakeGL30_Context(_THIS);
[/source]
and at the end of X11_CreateWindow(), just before return (0),
at line 1098,
[source]
if ( flags & SDL_OPENGL ) {
X11_GL_MakeGL30_Context(this);
}
[/source]
I plan on ploughing through the Windows bit to get a GL3.0 context in windows as
well;
Comments:
-
as far as I know, even under X, one needs a GL context to just make a 3.0
context because one needs to get the function pointer for
glXCreateContextAttribsARB, the above mess, just lets SDL-1.2.13 do its usual
thing in making a GL context and then tries to make a 3.0 context afterwards; in
truth it should make the context first, and if successful then delete the old
one, the last bit of shine I leave for later, as of now it deletes the old one
whenever it gets it has a valid fbc and can get the function pointer.
-
TODO: check my X code; in truth I am not familiar at all with X programming,
so if I made some X mistakes someone please post their fixes.
-
TODO: add 3.0GL context creation to Windows target.
-
TODO: add an interface to specify the context properties, right now it just
does GL3.0 always… there are quite a few extras that
glXCreateContextAttribsARB supports that should be added, the wgl analogue has
similar extras too.
-
TODO: add to SDL-1.3 as well (I am not using SDL1.3 right now as it is not
stable and currently is not quite source compatible with SDL1.2)