[英]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...). 我有一个问题,因为我目前正在Windows 10上运行Ubuntu终端。我还安装了XMing作为我的X服务器(我使用XMing作为qemu等等)。 And i am trying to run this SDL2 Program.
我正在尝试运行这个SDL2计划。 So i have this for main.cpp:
所以我对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: 然后当我运行
g++ main.cpp -lSDL2
,我得到这个输出:
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. 我试图搜索如何解决这个GLX问题,但似乎无法找到它的解决方案。 Help would be greatly appreciated!
非常感谢帮助!
Ensure that GLX is installed correctly by running glxinfo
. 通过运行
glxinfo
确保正确安装了GLX。 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: 在运行SDL2程序之前尝试运行以下命令:
export SDL_VIDEO_X11_VISUALID=
This causes SDL to go down a different code path to find the visual. 这会导致SDL沿着不同的代码路径向下查找视觉。 You can also try hardcoding the visual to the visual id from
glxinfo
: 您还可以尝试将视觉硬编码到
glxinfo
的视觉ID:
export SDL_VIDEO_X11_VISUALID=0x022
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.