SDL2 自建窗口使用OpenGL 时候 wglCreateContext 失败的解决方法
2014-11-19 14:36
471 查看
wglCreateContext返回NULL
GetLastError返回2000 经查询是“无效的像素格式。”错误
尝试用SDL创建的窗口,就没有这个问题。
比对得知,自建窗口没有调用SetPixelFormat,才导致了“无效的像素格式。”
解决方法:
在SDL_windowsopengl.c中WIN_GL_CreateContext函数里面做如下修改即可。
原来:
修改为:
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; }
相关文章推荐
- 解决Asp.net Mvc中使用异步的时候HttpContext.Current为null的方法
- 单元测试时候使用[ClassInitialize]会该方法必须是静态的公共方法,不返回值并且应采用一个TestContext类型的参数报错的解决办法
- 关于使用spring框架的时候抽象类中注入其他实现类失败的解决方法
- windows2003 IIS 服务启动失败,提示‘另一个程序正在使用此文件,进程无法访问',解决方法
- VS 2005 水晶报表 使用方法及 出现“加载报表失败” 的解决方法
- 使用MySQL-Front连接mysql的时候发生的错误解决方法
- myeclipse开发webservice的时候,加载axis2失败的解决方法
- 解决列表框更新数据的时候的闪烁问题(VC防止窗口及其控件(如CListCtrl)闪烁的简单方法(一组有用的宏) )
- 使用getJSON进行局部刷新时,url所带参数过长,导致失败的解决方法
- 使用缓存时候,发现Page_load只能运行一次的解决方法。
- su的时候密码认证失败的解决方法
- ASP使用ADO连接ORACLE数据库失败解决方法
- 使用SQLDMO中“接口SQLDMO.Namelist 的 QueryInterface 失败”异常的解决方法
- 关于IIS服务启动失败的问题:“IIS提示‘另一个程序正在使用此文件,进程无法访问’”,的解决方法
- 使用Ajax后,原来导出功能失败的解决方法
- asp.net 数据绑定 使用eval 时候报 字符文本中的字符太多 问题的解决方法
- 【Vegas原创】解决cmd窗口不够使用的方法
- 解决href使用onclick方法时点击该链接的时候不会跳转页面.但是滚动条会往上滚的问题
- 打开新窗口的window.open使用方法以及最大化等问题解决方法汇总
- smarty中用date_format格式化时间的时候使用汉字的解决方法