Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt5 and glew
Forum Updated to NodeBB v4.3 + New Features

Qt5 and glew

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi,

    I have a problem with the initialization of glew. glewInit() dosen't return GLEW_OK.

    class Viewer : public QWindow
    {
    private:
        QOpenGLContext* context_;
    	QSurfaceFormat* format_;
    public:
    	Viewer() {
    	setGeometry(QApplication::desktop()->screenGeometry().width()/2-350, QApplication::desktop()->screenGeometry().height()/2-350, 700, 700);
    
    	setSurfaceType(QWindow::OpenGLSurface);
    
    	format_ = new QSurfaceFormat();
    	format_->setDepthBufferSize(24);
    	format_->setStencilBufferSize(8);
    	format_->setVersion(4, 3);
    	format_->setSwapInterval(0);
    	format_->setProfile(QSurfaceFormat::CoreProfile);
    	setFormat(*format_);
    
    	context_ = new QOpenGLContext(this);
    	context_->setFormat(*format_);
    	context_->create();
    	context_->makeCurrent(this);
    	glewExperimental = true;
    	if (glewInit() != GLEW_OK) {
    		std::cout<<"GLEW isn't init."<<std::endl;
    	}
    
    	context_->doneCurrent();
        }
    	~Viewer();
    };
    

    Best regards,
    Robin

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      Well first thing that strikes me is you're not doing any error checking. create() and makeCurrent() may very well fail so you should check that.
      Other than that, if I remember correctly (I might not), the window isn't really created until it is first shown, so ceating and using context in the constructor is not the best place. You could deffer context creation until the first showEvent() or use a QOffscreenSurface if you really need it in the constructor.
      Also you are leaking format_. QSurfaceFormat is usually created on the stack and I strongly suggest that in this case.
      Take a look at OpenGL Window Example to see how correct context creation can be handled.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        You're right. if I connect a slot like that in my constructor : "connect(&loop_, SIGNAL(timeout()), this, SLOT(render()));", I can init glew's function.

        void Viewer::render() {
        	if (!context_) {
        		glewInit();
        	}
        }
        

        create() and makeCurrent() do not failed.

        thanks you for the QOffscreenSurface tricks :)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved