简体   繁体   English

SDL无法创建OpenGL窗口

[英]SDL can't create OpenGL windows

So here is my code: 所以这是我的代码:

void Game::init()
{
    SDL_Init(SDL_INIT_EVERYTHING);

    _window = SDL_CreateWindow("Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _screenWidth, _screenHeight, SDL_WINDOW_OPENGL);
}

This isn't working for some reason, but it works fine when I replace SDL_WINDOW_OPENGL with something like SDL_WINDOW_RESIZABLE or SDL_WINDOW_FULLSCREEN . 由于某些原因,这无法正常工作,但是当我将SDL_WINDOW_OPENGL替换为SDL_WINDOW_RESIZABLESDL_WINDOW_FULLSCREEN时,它可以正常工作。 It also doesn't work when I use SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN 当我使用SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN时,它也不起作用SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN . SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN Anything I can do? 我能做什么?

I'm using Kdevelop with Ubuntu, if that makes any difference. 我在Ubuntu上使用Kdevelop,如果有什么区别的话。

Update: 更新:

So I figured out what was wrong. 因此,我找出了问题所在。 It turns out that when you build SDL with both GLX and EGL support, it always uses EGL. 事实证明,在同时支持GLX和EGL的情况下构建SDL时,它始终使用EGL。 I had to compile it with --disable-video-opengles 我不得不用--disable-video-opengles进行编译

Yes, you most likely do support OpenGL, but which version? 是的,您最有可能支持OpenGL,但是哪个版本? On Ubuntu, you can get this information by opening the terminal and typing glxinfo | grep OpenGL 在Ubuntu上,您可以通过打开终端并键入glxinfo | grep OpenGL获取信息glxinfo | grep OpenGL glxinfo | grep OpenGL , which should give you the highest supported version. glxinfo | grep OpenGL ,应该为您提供最高支持的版本。 After that, you need to set those attributes in SDL. 之后,您需要在SDL中设置这些属性。 For example, to create an OpenGL 3.3 context: 例如,创建OpenGL 3.3上下文:

SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

Make sure you do this before creating the context or the window. 确保在创建上下文或窗口之前执行此操作。

Do you have dual graphics setup like eg Nvidia Optimus? 您是否有双显卡设置,例如Nvidia Optimus? Maybe the reason why program cannot start propertly is that your driver dosen't switch from integrated Intel GPU to dedicated AMD or NVidia GPU. 程序无法正确启动的原因可能是驱动程序没有从集成的Intel GPU切换到专用的AMD或NVidia GPU。

I met with this issue at least once in my friend's laptop. 我在朋友的笔记本电脑中至少遇到过一次此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM