QOpenGLWidgetでQPainterを使用しようとしています。しかし、それは3.0 OpenGLのバージョンでのみ動作します。何が問題ですか?OpenGL 3.3形式でQPainterを使用するには?
ここに私のコードです。
#include <QApplication>
#include <QMainWindow>
#include "window.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSurfaceFormat format;
format.setRenderableType(QSurfaceFormat::OpenGL);
format.setProfile(QSurfaceFormat::CoreProfile);
format.setVersion(3,3);
// Set widget up
Window *widget = new Window;
widget->setFormat(format);
// Set the window up
QMainWindow window;
window.setCentralWidget(widget);
window.resize(QSize(800, 600));
window.show();
return app.exec();
}
「format.setVersion(3,3);」とコメントしてくださいすべて正常に動作します。しかし、私のシェイダーは起動しません。
そして
#ifndef WINDOW_H
#define WINDOW_H
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
class QOpenGLShaderProgram;
class Window : public QOpenGLWidget,
protected QOpenGLFunctions
{
Q_OBJECT
// OpenGL Events
public:
void initializeGL();
void resizeGL(int width, int height);
void paintGL();
};
#endif // WINDOW_H
と最も単純例QOpenGLWidgetサブクラス。
#include "window.h"
#include <QDebug>
#include <QString>
#include <QOpenGLShaderProgram>
#include "vertex.h"
#include <QPainter>
void Window::initializeGL()
{}
void Window::resizeGL(int width, int height)
{}
void Window::paintGL()
{
QPainter p(this);
p.setPen(Qt::red);
p.drawLine(rect().topLeft(), rect().bottomRight());
}
あなたはどのようなハードウェアとドライバを持っていますか?彼らはOpenGL 3.3をサポートしていますか? – ybungalobill