#1 By: vanderlin, March 13th, 2009 17:23
I was wondering if it is possible to create a c++ app in objective c. I was trying to use the screensaver.framework for osx to build a screen saver.
Does anyone know if this is possible?
#2 By: hahakid, March 13th, 2009 20:07
#3 By: vanderlin, March 17th, 2009 14:07
were you able to compile OF as a screensaver? I was asking memo about it and he said I would need to replace glut.
#4 By: hahakid, March 17th, 2009 15:54
I wasn't using OF I'm afraid, just plain C++ and some Objective-C.
#5 By: memo, March 18th, 2009 07:16
Now that OF has the glut abstraction in place, it shouldn't be too hard to create an addon to remove glut and provide a native cocoa layer to run openFrameworks - similar to ofxiPhone (e.g. ofxCocoa or ofxOSX). Then you'd have full control of the window creation and there'd be no issues making screensavers (or using other osx frameworks or even making quartz composer plugins!). This has been on my todo list for a while but not had time :o
#6 By: theo, June 24th, 2009 14:25
#7 By: moka, June 24th, 2009 14:40
#8 By: memo, June 24th, 2009 14:54
#9 By: theo, June 26th, 2009 07:48
Okay I have OF running as a screensaver.
Webcam seems to work too
Only thing that doesn't seem to work is FMOD because the dylib has to be copied to the MAC_OS folder in myScreenSaver.saver/Contents/MAC_OS . The copying is fine but the @executable_path command we use in the build script for setting the dylib path fails because .saver is not an executable.
There is more info about the issue here:
Also I found this gem! A way to debug a screensaver on the command line.
/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -module RandomWeb -foreground
RandomWeb being the name of the screensaver.
This is so much better than the generic error System Preferences give you when you have an error in your code.
BTW most of this effort is based on the guide Andreas posted - so big thanks!
Code posted in next post.
#10 By: theo, June 26th, 2009 07:58
Okay so here is the example project.
the openFrameworks folder is included in the project folder because I had to comment out some FMOD related code to make it work.
the only other change that is needed is to modify freeimage.h
find the line:
typedef int32_t BOOL;
and change it to:
//typedef int32_t BOOL;
#define BOOL int32_t
Also a thing to note is that sometimes the system preferences doesn't re-load the screensaver correctly. so you have to right click on it in the list and remove it and then close system preferences and re-add it.
the screensaver can be found in Build/Debug/
I have not done anything yet in relation to the data/ folder that will come next.
Also be aware of the symbol clash issue described at the end here: http://cocoadevcentral.com/articles/000089.php
Basically it means you might not be able to have multiple screen savers with the same names / class names running at the same time.
#11 By: moka, June 26th, 2009 08:06
great, thanks theo, what target do you have to define for a screensaver? Is that a .bundle? I could not find .saver type targets so maybe you could clear that up for me.
#12 By: theo, June 26th, 2009 08:19
I just took a screensaver template project and hacked OF in.
one thing that would be good is to have two targets for a project - one that builds it as a cocoa window and another as a screensaver - that way it would be a lot faster to test stuff.
#13 By: moka, June 26th, 2009 08:55
yes, I just checked it and it seems to be a .boundle. no idea about the details though. Just out of curiosity I will try to build a project from scracth the next days
#14 By: sth, June 26th, 2009 10:52
You can adjust the loader_path of the plugin with install_name_tool, set it to @loaderpath instead of @executable_path this will circumvent the problem
For more info do a google search for install_name_tool and loader_path / bundle
#15 By: theo, June 26th, 2009 11:47
oh thats awesome - thanks!
that should do the trick.
I also have the same problem with loading files - currently I have to hardcode the data path in, but I think I should be able to get the screensaver's current path then set that as the data path on runtime.
#16 By: theo, June 26th, 2009 12:47
I found a bunch of bugs related to the way screensavers work and the way OF is setup.
Basically when you load a screensaver in and you are previewing it, it is one instance of your app then when you test it that is another instance. This means that all static pointers that are designed for accessing the window and testApp are being messed with and things get kind of ugly.
Anyway it is easily fixable, it is just that we have never really had a situation where we have needed to essentially run multiple testApps at the same time.
If anyone is interested this is what happens when you load a screensaver into system prefs, preview it, test it and then close system prefs - I had a lot of strange stuff happen with a more complex app - knowing the order helped a lot to figure out the bugs.
--open system preferences and select the OF screensaver
initWithFrame (the starting point for the screensaver view - objective-c )
ofAppScreenSaverWindow::ofAppScreenSaverWindow() ( our window is created )
PREVIEW PREVIEW PREVIEW PREVIEW PREVIEW PREVIEW ( we are in preview mode )
startAnimation ( this is also a screensaver view callback - gets called before the animation starts )
setup called! ( we call testApp::setup in ofAppScreenSaverWindow on the first update loop )
//the main loop
--now we hit the test... button to see it fullscreen
stopAnimation ( NOTE: it is pausing the preview, not killing it )
FULLSCREEN: ( all the commands are the same as above )
FULL FULL FULL FULL FULL FULL FULL FULL FULL
firstFrame! //why are there two?
firstFrame! //what are there two?
//the main loop
--now we move the mouse and exit fullscreen
stopAnimation ( stopping the fullscreen animation )
startAnimation ( the animation resumes )
dealloc ( this is actually the fullscreen view deallocing )
--end of preview as I close sys prefs
stopAnimation ( stop the preview animation )
dealloc ( dealloc the preview animation )
Also this is very helpful - lets you debug your screensaver with gdb on the commandline:
I will post an updated example project that should have a lot of these pointer fixes in.
#17 By: cthompso, February 21st, 2010 20:53
Theo, your project zip posted a while back on this thread doesn't play nice with 0061. I'm having some troubles with includes & such. Following the 0061 xcode project structure post is tricky too since the screen saver example has different targets etc., and I'm stuck in fairly unfamiliar territory. Do you have an updated version which works with 0061, or perhaps could explain how to update the old one?
thanks for any and all help,
#18 By: rogerpala, May 19th, 2010 12:11
I am trying to create a screensaver targeting 10.5, 10.6 OSX and Windows using oF.
I kind of get running Theo's example using 006 oF and targetting 10.5 but no success with the other ones.
Theo, do you have your updated screensaver example already?
Do you guys have any new information regarding openframeworks screensavers or can you point me to some direction?
Thanks a lot,
#19 By: nununo, March 2nd, 2011 09:38
Any news on this? I would like to convert a simple OF project into a screensaver and was hoping I could get the latest version of the example already with those bug fixed. Theo, can you post it?