可跨平台C++开源图形图像框架:openFrameworks

博客参考: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),同时它还封装了多种常用的库,包括:

这些库虽然遵循着不同的规则和用法,但 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的文件,双击开启
  • 编译、运行即可
原文地址:https://www.cnblogs.com/flyinggod/p/10785233.html