opengl - 创建渲染器时 SDL 终止
问题描述
当我运行此代码时:
#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,
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
终止而不是返回一个空指针?
解决方案
推荐阅读
- jsp - 如何在primefaces数据表中显示字符串数组?
- email - 响应式 3 列 html 电子邮件布局最后一列图像在 gmail 和 Outlook 中太高一个像素
- javascript - 用于下载文件的烧瓶 html 链接
- android - 无法在 Ionic App 中查看本地 PDF 文件(使用 ng2-pdf-viewer)
- php - 异步PHP SOAP服务器在响应之前发送确认消息?
- python - 在 Python 中输出扩展总和和反向扩展总和
- c# - jQuery datatable c# 服务器端默认排序列给出null
- php - PDF 和 Roland 打印机特定代码
- arrays - 在perl中将数组从一个引用复制到另一个引用
- docker - docker hub 中的构建参数是什么