Qt5中的glGenBuffers在哪里? [英] Where is glGenBuffers in Qt5?

查看:413
本文介绍了Qt5中的glGenBuffers在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎在Qt5中找不到glGenBuffer函数,我的包含列表看起来像

I can't seem to find the glGenBuffer function in Qt5, my include list looks like

#include <QtOpenGL/qgl.h>
#include <QtOpenGL/qglbuffer.h>
#include <QtOpenGL/qglcolormap.h>
#include <QtOpenGL/qglframebufferobject.h>
#include <QtOpenGL/qglfunctions.h>
#include <QtOpenGL/qglpixelbuffer.h>
#include <QtOpenGL/qglshaderprogram.h>
#include <GL/GLU.h>

我正在尝试执行以下示例:

I am trying to do something like the following example:

http://qt-project.org/doc/qt- 5.0/qtopengl/cube.html

在哪里?

推荐答案

我知道我来晚了,但这是一个更优雅的解决方案(您不需要GLEW =)

I know I'm late, but here's a more elegant solution (you don't need GLEW =))

除了确保您的* .pro文件中包含QT += opengl,并且您的Qt版本具有OpenGL,并且您具有#include <QGLFunctions>(您并不需要列出的所有内容)上面;只有这一行)在您的头文件中,您还需要一件事.

in addition to making sure you have QT += opengl in your *.pro file, and that your version of Qt has OpenGL, and that you have #include <QGLFunctions> (you don't need all of those includes that you listed down above; just this one line) in your header file, you need one more thing.

因此,假设您有一个调用所有这些功能的类:

So given you have a class that calls all these functions:

class MeGlWindow : public QGLWidget
{
   // bla bla bla...
}

您需要继承受保护的类 QGLFunctions :

You need to inherit a protected class QGLFunctions:

class MeGlWindow : public QGLWidget, protected QGLFunctions // add QGLFunctions
{
   // bla bla bla...
}

此外,就像GLEW要求在调用OpenGL函数之前调用glewInit()一样,QGLFunctions也要求您调用initializeGLFunctions().因此,例如,在QGLWidget中,initializeGL()在开始绘制任何内容之前被调用一次:

ALSO, just as GLEW required glewInit() to be called once before you call the OpenGL functions, QGLFunctions requires you to call initializeGLFunctions(). So for example, in QGLWidget, initializeGL() is called once before it starts drawing anything:

void MeGlWindow::initializeGL()
{
    initializeGLFunctions();

    // ...now you can call your OpenGL functions!
    GLuint myBufferID;
    glGenBuffers(1, &myBufferID);

    // ...
}

现在,您应该可以在没有GLEW的情况下调用glGenBuffersglBindBufferglVertexAttribPointer或其他任何openGL函数.

Now you should be able to call glGenBuffers, glBindBuffer, glVertexAttribPointer or whatever openGL function without GLEW.

更新: 某些OpenGL函数(例如glVertexAttribDivisorglDrawElementsInstanced)不适用于QGLFunctions.这是因为QGLFunctions仅提供特定于OpenGL/ES 2.0 API的功能,而这些功能可能没有这些功能.

UPDATE: Certain OpenGL functions like glVertexAttribDivisor and glDrawElementsInstanced do not work with QGLFunctions. This is because QGLFunctions only provides functions specific to OpenGL/ES 2.0 API, which may not have these features.

要解决此问题,您可以使用 QOpenGLFunctions_4_3_Core (或类似),仅从Qt 5.1开始可用.将QGLFunctions替换为QOpenGLFunctions_4_3_Core,将initializeGLFunctions()替换为initializeOpenGLFunctions().

To work around this you could use QOpenGLFunctions_4_3_Core(or similar) which is only available since Qt 5.1. Replace QGLFunctions with QOpenGLFunctions_4_3_Core, and initializeGLFunctions() with initializeOpenGLFunctions().

这篇关于Qt5中的glGenBuffers在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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