博客參考:https://www.hahack.com/codes/openframeworks-intro/#%E4%BB%80%E4%B9%88%E6%98%AF-openframeworks 和 https://www.cnblogs.com/freeblues/p/5754158.html
什么是 openFrameworks
openFrameworks(以下簡稱 oF) 是一個開源的、跨平台的 C++ 工具包,它的設計目的為開發創造過程提供一個更加簡單和直觀的框架。openFrameworks
設計的初衷不是為計算機專業人士准備的, 而是為藝術專業人士准備的, 就像 Processing
一樣.
oF 的強大之處在於,它不僅是一個通用的膠水(glue),同時它還封裝了多種常用的庫,包括:
- OpenGL、GLEW、GLUT、libtess2、cairo - 用於處理圖形;
- rtAudio、PortAudio、OpenAL、Kiss FFT、FMOD - 用於音頻的輸入、輸出和分析;
- FreeType - 用於字體顯示;
- FreeImage - 用於圖像存儲和載入;
- Quicktime、GStreamer、videoInput - 用於視頻播放和截取;
- Poco - 用於開發網絡應用;
- OpenCV - 用於計算機視覺;
- Assimp - 用於讀入 3D 模型。
這些庫雖然遵循着不同的規則和用法,但 oF 在它們基礎上提供了一個通用的接口,使得使用它們變得很容易。除此之外,oF 的另一亮點在於它具有很好的跨平台特性。目前它支持 5 種操作系統(Windows、OSX、Linux、iOS、Android)以及 4 種 集成開發環境(XCode、Code::Blocks、Visual Studio、Eclipse)。
安裝和配置 oF
下面介紹如何在 Windows下安裝和配置 oF 。
超級簡單的代碼結構
其實 openFrameworks
最值得稱道的是它的代碼結構極其簡單, 假設你的項目名為 myOF
, 那么代碼結構如下:
#include "myOF.h" //-------------------------------------------------------------- void myOF::setup(){ } //-------------------------------------------------------------- void myOF::update(){ } //-------------------------------------------------------------- void myOF::draw(){ } //-------------------------------------------------------------- void myOF::keyPressed(int key){ } ...
如果你有過使用 Processing
的經驗, 就會感覺非常熟悉, 沒錯, 這些函數跟 Processing
中的含義完全一樣.
setup
在程序啟動時執行一次;draw
在程序啟動后每秒執行60次(該頻率可設), 用來繪制圖形;update
跟draw
一樣, 每秒執行60次, 把需要更新的代碼放在這里;keyPressed
處理按鍵事件;- 還有處理鼠標事件的一系列函數, 這里就不贅述了.
為什么會使用這種代碼結構? 因為 openFrameworks
原本的設計目的就是要讓非計算機專業的人士通過編程來創造各種計算機視覺/圖像/視頻/聲音藝術, 就像 Processing
的設計目標一樣, 所以它才會搞成這種簡單易用但是功能強大的形式.
環境配置
openFrameworks plugin for Visual Studio
Before you're able to use openFrameworks with Visual Studio, you have to have Common Tools for Visual C++ 2017 installed, otherwise you'll get an error message later on. To install, go to File > New > Project and choose Visual C++ in the installed templates section. There now should be an option to install the tools, if they aren't already. Select it, confirm with 'OK' and follow the instructions.
From Visual Studio, go to Tools > Extensions and Updates. Select online and search for openFrameworks and install the plugin.
That will allow you to use File > New > Project... to create new openFrameworks projects and the contextual menu on any project to later add and remove addons
Example這個文件夾下邊包含各種應用,也是學習、參考of的開始
- 開啟VS2017,打開example下的任何一個工程,找到后綴名.sln的文件,雙擊開啟
- 編譯、運行即可