QOpenGL위젯 스테레오스코픽 렌더링 예제
이 예는 스테레오 렌더링을 지원하는 최소한의 QOpenGLWidget 기반 애플리케이션을 만드는 방법을 보여줍니다.
참고: 스테레오 렌더링을 지원하려면 스테레오를 지원하는 그래픽 카드, 3D 안경 및 특정 모니터와 같은 특정 하드웨어 요구 사항이 있습니다.
참고: 이 예에서는 두 개의 이미지를 두 개의 개별 버퍼에 렌더링합니다. 3D 안경을 통해 이미지를 보면 3D 홀로그램 효과가 나타납니다.
위 이미지는 왼쪽 버퍼에 렌더링되는 이미지입니다.
위 이미지는 오른쪽 버퍼에 렌더링될 이미지입니다.
올바른 표면 플래그 설정하기
스테레오스코픽 렌더링을 활성화하려면 전역적으로 QSurfaceFormat::StereoBuffers 플래그를 설정해야 합니다. 플래그가 내부적으로 처리되는 방식 때문에 위젯에서 설정하는 것만으로는 충분하지 않습니다. 가장 안전한 방법은 애플리케이션을 시작하기 전에 QSurfaceFormat::SetDefaultFormat에서 이 작업을 수행하는 것입니다.
QSurfaceFormat format; format.setDepthBufferSize(24); format.setStencilBufferSize(8); // Enable stereoscopic rendering support format.setStereo(true); QSurfaceFormat::setDefaultFormat(format);
두 번 렌더링하기
QSurfaceFormat::StereoBuffers 이 설정되면 paintGL()이 각 버퍼에 대해 한 번씩 두 번 호출됩니다. paintGL()에서 currentTargetBuffer()를 호출하여 현재 활성화된 TargetBuffer를 쿼리할 수 있습니다.
다음 스니펫에서는 행렬을 약간 변환하여 정점이 서로 겹치지 않도록 렌더링합니다. 이 간단한 예제를 통해 필요한 지원이 있으면 런타임에 왼쪽과 오른쪽에 각각 하나씩 두 개의 객체가 표시되어야 한다는 것을 알 수 있습니다.
// 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);
© 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.