Last active
August 29, 2015 13:56
-
-
Save remram44/9282025 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #------------------------------------------------- | |
| # | |
| # Project created by QtCreator 2014-02-28T17:28:33 | |
| # | |
| #------------------------------------------------- | |
| QT += core gui opengl openglextensions | |
| greaterThan(QT_MAJOR_VERSION, 4): QT += widgets | |
| TARGET = qtopengltest | |
| TEMPLATE = app | |
| SOURCES += \ | |
| testgl.cpp | |
| HEADERS += \ | |
| testgl.h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "testgl.h" | |
| #include <QApplication> | |
| #include <QDebug> | |
| #include <QOpenGLContext> | |
| #include <QSet> | |
| TestGLWidget::TestGLWidget() | |
| : QGLWidget(QGLFormat(QGL::SampleBuffers)) | |
| { | |
| } | |
| QSize TestGLWidget::minimumSizeHint() const | |
| { | |
| return QSize(50, 50); | |
| } | |
| QSize TestGLWidget::sizeHint() const | |
| { | |
| return QSize(400, 400); | |
| } | |
| void TestGLWidget::initializeGL() | |
| { | |
| qglClearColor(QColor(0, 0, 128)); | |
| glShadeModel(GL_SMOOTH); | |
| glEnable(GL_MULTISAMPLE); | |
| QOpenGLContext *opengl = QOpenGLContext::currentContext(); | |
| QList<QByteArray> extensions = opengl->extensions().toList(); | |
| qSort(extensions); | |
| qDebug() << "Supported extensions (" << extensions.count() << ")"; | |
| foreach(const QByteArray &extension, extensions) | |
| qDebug() << " " << extension; | |
| if(opengl->hasExtension(QByteArrayLiteral("GL_ARB_compute_shader"))) | |
| { | |
| compute_shader = new QOpenGLExtension_ARB_compute_shader(); | |
| compute_shader->initializeOpenGLFunctions(); | |
| //compute_shader->glDispatchCompute(); | |
| } | |
| else | |
| { | |
| qDebug() << "Compute shaders not supported"; | |
| compute_shader = 0; | |
| } | |
| } | |
| void TestGLWidget::resizeGL(int width, int height) | |
| { | |
| int side = qMin(width, height); | |
| glViewport((width - side) / 2, (height - side) / 2, side, side); | |
| glMatrixMode(GL_PROJECTION); | |
| glLoadIdentity(); | |
| #ifdef QT_OPENGL_ES_1 | |
| glOrthof(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0); | |
| #else | |
| glOrtho(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0); | |
| #endif | |
| glMatrixMode(GL_MODELVIEW); | |
| } | |
| void TestGLWidget::paintGL() | |
| { | |
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
| glLoadIdentity(); | |
| glTranslatef(0.0, 0.0, -10.0); | |
| glBegin(GL_TRIANGLES); | |
| glVertex3f(-0.2f, -0.2f, 0.0f); | |
| glVertex3f( 0.2f, -0.2f, 0.0f); | |
| glVertex3f( 0.2f, 0.2f, 0.0f); | |
| glEnd(); | |
| } | |
| MainWindow::MainWindow(QWidget *parent) | |
| : QMainWindow(parent) | |
| { | |
| setCentralWidget(new TestGLWidget()); | |
| setWindowTitle(tr("Test")); | |
| } | |
| int main(int argc, char *argv[]) | |
| { | |
| QApplication a(argc, argv); | |
| MainWindow w; | |
| w.show(); | |
| return a.exec(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef TESTGL_H | |
| #define TESTGL_H | |
| #include <QGLWidget> | |
| #include <QMainWindow> | |
| #include <QtOpenGLExtensions/QOpenGLExtensions> | |
| class TestGLWidget : public QGLWidget { | |
| Q_OBJECT | |
| private: | |
| QOpenGLExtension_ARB_compute_shader *compute_shader; | |
| public: | |
| TestGLWidget(); | |
| QSize minimumSizeHint() const; | |
| QSize sizeHint() const; | |
| protected: | |
| void initializeGL(); | |
| void paintGL(); | |
| void resizeGL(int width, int height); | |
| }; | |
| class MainWindow : public QMainWindow { | |
| Q_OBJECT | |
| public: | |
| MainWindow(QWidget *parent = 0); | |
| }; | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment