我想使用QO使用QOpenGLWidget OpenGL,但我很難找到任何相關的例子。我是OpenGL的新手,所以我正在嘗試學習如何使用它,但是我發現這些教程在QOpenGLWidget中似乎並不適用。現在,我想要做的就是渲染一個三角形。如何在QOpenGLWidget中渲染三角形?
這是我到目前爲止。
頁眉:
namespace Ui {
class Widget;
}
class Widget : public QOpenGLWidget, protected QOpenGLFunctions
{
public:
explicit Widget(QWidget *parent = 0);
~Widget();
protected:
void initializeGL();
void resizeGL(int, int);
void paintGL();
private:
Ui::Widget *ui;
};
類:
Widget::Widget(QWidget *parent) :
QOpenGLWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
void Widget::initializeGL()
{
// Set up the rendering context, load shaders and other resources, etc.:
initializeOpenGLFunctions();
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
}
void Widget::resizeGL(int w, int h)
{
// Update projection matrix and other size-related settings:
}
void Widget::paintGL()
{
// Draw the scene:
glClear(GL_COLOR_BUFFER_BIT);
}
Widget::~Widget()
{
delete ui;
}
有沒有我可以用它來只呈現一個基本的三角任何的例子嗎?我試過這個:https://www.khronos.org/assets/uploads/books/openglr_es_20_programming_guide_sample.pdf,但是它拋出了很多我無法解決的錯誤。
我也不知道OpenGL上下文在QOpenGLWidget中是如何工作的。
*編輯:事實證明,這些例子是我的發行版(Arch Linux)上的一個單獨的軟件包。我能夠安裝它們,而且看起來有很多東西可以開始使用。
感謝您的幫助!
您是否嘗試過學習所附帶的GL(ES)的例子Qt的? QOpenGLWidget沒有什麼特別之處。 – peppe
我在哪裏可以找到這些例子? – inefarius
它們與Qt一起發貨。 OpenGL部分。 http://doc.qt.io/qt-5/examples-widgets-opengl.html – peppe