ofxAssets is an openFrameworks addon for simple access to assets inside your data folder.
Setup the addon with your project (e.g. drag the ofxAssets src files into your XCode project).
Assets go inside data/assets
appFolder/
appFolder/data/assets/images - places images here (png, jpg, jpeg)
appFolder/data/assets/shaders - place any shaders here (vert, frag, geom)
appFolder/data/assets/fonts - place any font files here (ttf)
#include “ofxAssets.h”
using namespace ofxAssets; // this is optional
//example
void testApp::draw() {
// quick access to assets
image("imageName").draw(10,10);
font("fontName", 30).drawString("...", 10, 10);
shader("shaderName").begin();
// if you don’t put ‘using namespace ofxAssets’ at the top of your source or header, then use:
ofxAssets::image("imageName").draw(10,10);
}
You can also reload the asset register (e.g. you edit an image externally and what to see it updated in your app) using
AssetRegister::refresh()
If your asset filename is background.png
, then you access this asset without the extension, e.g. image("background")
.
If phong.vert
and phong.frag
both exist in your assets/shaders
folder, then they will all be merged into one shader asset shader("phong")
. This is of course true for any combinationn of fragment vertex and geometry shader files. Your filesystem is not affected by this 'merging'.
The functions:
image(string)
font(string, int)
shader(string)
All return non-const references to instances of relevent types, i.e.:
ofImage
ofTrueTypeFont
ofShader
respectively.