问题描述
当我运行此代码时:
#include <iostream>
#include <SDL.h>
#include <stdexcept>
#include <GL/gl3w.h>
int main() try {
if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER ) != 0 )
throw std::runtime_error{ "Could not initialize sdl" };
SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS,0 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK,SDL_GL_CONTEXT_PROFILE_CORE );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION,3 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MInor_VERSION,0 );
// Create window with graphics context
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER,1 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE,24 );
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE,8 );
auto window_flags = (SDL_WindowFlags) ( SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI );
auto window = SDL_CreateWindow( "window",SDL_WINDOWPOS_CENTERED,1280,720,window_flags );
auto gl_context = SDL_GL_CreateContext( window );
SDL_GL_MakeCurrent( window,gl_context );
SDL_GL_SetSwapInterval( 1 ); // Enable vsync
if ( gl3wInit() != 0 )
throw std::runtime_error{ "Unable to initialize OpenGL loader" };
auto renderer = SDL_CreateRenderer( window,-1,0 );
return 0;
}
catch ( std::exception& e ) {
std::cerr << e.what() << "\n";
return -1;
}
它产生以下输出:
X Error of Failed request: GLXBadDrawable
Major opcode of Failed request: 151 (GLX)
Minor opcode of Failed request: 5 (X_GLXMakeCurrent)
Serial number of Failed request: 259
Current serial number in output stream: 259
Process finished with exit code 1
当我注释掉设置opengl版本的行时,它运行正常。
是什么原因导致此错误?为何SDL_CreateRenderer
终止而不返回空指针?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)