QOpenGLWidget绘制2D的方法
2017-08-13 13:35
429 查看
补充:必须在非核心模式的opengl才能实现同时使用gl原生函数和QPainter绘制。核心模式的opengl使用QPainter会导致QOpenGLWidget什么都显示不出来。
参考:https://stackoverflow.com/questions/27422928/qopenglwidget-and-qpainter-can-t-render-2d-and-3d-at-the-same-time
可以重新实现paintGL(),在其中通过QPainter绘图。通过update()重绘。
也可以使用通常QWidget的paintEvent()方法实现绘图,通过update()重绘。
下面是官方文档的节选:
Painting Techniques
As described above, subclassQOpenGLWidget to render pure 3D content in the following way:
Reimplement the
initializeGL() andresizeGL() functions to set up the OpenGL state and provide a perspective transformation.
Reimplement
paintGL() to paint the 3D scene, calling only OpenGL functions.
It is also possible to draw 2D graphics onto aQOpenGLWidget subclass usingQPainter:
In paintGL(), instead of issuing OpenGL commands, construct aQPainter
object for use on the widget.
Draw primitives using
QPainter's member functions.
Direct OpenGL commands can still be issued. However, you must make sure these are enclosed by a call to the painter's beginNativePainting() and endNativePainting().
When performing drawing usingQPainter only, it is also possible to perform the painting
like it is done for ordinary widgets: by reimplementingpaintEvent().
Reimplement the
paintEvent() function.
Construct a
QPainter object targeting the widget. Either pass the widget to the constructor or theQPainter::begin() function.
Draw primitives using
QPainter's member functions.
Painting finishes then the
QPainter instance is destroyed. Alternatively, callQPainter::end() explicitly.
参考:https://stackoverflow.com/questions/27422928/qopenglwidget-and-qpainter-can-t-render-2d-and-3d-at-the-same-time
可以重新实现paintGL(),在其中通过QPainter绘图。通过update()重绘。
也可以使用通常QWidget的paintEvent()方法实现绘图,通过update()重绘。
下面是官方文档的节选:
Painting Techniques
As described above, subclassQOpenGLWidget to render pure 3D content in the following way:
Reimplement the
initializeGL() andresizeGL() functions to set up the OpenGL state and provide a perspective transformation.
Reimplement
paintGL() to paint the 3D scene, calling only OpenGL functions.
It is also possible to draw 2D graphics onto aQOpenGLWidget subclass usingQPainter:
In paintGL(), instead of issuing OpenGL commands, construct aQPainter
object for use on the widget.
Draw primitives using
QPainter's member functions.
Direct OpenGL commands can still be issued. However, you must make sure these are enclosed by a call to the painter's beginNativePainting() and endNativePainting().
When performing drawing usingQPainter only, it is also possible to perform the painting
like it is done for ordinary widgets: by reimplementingpaintEvent().
Reimplement the
paintEvent() function.
Construct a
QPainter object targeting the widget. Either pass the widget to the constructor or theQPainter::begin() function.
Draw primitives using
QPainter's member functions.
Painting finishes then the
QPainter instance is destroyed. Alternatively, callQPainter::end() explicitly.
相关文章推荐
- Android开发之OpenGL绘制2D图形的方法分析
- Delphi使用OpenGL2d绘图之画图片Bmp的方法
- Android学习日记(yzy):opengl 绘制2d图形 基本框架
- QOpenGLWindow 、QOpenGLWidget 和 QPainter混合渲染方法初探
- 基于TILED的2D游戏绘制方法详解
- iOS开发中使用Quartz2D绘制上下文栈和矩阵的方法
- 【OpenGL】学习笔记之一 绘制基本图形单元的方法
- [Android]OpenGL绘制2D几何图形
- Win32 OpenGL编程系列 2D例子 -- 七巧板图形绘制
- Opengl绘制数组数据与文件数据的方法与Nvidia opengl sdk辅助实现
- Delphi下OpenGL2d绘图之画四边形的方法
- D3D中用3D方法绘制2D图象的例子
- [转]D3D中实现2D绘制的2种方法的学习
- [置顶]OpenGL11-绘制汉字最高效方法(使用Freetype)(代码已更新)
- QOPenGLWidget与QPainter混合编程--绘制文本
- OpenGL绘制基本图形单元的方法
- opengl|es - 2D绘制
- OpenGL绘制纹理,缩放相机导致纹理闪烁的解决方法gluPerspective ()
- Android基于OpenGL在GLSurfaceView上绘制三角形及使用投影和相机视图方法示例
- D3D中用3D方法绘制2D图象的例子