8.在源代码中继承,并实现。
virtual void initializeGL();//负责初始化,就是缓冲对象vao、vbo、ebo、着色器、纹理、摄像机。
virtual void resizeGL(int w, int h);//视图、窗口大小改变,自动调用
virtual void paintGL();//画,渲染一次。循环要添加update()函数
9.initializeGL()函数,负责初始化,就是缓冲对象vao、vbo、ebo、着色器、纹理、摄像机。
This virtual function is called once before the first call to paintGL() or resizeGL(). Reimplement it in a subclass.This function should set up any required OpenGL resources and state.
There is no need to call makeCurrent() because this has already been done when this function is called. Note however that the framebuffer is not yet available at this stage, so avoid issuing draw calls from here. Defer such calls to paintGL() instead.
10.resizeGL(int w, int h)函数,/视图、窗口大小改变,自动调用
This virtual function is called whenever the widget needs to be painted. Reimplement it in a subclass.There is no need to call makeCurrent() because this has already been done when this function is called.
Before invoking this function, the context and the framebuffer are bound, and the viewport is set up by a call to glViewport(). No other state is set and no clearing or drawing is performed by the framework.
11.paintGL()函数画,渲染一次。循环要添加update()函数
Sets the requested surface format.When the format is not explicitly set via this function, the format returned by QSurfaceFormat::defaultFormat() will be used. This means that when having multiple OpenGL widgets, individual calls to this function can be replaced by one single call to QSurfaceFormat::setDefaultFormat() before creating the first widget.
12. 在cpp文件中修改一下,paintGL函数的内容。
13.结果,看见一个黑色框框就是正确的QOpenGLWidget窗口。
源代码: