Bad OpenGL context handling

Hi,
While developing one application I came across with the following odd
behavior. This simple testcase fails, even I don’t see any reason it should,
except SDL’s incorrect managing of the OpenGL context. Many other functions,
like glBegin etc. do work on the second round of initializing SDL’s video
capabilities again. So, is there something I’m doing wrong or is it just a
bug?

/* begin main.c */
#include <stdio.h>
#include <stdlib.h>
#include “SDL.h”
#include “SDL_opengl.h”

void mess_with_video()
{
if(SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
abort();
if(SDL_GL_LoadLibrary(NULL) == -1)
abort();
const GLubyte*(*func)(GLenum);
if((func = SDL_GL_GetProcAddress(“glGetString”)) == NULL)
abort();
if(func(GL_EXTENSIONS) == NULL)
{
printf(“Failed…\n”);
abort();
}

SDL_QuitSubSystem(SDL_INIT_VIDEO);

}

int main(int argc, char* argv[])
{
if(SDL_Init(0) == -1)
return 1;
mess_with_video();
mess_with_video();
SDL_Quit();
return 0;
}
/* end main.c */

Regards, Joonas.–
Joonas “dolphin” Lahtinen <@Joonas_Lahtinen>

In this test case, you are not setting up a GL context. Without a
context, the functions behaviour is undefined. The fact that glBegin
and glEnd work is not a true test since a context is not needed to tell
a system you are ready to draw.

HTH,
RichardOn Fri, 2006-01-06 at 11:17 +0200, Joonas Lahtinen wrote:

Hi,
While developing one application I came across with the following odd
behavior. This simple testcase fails, even I don’t see any reason it should,
except SDL’s incorrect managing of the OpenGL context. Many other functions,
like glBegin etc. do work on the second round of initializing SDL’s video
capabilities again. So, is there something I’m doing wrong or is it just a
bug?

/* begin main.c */
#include <stdio.h>
#include <stdlib.h>
#include “SDL.h”
#include “SDL_opengl.h”

void mess_with_video()
{
if(SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
abort();
if(SDL_GL_LoadLibrary(NULL) == -1)
abort();
const GLubyte*(*func)(GLenum);
if((func = SDL_GL_GetProcAddress(“glGetString”)) == NULL)
abort();
if(func(GL_EXTENSIONS) == NULL)
{
printf(“Failed…\n”);
abort();
}

SDL_QuitSubSystem(SDL_INIT_VIDEO);
}

int main(int argc, char* argv[])
{
if(SDL_Init(0) == -1)
return 1;
mess_with_video();
mess_with_video();
SDL_Quit();
return 0;
}
/* end main.c */

Regards, Joonas.

if(SDL_GL_LoadLibrary(NULL) == -1)
abort();
const GLubyte*(*func)(GLenum);
if((func = SDL_GL_GetProcAddress(“glGetString”)) == NULL)
abort();

Call SDL_SetVideoMode() after SDL_GL_LoadLibrary() and before
SDL_GL_GetProcAddress().

–ryan.

if(SDL_GL_LoadLibrary(NULL) == -1)
  abort();
const GLubyte*(*func)(GLenum);
if((func = SDL_GL_GetProcAddress("glGetString")) == NULL)
  abort();

Call SDL_SetVideoMode() after SDL_GL_LoadLibrary() and before
SDL_GL_GetProcAddress().

I’m not willing to have any window yet by the time I do this. Obviously this
means I will have to handle the context on my own, right?

Regards, JoonasOn Friday 06 January 2006 15:18, Ryan C. Gordon wrote:

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Joonas “dolphin” Lahtinen <@Joonas_Lahtinen>