Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDL2 Can't create window since it couldn't find matching GLX visual

I have a problem as i am currently running Ubuntu Terminal on Windows 10. I also have XMing installed as my X-server(I use XMing for qemu,etc...). And i am trying to run this SDL2 Program. So i have this for main.cpp:

#include <stdio.h> 
#include <stdlib.h> 
#include <unistd.h> 

#include <SDL2/SDL.h> 
#include <GL/gl.h> 

int main(int argc, char *argv[]) 
{ 
        int final_status = 1; 
        SDL_Window *window; 
        SDL_GLContext openGL_context; 

        if (SDL_Init(SDL_INIT_VIDEO)) { 
                fprintf(stderr, "Unable to initialize SDL: %s\n", 
                        SDL_GetError()); 
                return 1; 
        } 
        window = SDL_CreateWindow("My Demo", SDL_WINDOWPOS_CENTERED, 
                                  SDL_WINDOWPOS_CENTERED, 640, 480, 
                                  SDL_WINDOW_OPENGL); 
        if (!window) { 
                fprintf(stderr, "Can't create window: %s\n", SDL_GetError()); 
                goto finished; 
        } 

        openGL_context = SDL_GL_CreateContext(window); 
        if (!openGL_context) { 
                fprintf(stderr, "Can't create openGL context: %s\n", 
                        SDL_GetError()); 
                goto close_window; 
        } 

        /* drawing code removed */ 

        final_status = 0; 
        SDL_GL_DeleteContext(openGL_context); 
close_window: 
        SDL_DestroyWindow(window); 
finished: 
        SDL_Quit(); 
        fprintf(stdout, "done\n"); 
        fflush(stdout); 
        return final_status; 
}  

And then when i run g++ main.cpp -lSDL2 , i get this output:

Can't create window: Couldn't find matching GLX visual
done

I have tried to search how to solve this GLX Problem but can't seem to find a solution for it. Help would be greatly appreciated!

like image 801
amanuel2 Avatar asked Dec 27 '16 03:12

amanuel2


1 Answers

Ensure that GLX is installed correctly by running glxinfo. At the bottom, you'll find the list of supported visuals. Here's mine:

1 GLX Visuals
    visual  x   bf lv rg d st  colorbuffer  sr ax dp st accumbuffer  ms  cav
  id dep cl sp  sz l  ci b ro  r  g  b  a F gb bf th cl  r  g  b  a ns b eat
----------------------------------------------------------------------------
0x022 24 tc  0  24  0 r  y .   8  8  8  0 .  .  0 16  0  0  0  0  0  0 0 None

Try running the following before running the SDL2 program:

export SDL_VIDEO_X11_VISUALID=

This causes SDL to go down a different code path to find the visual. You can also try hardcoding the visual to the visual id from glxinfo:

export SDL_VIDEO_X11_VISUALID=0x022
like image 107
kill -1 Avatar answered Sep 28 '22 07:09

kill -1