无法在InitializeGL和paintGL之外调用OpenGL相关函数 [英] Unable to call OpenGL related functions outside of InitializeGL and paintGL

查看:1355
本文介绍了无法在InitializeGL和paintGL之外调用OpenGL相关函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所示,在Qt内部,我无法使用或调用QGLWidget函数之外的任何OpenGL函数,例如 initializeGL() paintGL()



在我调用 QMainWindow 类的插槽之后,我正在尝试构建一个3D模型。一切似乎工作正常,所有的顶点都加载,但是,当我尝试和绘制我的模型,我得到一个NULL引用异常;这通常在提供太少的顶点时发生。



当在 initializeGL()中使用时,同样的构建函数工作。

As the title suggests, inside of Qt, I am unable to use, or call any OpenGL functions outside of QGLWidget functions like initializeGL(), and paintGL().

I am trying to build a 3D model, after a slot from my QMainWindow class is called. Everything appears to work fine, all of the vertices are loaded, however, when I try and draw my model, I get a NULL reference exception; which occurs, most often, when too few Vertexes are provided.

The same building function works when I use it in initializeGL().

推荐答案

这实际上很简单:在这些函数之外,QGLWidget的上下文不是当前的。您可以通过调用QGLWidet :: makeCurrent()使上下文当前。一个或许更好的方法来解决这个问题是延迟调用任何GL函数在paintGL内,因为这确保上下文是最新的,你不会冒险通过改变上下文来打扰任何其他openGL的东西。

This is actually quite simple: outside of those functions, the QGLWidget's context is not current. You can make the context current by calling QGLWidet::makeCurrent(). A perhaps better way to get around this is to defer calling any GL functions to within paintGL, as that ensures that the context is current, and you don't risk messing with any other openGL stuff by changing the context.

这篇关于无法在InitializeGL和paintGL之外调用OpenGL相关函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆