MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / Init

Method Init

samples/helloworldoverlay/openvroverlaycontroller.cpp:87–144  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

85// Purpose:
86//-----------------------------------------------------------------------------
87bool COpenVROverlayController::Init()
88{
89 bool bSuccess = true;
90
91 m_strName = "systemoverlay";
92
93 QStringList arguments = qApp->arguments();
94
95 int nNameArg = arguments.indexOf( "-name" );
96 if( nNameArg != -1 && nNameArg + 2 <= arguments.size() )
97 {
98 m_strName = arguments.at( nNameArg + 1 );
99 }
100
101 QSurfaceFormat format;
102 format.setMajorVersion( 4 );
103 format.setMinorVersion( 1 );
104 format.setProfile( QSurfaceFormat::CompatibilityProfile );
105
106 m_pOpenGLContext = new QOpenGLContext();
107 m_pOpenGLContext->setFormat( format );
108 bSuccess = m_pOpenGLContext->create();
109 if( !bSuccess )
110 return false;
111
112 // create an offscreen surface to attach the context and FBO to
113 m_pOffscreenSurface = new QOffscreenSurface();
114 m_pOffscreenSurface->create();
115 m_pOpenGLContext->makeCurrent( m_pOffscreenSurface );
116
117 m_pScene = new QGraphicsScene();
118 connect( m_pScene, SIGNAL(changed(const QList<QRectF>&)), this, SLOT( OnSceneChanged(const QList<QRectF>&)) );
119
120 // Loading the OpenVR Runtime
121 bSuccess = ConnectToVRRuntime();
122
123 bSuccess = bSuccess && vr::VRCompositor() != NULL;
124
125 if( vr::VROverlay() )
126 {
127 std::string sKey = std::string( "sample." ) + m_strName.toStdString();
128 vr::VROverlayError overlayError = vr::VROverlay()->CreateDashboardOverlay( sKey.c_str(), m_strName.toStdString().c_str(), &m_ulOverlayHandle, &m_ulOverlayThumbnailHandle );
129 bSuccess = bSuccess && overlayError == vr::VROverlayError_None;
130 }
131
132 if( bSuccess )
133 {
134 vr::VROverlay()->SetOverlayWidthInMeters( m_ulOverlayHandle, 1.5f );
135 vr::VROverlay()->SetOverlayInputMethod( m_ulOverlayHandle, vr::VROverlayInputMethod_Mouse );
136
137 m_pPumpEventsTimer = new QTimer( this );
138 connect(m_pPumpEventsTimer, SIGNAL( timeout() ), this, SLOT( OnTimeoutPumpEvents() ) );
139 m_pPumpEventsTimer->setInterval( 20 );
140 m_pPumpEventsTimer->start();
141
142 }
143 return true;
144}

Callers 1

mainFunction · 0.45

Calls 4

sizeMethod · 0.80
SetOverlayInputMethodMethod · 0.45

Tested by

no test coverage detected