4

I have compiled my SDL game on the PI. I used apt to install the SDL 1.2 dev package. When I call SDL_SetVideoMode, it fails and this is the SDL error string.

couldn't find matching glx visual

What I have tried so far was changing my bits per pixel parameter from 32 down to 24 and 16 with no change. I have also googled similar problems but it's getting me nowhere. I would like to understand this from first principles. It is the last function call that fails and returns null.

if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
  return false;

const SDL_VideoInfo *videoInfo = SDL_GetVideoInfo();
if (!videoInfo) {
  fprintf(stderr, "Video query failed: %s\n",
     SDL_GetError());
  return false;
}

/* the flags to pass to SDL_SetVideoMode */
videoFlags = SDL_OPENGL;       /* Enable OpenGL in SDL */
videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
videoFlags |= SDL_HWPALETTE;       /* Store the palette in hardware */

/* This checks to see if surfaces can be stored in memory */
if (videoInfo->hw_available)
  videoFlags |= SDL_HWSURFACE;
else
  videoFlags |= SDL_SWSURFACE;

widthViewport = videoInfo->current_w;
heightViewport = videoInfo->current_h;
videoFlags |= SDL_FULLSCREEN;

/* This checks if hardware blits can be done */
if (videoInfo->blit_hw)
  videoFlags |= SDL_HWACCEL;

/* Sets up OpenGL double buffering */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

/* get a SDL surface */
TRACE("SDL_SetVideoMode\n");
surface = SDL_SetVideoMode(widthViewport, heightViewport, 
  32, videoFlags);

/* Verify there is a surface */

if (!surface) {
  fprintf(stderr, "Video mode set failed: %s\n", SDL_GetError());
  return false;
}
  • 1
    It could help if you post you SDL setup function here. In general, the error you got means that it is not possible to initialize OpenGL (via GLX) subsystem with requested parameters. Since we don't know them, we can't tell you which settings may cause problems in your situation. Please note, however, that RaspberryPi currently does not provide hardware accelerated GLX subsystem so if you use it, even if it works, things will be very slow. – Krzysztof Adamski Oct 22 '12 at 8:46
  • The code is there now. Is there an alternative to my using running this within X Windows? – ScrollerBlaster Oct 22 '12 at 10:41
  • 1
    You should now try to remove all the flags you are trying to request using videoFlags variable and see if it's working this way. Especially, SDL_HWSURFACE seems to be set regardless of if it's supported or not, even thought you check for it. Do you use OpenGL directly or anything that needs it? – Krzysztof Adamski Oct 22 '12 at 10:52
  • I only set SDL_HWSURFACE if it's available. The machine is at home so I can't progress for now. – ScrollerBlaster Oct 22 '12 at 10:58
  • 1
    Oh, you're right, it's SWSURFACE otherwise. – Krzysztof Adamski Oct 22 '12 at 11:27
4

I had the same problem in this question. To fix it:

sudo apt-get install libgl1-mesa-swx11

Be warned though, GLX is not hardware accelerated as of answering this question, so things will probably run very slow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.