I have an existing graphics program with OpenGL in Ubuntu. I want to use some functions in OF such as KInect related addons in my own graphics program. I suppose OF is a library and I may use it as a library in my own program. Would anyone help me how to solve my problem? Thank you very much!
Although OF is mainly oriented to be used as a framework rather than a library, ie: it imposses certain structure to your application… since 0.9.0 there’s a new call ofInit() that starts all the subsystems without need for creating an openFrameworks application. that should help towards being able to use OF as a library from a plain C++ application.
Also there’s certain calls that depend on an OF main loop and window been created but as long as you avoid those it should be ok, mostly avoid anything in ofGraphics.h and any draw or bind calls on objects. if you need the functionality of any of those but don’t want to have an OF mainloop and window you can still create a GL renderer (ofGLRenderer or ofGLProgrammableRenderer) and pass the objects to draw or bind to it. so instead of doing:
ofDrawCircle(...) texture.bind() mesh.draw() texture.unbind()
you would do:
// somewhere in you application init ofGLProgrammableRenderer gl; ofInit(); gl.setup(); // in your draw loop gl.startRender(); gl.drawCircle(...); gl.bind(texture); gl.draw(mesh); gl.unbind(texture); gl.endRender();
there’s an example on how to use an OF renderer that way in our git repository in apps/devApps/explicitRendererExample although there it’s still used as an OF app rather than from a plain C++/gl application
the choice between ofGLRenderer and ofGLProgrammableRenderer depends on the version of openGL you are using, if you are using openGL 3 or more then you should be using a programmable renderer
Many thanks for your detailed reply! This is great. It is much clear to me now.
My further questions now are:
How to use OF similar as other libraries, such as how to specify include path and lib files?
Currently, I compile OF inside OF folder and not sure where the lib files are. There is also no consideration of include path.
When I use OF as a library in a standalone C++ project, I need to specify the include path and lib files.
If I want to use an addon (e.g. ofxKinect) in my own project, how to define these then?
From my understanding, I need to copy OF files (e.g. ./lib/openframeworks under the main folder) to the folder of my C++ project and do “#include ‘ofxmain.h’” in my project files. Am I right? Or I need to compile OF files as a separate lib? Thanks a lot!