blob: 0cb45b9808e18084c8b2bf2282712a8de0d378fe (
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
|
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\example stereoqopenglwidget
\title QOpenGLWidget Stereoscopic Rendering Example
\examplecategory {Graphics}
\ingroup examples-widgets-opengl
\brief This example shows how to create a minimal QOpenGLWidget based
application with stereoscopic rendering support.
\note Support for stereoscopic rendering has certain hardware requirements,
such as, a graphics card with stereo support, 3D glasses and specific
monitors.
\note This example renders two images to two separate buffers. When you
view the images through 3D glasses, they give a 3D holographic effect.
\image stereoexample-leftbuffer.png
The above image is what will be rendered to the left buffer.
\image stereoexample-rightbuffer.png
The above image is what will be rendered to the right buffer.
\section1 Setting the correct surface flag
To enable stereoscopic rendering you need to set the flag
QSurfaceFormat::StereoBuffers globally. Just doing it on the widget is not enough
because of how the flag is handled internally. The safest is to do it on
QSurfaceFormat::SetDefaultFormat prior to starting the application.
\snippet stereoqopenglwidget/main.cpp 1
\section1 Rendering twice
After QSurfaceFormat::StereoBuffers is set, then paintGL() will be called twice,
once for each buffer. In paintGL() you can call currentTargetBuffer() to query
which TargetBuffer is currently active.
In the following snippet we slightly translate the matrix to not render the
vertices on top of each other. This is a simple example just too see that if the
necessary support is there, at runtime you should see two objects, one on the left
and one on the right.
\snippet stereoqopenglwidget/glwidget.cpp 1
*/
|