使用的是Qt,建议使用Qt提供的OpenGL函数,例如QOpenGLVertexArrayObject类代替glGenVertexArrays和glBindVertexArray函数,怎么替代
时间: 2024-03-28 22:41:34 浏览: 93
如果您使用的是Qt,建议使用Qt提供的OpenGL函数代替OpenGL原生函数。
要使用`QOpenGLVertexArrayObject`类代替`glGenVertexArrays`和`glBindVertexArray`函数,您可以按照以下步骤进行操作:
1. 在您的类中添加一个`QOpenGLVertexArrayObject`对象:
```cpp
class MyGLWidget : public QOpenGLWidget
{
public:
// ...
private:
QOpenGLVertexArrayObject m_vao;
};
```
2. 在您的初始化函数中生成和绑定`QOpenGLVertexArrayObject`对象:
```cpp
void MyGLWidget::initializeGL()
{
// ...
m_vao.create();
m_vao.bind();
// ...
}
```
3. 在您的绘制函数中使用`QOpenGLVertexArrayObject`对象:
```cpp
void MyGLWidget::paintGL()
{
// ...
m_vao.bind();
// ...
}
```
这样可以替代以下OpenGL原生函数:
```cpp
GLuint m_vao;
glGenVertexArrays(1, &m_vao);
glBindVertexArray(m_vao);
```
请注意,`QOpenGLVertexArrayObject`类需要在Qt 5.1及以上版本中可用。如果您使用的是较旧的版本,可以使用扩展库glew来获取OpenGL 3.0及以上版本的`glGenVertexArrays`和`glBindVertexArray`函数。
阅读全文
相关推荐
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)