summaryrefslogtreecommitdiffstats
path: root/src/gui/doc/snippets/code/src_gui_opengl_qopenglfunctions.cpp
blob: 14531446a1002d5380685cdd94e4661ecb56b597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QOpenGLFunctions>
#include <QtOpenGL/QOpenGLWindow>

#include <QSurface>
#include <QWidget>
#include <QWindow>

namespace src_gui_opengl_qopenglfunctions {

//! [0]
class MyGLWindow : public QWindow, protected QOpenGLFunctions
{
    Q_OBJECT
public:
    explicit MyGLWindow(QScreen *screen = nullptr);

protected:
    void initializeGL();
    void paintGL();

    QOpenGLContext *m_context;
};

MyGLWindow::MyGLWindow(QScreen *screen)
  : QWindow(screen)
{
    setSurfaceType(OpenGLSurface);
    create();

    // Create an OpenGL context
    m_context = new QOpenGLContext;
    m_context->create();

    // Setup scene and render it
    initializeGL();
    paintGL();
};

void MyGLWindow::initializeGL()
{
    m_context->makeCurrent(this);
    initializeOpenGLFunctions();
}
//! [0]


int textureId = 0;

//! [1]
void MyGLWindow::paintGL()
{
    m_context->makeCurrent(this);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D, textureId);
    // ...
    m_context->swapBuffers(this);
    m_context->doneCurrent();
}
//! [1]


void wrapper0() {
//! [2]
QOpenGLFunctions glFuncs(QOpenGLContext::currentContext());
glFuncs.glActiveTexture(GL_TEXTURE1);
//! [2]
} // wrapper0


void wrapper1() {
//! [3]
QOpenGLFunctions *glFuncs = QOpenGLContext::currentContext()->functions();
glFuncs->glActiveTexture(GL_TEXTURE1);
//! [3]


//! [4]
QOpenGLFunctions funcs(QOpenGLContext::currentContext());
bool npot = funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures);
//! [4]

Q_UNUSED(npot);
} // wrapper1
} // src_gui_opengl_qopenglfunctions