您的位置:首页 > 运维架构

SDL2 自建窗口使用OpenGL 时候 wglCreateContext 失败的解决方法

2014-11-19 14:36 471 查看
wglCreateContext返回NULL

GetLastError返回2000 经查询是“无效的像素格式。”错误

尝试用SDL创建的窗口,就没有这个问题。

比对得知,自建窗口没有调用SetPixelFormat,才导致了“无效的像素格式。”

解决方法:

在SDL_windowsopengl.c中WIN_GL_CreateContext函数里面做如下修改即可。

原来:

if (_this->gl_config.major_version < 3 &&
_this->gl_config.profile_mask == 0 &&
_this->gl_config.flags == 0) {
/* Create legacy context */
context = _this->gl_data->wglCreateContext(hdc);
if( share_context != 0 ) {
_this->gl_data->wglShareLists(share_context, context);
}
} else {
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
HGLRC temp_context = _this->gl_data->wglCreateContext(hdc);
if (!temp_context) {
SDL_SetError("Could not create GL context");
return NULL;
}


修改为:

if (_this->gl_config.major_version < 3 &&
_this->gl_config.profile_mask == 0 &&
_this->gl_config.flags == 0) {
/* Create legacy context */
context = _this->gl_data->wglCreateContext(hdc);

//20141119 metin add
if (NULL == context)
{
WIN_GL_InitExtensions(_this);

if (WIN_GL_SetupWindow(_this, window) >= 0)
{
/* Create legacy context */
context = _this->gl_data->wglCreateContext(hdc);
}
}

if( share_context != 0 ) {
_this->gl_data->wglShareLists(share_context, context);
}
} else {
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
HGLRC temp_context = _this->gl_data->wglCreateContext(hdc);
if (!temp_context) {
SDL_SetError("Could not create GL context");
return NULL;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐