天天看點

從LearnOpenGL CN轉到Qt OpenGL

               LearnOpenGL CN教程中,因為OpenGL隻是一個标準/規範,具體的實作是由驅動開發商針對特定顯示卡實作的。是以使用glfw庫來建立一個OpenGL上下文(Context)和一個用于顯示的視窗,使用glad庫來實作OpenGL接口的各個函數。在評論中還能看到一下網友使用IMGUI作為一些小工具視窗,友善修改一些參數等。由于日常工作使用Qt且Qt對opengl做了很好的封裝,并且市面的桌面應用Ui基本上都使用qt庫,是以轉入Qt OpenGL來跟着教程學習。

準備使用opengl來畫一個三角形。從qt示例中看看qt是怎樣教我們使用相關的代碼。

                                        ​​​​​​​        ​​​​​​​        ​​​​​​​        

從LearnOpenGL CN轉到Qt OpenGL
從LearnOpenGL CN轉到Qt OpenGL

 通過繼承QWindow和QOpenGLFunctions來實作。

從LearnOpenGL CN轉到Qt OpenGL
從LearnOpenGL CN轉到Qt OpenGL

通過繼承QOpenGLWidget和QOpenGLFunctions來實作。

也有通過繼承QOpenGLWidget和QOpenGLExtraFunctions來實作。

QOpenGLFunctions  說明

   QOpenGLFunctions 類提供了跨平台的OpenGl ES2.0 API版本。

  OpenGL 2.0 提供了OpenGL中的子類集合,可以提供跨多個平台的桌面系統以及嵌入式OpenGL的實作。然而,卻很難使用子類因為子類需要解決許多平台系統的操作問題。

  是以 QOpenGLFunctions提供了這樣的API,可以保證在所有的OpenGL系統中使用,并且也關注不同系統中的OpenGL的版本API的使用。Qt推薦直接繼承的方式來使用 QOpenGLFunctions類。

QOpenGLExtraFunctions是QOpenGLFunctions的子類,主要是對es3.0的一些方法的拓展。

 參考下面部落格:

OpenglES 3.0基礎知識_自由理想的足迹-CSDN部落格_opengles3一、Opengles特性1.對Opengl的簡化,比如OGL指定網格資料,可以用立即模式,可以顯示清單,和頂點數組;但是Opengl es上隻能用頂點數組方式傳遞幾何資料。2.對Opengl相容,盡量定義為一個精簡的opengl子集,也能夠在Opengl中運作。3.為了降低耗電和提高shader性能,引入了類型精度限定符。4.確定實作圖像品質的最小功能集,符合openglel圖像質

從LearnOpenGL CN轉到Qt OpenGL

https://blog.csdn.net/Blues1021/article/details/60335339

還有通過繼承QOpenGLWidget和QOpenGLFunctions_3_3_Core等等。

以上的QOpenGLFunctions_X_X_Core系列都是繼承QAbstractOpenGLFunctions,qt幫助文檔對于QAbstractOpenGLFunctions的描述:

OpenGL implementations on different platforms are able to link to a variable number of OpenGL functions depending upon the OpenGL ABI on that platform. For example, on Microsoft Windows only functions up to those in OpenGL 1.1 can be linked to at build time. All other functions must be resolved at runtime. The traditional solution to this has been to use either QOpenGLContext::getProcAddress() or QOpenGLFunctions. The former is tedious and error prone and means dealing directly with function pointers. The latter only exposes those functions common to OpenGL ES 2 and desktop OpenGL. There is however much new OpenGL functionality that is useful when writing real world OpenGL applications.

不同平台上的 OpenGL 實作能夠連結到可變數量的 OpenGL 函數,具體取決于該平台上的 OpenGL ABI。例如,在 Microsoft Windows 上,隻有 OpenGL 1.1 中的功能才能在建構時連結到。所有其他函數必須在運作時解析。傳統的解決方案是使用 QOpenGLContext::getProcAddress() 或 QOpenGLFunctions。前者繁瑣且容易出錯,意味着直接處理函數指針。後者僅公開 OpenGL ES 2 和桌面 OpenGL 共有的那些功能。然而,在編寫現實世界的 OpenGL 應用程式時,有許多新的 OpenGL 功能很有用。      
從LearnOpenGL CN轉到Qt OpenGL

 QOpenGLFunctions_3_3_Core  是對opengl3.3的包裝。

QOpenGLFunctions_3_3_Compatibility 為相容版本。

        簡單了解完這些,下一遍文章選擇QOpenGLWidget和QOpenGLExtraFunctions的方式編寫最經典的helloTriangle類,展示漂亮的三角形吧。

下一篇:Qt-OpenGL-01 hello三角形​​​​​​​