Esempio n. 1
0
TestWindow::TestWindow() {
    setSurfaceType(QSurface::OpenGLSurface);


    auto timer = new QTimer(this);
    timer->setInterval(5);
    connect(timer, &QTimer::timeout, [&] { draw(); });
    timer->start();

    connect(qApp, &QCoreApplication::aboutToQuit, [this, timer] {
        timer->stop();
        _aboutToQuit = true;
    });

#ifdef DEFERRED_LIGHTING
    _light->setType(model::Light::SUN);
    _light->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset::OLD_TOWN_SQUARE);
    _light->setIntensity(1.0f);
    _light->setAmbientIntensity(0.5f);
    _light->setColor(vec3(1.0f));
    _light->setPosition(vec3(1, 1, 1));
    _renderContext->args = _renderArgs;
#endif

    QSurfaceFormat format = getDefaultOpenGLSurfaceFormat();
    format.setOption(QSurfaceFormat::DebugContext);
    //format.setSwapInterval(0);
    setFormat(format);
    _glContext.setFormat(format);
    _glContext.create();
    _glContext.makeCurrent(this);
    show();
}
Esempio n. 2
0
int main(int argc, char** argv) {
    auto glversion = gl::getAvailableVersion();
    auto major = GL_GET_MAJOR_VERSION(glversion);
    auto minor = GL_GET_MINOR_VERSION(glversion);

    if (glversion < GL_MAKE_VERSION(4, 1)) {
        MessageBoxA(nullptr, "Interface requires OpenGL 4.1 or higher", "Unsupported", MB_OK);
        return 0;
    }
    QGuiApplication app(argc, argv);

    bool quitting = false;
    // FIXME need to handle window closing message so that we can stop the timer
    GLWindow* window = new GLWindow();
    window->create();
    window->show();
    window->setSurfaceType(QSurface::OpenGLSurface);
    window->setFormat(getDefaultOpenGLSurfaceFormat());
    bool contextCreated = false;
    QTimer* timer = new QTimer();
    QObject::connect(timer, &QTimer::timeout, [&] {
        if (quitting) {
            return;
        }
        if (!contextCreated) {
            window->createContext();
            contextCreated = true;
        }
        if (!window->makeCurrent()) {
            throw std::runtime_error("Failed");
        }
        glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        window->swapBuffers();
        window->doneCurrent();
    });
    // FIXME need to handle window closing message so that we can stop the timer
    QObject::connect(&app, &QCoreApplication::aboutToQuit, [&] {
        quitting = true;
        QObject::disconnect(timer, &QTimer::timeout, nullptr, nullptr);
        timer->stop();
        timer->deleteLater();
    });

    timer->setInterval(15);
    timer->setSingleShot(false);
    timer->start();
    app.exec();
    return 0;
}
Esempio n. 3
0
bool OffscreenGLCanvas::create(QOpenGLContext* sharedContext) {
    if (nullptr != sharedContext) {
        sharedContext->doneCurrent();
        _context->setShareContext(sharedContext);
    }
    _context->setFormat(getDefaultOpenGLSurfaceFormat());

    if (_context->create()) {
        _offscreenSurface->setFormat(_context->format());
        _offscreenSurface->create();
        return _offscreenSurface->isValid();
    }
    qWarning("Failed to create OffscreenGLCanvas context");

    return false;
}
Esempio n. 4
0
TestWindow::TestWindow() {

    auto timer = new QTimer(this);
    timer->setTimerType(Qt::PreciseTimer);
    timer->setInterval(5);
    connect(timer, &QTimer::timeout, [&] { draw(); });
    timer->start();

    connect(qApp, &QCoreApplication::aboutToQuit, [this, timer] {
        timer->stop();
        _aboutToQuit = true;
    });

    setSurfaceType(QSurface::OpenGLSurface);

    QSurfaceFormat format = getDefaultOpenGLSurfaceFormat();
    format.setOption(QSurfaceFormat::DebugContext);
    setFormat(format);
    _glContext.setFormat(format);
    _glContext.create();
    _glContext.makeCurrent(this);

    show();
}
Esempio n. 5
0
void GLWindow::createContext(QOpenGLContext* shareContext) {
    createContext(getDefaultOpenGLSurfaceFormat(), shareContext);
}
Esempio n. 6
0
OffscreenGLCanvas::OffscreenGLCanvas() :
    _context(new QOpenGLContext),
    _offscreenSurface(new QOffscreenSurface)
{
    setFormat(getDefaultOpenGLSurfaceFormat());
}