QOpenGLWidget ステレオスコピック・レンダリングの例

この例では、ステレオスコピック・レンダリングをサポートした最小限のQOpenGLWidget ベースのアプリケーションを作成する方法を示します。

注: 立体レンダリングのサポートには、ステレオをサポートするグラフィックカード、3Dメガネ、特定のモニタなど、特定のハードウェア要件があります。

注: この例では、2つの画像を2つの別々のバッファにレンダリングします。3Dメガネを通して画像を見ると、3Dホログラフィック効果が得られます。

上の画像は左のバッファにレンダリングされるものです。

上の画像は右のバッファにレンダリングされるものです。

正しいサーフェスフラグの設定

立体レンダリングを有効にするには、QSurfaceFormat::StereoBuffers というフラグをグローバルに設定する必要があります。このフラグが内部でどのように処理されるかによっ て、ウィジェット上で行うだけでは十分ではありません。最も安全なのは、アプリケーションを開始する前に QSurfaceFormat::SetDefaultFormat で設定することです。

QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);

// Enable stereoscopic rendering support
format.setStereo(true);

QSurfaceFormat::setDefaultFormat(format);

2回のレンダリング

QSurfaceFormat::StereoBuffers が設定されると、paintGL()が2回呼び出されます。paintGL()の中でcurrentTargetBuffer()を呼び出すと、現在アクティブなTargetBufferを問い合わせることができます。

次のスニペットでは、頂点が重なってレンダリングされないように行列を少し平行移動しています。これは単純な例で、必要なサポートがあれば、実行時に左と右に2つのオブジェクトが表示されることを確認するためのものです。

// Slightly translate the model, so that there's a visible difference in each buffer.
QMatrix4x4 modelview;
if (currentTargetBuffer() == QOpenGLWidget::LeftBuffer)
    modelview.translate(-0.4f, 0.0f, 0.0f);
else if (currentTargetBuffer() == QOpenGLWidget::RightBuffer)
    modelview.translate(0.4f, 0.0f, 0.0f);

プロジェクト例 @ code.qt.io

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.