void QVROSGViewer::render(QVRWindow* /* w */, const QVRRenderContext& context, int viewPass, unsigned int texture) { // Set up framebuffer object to render into GLint width, height; glBindTexture(GL_TEXTURE_2D, texture); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); glBindTexture(GL_TEXTURE_2D, _fboDepthTex); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glBindFramebuffer(GL_FRAMEBUFFER, _fbo); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0); // Set up OSG graphics window _graphicsWindow->resized(0, 0, width, height); // Set up OSG camera QMatrix4x4 P = context.frustum(viewPass).toMatrix4x4(); _viewer.getCamera()->setProjectionMatrix(osg::Matrix(P.constData())); QMatrix4x4 V = context.viewMatrix(viewPass); _viewer.getCamera()->setViewMatrix(osg::Matrix(V.constData())); // Render _viewer.frame(); }
void QVRMinimalExample::render(QVRWindow* /* w */, const QVRRenderContext& context, int viewPass, unsigned int texture) { // Set up framebuffer object to render into GLint width, height; glBindTexture(GL_TEXTURE_2D, texture); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height); glBindTexture(GL_TEXTURE_2D, _fboDepthTex); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); glBindFramebuffer(GL_FRAMEBUFFER, _fbo); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture, 0); // Set up view glViewport(0, 0, width, height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); QMatrix4x4 projectionMatrix = context.frustum(viewPass).toMatrix4x4(); QMatrix4x4 viewMatrix = context.viewMatrix(viewPass); // Set up shader program glUseProgram(_prg.programId()); _prg.setUniformValue("projection_matrix", projectionMatrix); glEnable(GL_DEPTH_TEST); // Render QMatrix4x4 modelMatrix; modelMatrix.translate(0.0f, 0.0f, -15.0f); modelMatrix.rotate(_rotationAngle, 1.0f, 0.5f, 0.0f); QMatrix4x4 modelViewMatrix = viewMatrix * modelMatrix; _prg.setUniformValue("modelview_matrix", modelViewMatrix); _prg.setUniformValue("normal_matrix", modelViewMatrix.normalMatrix()); glBindVertexArray(_vao); glDrawElements(GL_TRIANGLES, _vaoIndices, GL_UNSIGNED_INT, 0); }