Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Not able to Draw using QOpenGLWidget



  • I have upgraded my project from QGLWidget to QOpenglWidget.

    The project worked fine using QGL widget but now i am not able to see the rendered output.

    class GLWidget : public  QOpenGLWidget
    {
    	Q_OBJECT;
    public:
    	explicit GLWidget(QWidget *parent = 0);
    //	~GLWidget();
    	void initializeGL() override;
    	void paintGL() override;
    	void resizeGL(int w, int h) override;
    	QTimer timer;
    	QElapsedTimer elapsedtimer;
    	
    
    private:
    	int width;
    	int height;
    
    };
    
    ///////////////////////////////////////////////////////////////////////////////////
    GLWidget::GLWidget(QWidget *parent) : QOpenGLWidget(parent)
    {
    	
    }
    
    //////////////////////////////////////////////////////////////////////////////////////////
    void GLWidget::initializeGL() 
    {
    	GLenum GlewInitResult;
    	glewExperimental = GL_TRUE;
    	GlewInitResult = glewInit();
    	if (GLEW_OK != GlewInitResult)   // Check if glew is initialized properly
    	{
    		QMessageBox msgBox;
    		msgBox.setText("Not able to Initialize Glew");
    		msgBox.exec();
    	}
    
    }
    /////////////////////////////////////////////////////////////////////////////////////////////
    void GLWidget::paintGL() 
    {
      // Painting commands here which are opengl commands using GLEW.
         glBindFramebuffer(GL_FRAMEBUFFER, 0);	// Render in default framebuffer
         glClear(GL_COLOR_BUFFER_BIT);
         RenderCube();	
    
       
    }
    ///////////////////////////////////////////////////////////////////////////////////////////
    
    IN the Main function
    
    QApplication application(argc, argv);
    
    QSurfaceFormat format;
    format.setDepthBufferSize(24);
    format.setStencilBufferSize(8);
    format.setVersion(3, 2);
    format.setProfile(QSurfaceFormat::CoreProfile);
    QSurfaceFormat::setDefaultFormat(format);
    
    return application.exec();
    

  • Lifetime Qt Champion

    Hi,

    Please provide a complete minimal compilable example that shows your issue.


Log in to reply