void DrawWidget::initPipeline() { if(renderer.isModernOpenGLAvailable()) { forward = new ForwardModule(); QString frag = QtUtils::fileToString(":shaders/shaders/forward.frag.glsl"); QString vert = QtUtils::fileToString(":shaders/shaders/forward.vert.glsl"); ShaderSource *source = new ShaderSource(); source->setSource(frag.toStdString().c_str(), ShaderSource::FRAGMENT); source->setSource(vert.toStdString().c_str(), ShaderSource::VERTEX); forward->setShaderSource(source); forward->compileShaders(sceneManager.getScene()); renderer.addModule(forward, "forward"); pick = new PickModule(width(), height()); forward->setRenderTarget(pick->getFrameBuffer()); renderer.addModule(pick, "pick"); forward->setClearBeforeDrawing(true); #ifdef COMPATIBILITY_DIMITRI qtFBO = new FrameBuffer(defaultFramebufferObject()); #endif pick->setRenderTarget(qtFBO); } else renderer.addModule(new CrappyModule(), "crappy"); }
void Preview::resizeGL(int width, int height) { nse.make_current(m_glew_id); nsrender_system * rs = nse.system<nsrender_system>(); if (rs != NULL) { rs->set_screen_fbo(defaultFramebufferObject()); rs->resize_screen(ivec2(width,height)); } emit opengl_resized(); }
void DrawWidget::resizeGL(int w, int h) { renderer.resizeGL(w, h); if(forward != NULL) { forward->setRenderTarget(pick->getFrameBuffer()); #ifdef COMPATIBILITY_DIMITRI delete(qtFBO); qtFBO = new FrameBuffer(defaultFramebufferObject()); pick->setRenderTarget(qtFBO); #endif } }
OGLViewer::OGLViewer(QWidget *parent) : QOpenGLWidget(parent) , view_cam(new perspCamera( Point3f(10, 6, 10), Point3f(0.0, 0.0, 0.0), Vector3f(0, 1, 0), width() / Float(height()))) , model_mesh(new TriangleMesh("../../scene/obj/unitCube.obj")) { auto ctx = this->context(); cout << "default fbo:\t" << defaultFramebufferObject() << endl; // Set surface format for current widget QSurfaceFormat format; format.setDepthBufferSize(32); format.setStencilBufferSize(8); format.setSamples(4); format.setVersion(4, 5); format.setProfile(QSurfaceFormat::CoreProfile); this->setFormat(format); }
void VideoPlayer::paintGL() { mpv_opengl_cb_draw(mpv_gl, defaultFramebufferObject(), width(), -height()); }
void NGLScene::paintGL() { //---------------------------------------------------------------------------------------------------------------------- // draw to our FBO first //---------------------------------------------------------------------------------------------------------------------- // grab an instance of the shader manager ngl::ShaderLib *shader=ngl::ShaderLib::instance(); (*shader)["Phong"]->use(); // Rotation based on the mouse position for our global transform ngl::Mat4 rotX; ngl::Mat4 rotY; // create the rotation matrices rotX.rotateX(m_win.spinXFace); rotY.rotateY(m_win.spinYFace); // multiply the rotations m_mouseGlobalTX=rotY*rotX; // add the translations m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x; m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y; m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z; static float rot=0.0; // get the VBO instance and draw the built in teapot ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance(); // we are now going to draw to our FBO // set the rendering destination to FBO glBindFramebuffer(GL_FRAMEBUFFER, m_fboID); // set the background colour (using blue to show it up) glClearColor(0,0.4f,0.5f,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set our viewport to the size of the texture // if we want a different camera we wouldset this here glViewport(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT); // rotate the teapot m_transform.reset(); m_transform.setRotation(rot,rot,rot); loadMatricesToShader(); prim->draw("teapot"); rot+=0.5; //---------------------------------------------------------------------------------------------------------------------- // now we are going to draw to the normal GL buffer and use the texture created // in the previous render to draw to our objects //---------------------------------------------------------------------------------------------------------------------- // first bind the normal render buffer glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebufferObject()); // now enable the texture we just rendered to glBindTexture(GL_TEXTURE_2D, m_textureID); // do any mipmap generation glGenerateMipmap(GL_TEXTURE_2D); // set the screen for a different clear colour glClearColor(0.4f, 0.4f, 0.4f, 1.0f); // Grey Background // clear this screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // get the new shader and set the new viewport size shader->use("TextureShader"); // this takes into account retina displays etc glViewport(0, 0, static_cast<GLsizei>(width() * devicePixelRatio()), static_cast<GLsizei>(height() * devicePixelRatio())); ngl::Mat4 MVP; m_transform.reset(); MVP= m_project*m_view*m_mouseGlobalTX; shader->setUniform("MVP",MVP); prim->draw("plane"); m_transform.setPosition(0,1,0); MVP= m_project*m_view*m_mouseGlobalTX*m_transform.getMatrix(); shader->setUniform("MVP",MVP); prim->draw("sphere"); //---------------------------------------------------------------------------------------------------------------------- }
void NGLScene::paintGL() { //---------------------------------------------------------------------------------------------------------------------- // draw to our FBO first //---------------------------------------------------------------------------------------------------------------------- // grab an instance of the shader manager ngl::ShaderLib *shader=ngl::ShaderLib::instance(); (*shader)["Phong"]->use(); glEnable(GL_MULTISAMPLE); // Rotation based on the mouse position for our global transform ngl::Mat4 rotX; ngl::Mat4 rotY; // create the rotation matrices rotX.rotateX(m_win.spinXFace); rotY.rotateY(m_win.spinYFace); // multiply the rotations m_mouseGlobalTX=rotY*rotX; // add the translations m_mouseGlobalTX.m_m[3][0] = m_modelPos.m_x; m_mouseGlobalTX.m_m[3][1] = m_modelPos.m_y; m_mouseGlobalTX.m_m[3][2] = m_modelPos.m_z; static float rot=0.0; // get the VBO instance and draw the built in teapot ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance(); // we are now going to draw to our FBO // set the rendering destination to FBO glBindFramebuffer(GL_FRAMEBUFFER, m_fboID); // set the background colour (using blue to show it up) glClearColor(0,0.4f,0.5f,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set our viewport to the size of the texture // if we want a different camera we wouldset this here glViewport(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT); // rotate the teapot m_transform.reset(); m_transform.setScale(1.8f,1.8f,1.8f); m_transform.setRotation(rot,rot,rot); loadMatricesToShader(); prim->draw("teapot"); rot+=0.1; //---------------------------------------------------------------------------------------------------------------------- // now we are going to draw to the normal GL buffer and use the texture created // in the previous render to draw to our objects //---------------------------------------------------------------------------------------------------------------------- // first bind the normal render buffer glBindFramebuffer(GL_FRAMEBUFFER, defaultFramebufferObject()); // now enable the texture we just rendered to glDisable(GL_MULTISAMPLE); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_textureID); // set the screen for a different clear colour glClearColor(0.4f, 0.4f, 0.4f, 1.0f); // Grey Background // clear this screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // get the new shader and set the new viewport size shader->use("TextureShader"); GLsizei numActiveUniforms; glGetProgramStageiv(shader->getProgramID("TextureShader"), GL_FRAGMENT_SHADER, GL_ACTIVE_SUBROUTINE_UNIFORM_LOCATIONS, &numActiveUniforms); glUniformSubroutinesuiv(GL_FRAGMENT_SHADER,numActiveUniforms,&m_subroutines[m_activeSubroutine]); // this takes into account retina displays etc glViewport(0, 0, static_cast<GLsizei>(width() * devicePixelRatio()), static_cast<GLsizei>(height() * devicePixelRatio())); ngl::Mat4 MVP; m_transform.reset(); MVP= m_project*m_view*m_mouseGlobalTX; shader->setUniform("MVP",MVP); prim->draw("plane"); m_transform.setPosition(0,1,0); MVP= m_project*m_view*m_mouseGlobalTX*m_transform.getMatrix(); shader->setUniform("MVP",MVP); prim->draw("sphere"); //---------------------------------------------------------------------------------------------------------------------- // glBindFramebuffer(GL_DRAW_FRAMEBUFFER, defaultFramebufferObject()); // Make sure no FBO is set as the draw framebuffer // glBindFramebuffer(GL_READ_FRAMEBUFFER, m_renderFBO); // Make sure your multisampled FBO is the read framebuffer // glDrawBuffer(GL_BACK); // Set the back buffer as the draw buffer // glBlitFramebuffer(0, 0, m_win.width, m_win.height, 0, 0, m_win.width, m_win.height, GL_COLOR_BUFFER_BIT, GL_NEAREST); }
void MpvWidget::paintGL() { mpv_opengl_cb_draw(mpv_gl, defaultFramebufferObject(), width(), -height()); }