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?
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?
I found these pretty helpul with making OSX screensavers:
http://cocoadevcentral.com/articles/000088.php
http://cocoadevcentral.com/articles/000089.php
http://www.mactech.com/articles/mactech-…-urScreens/
http://www.mactech.com/articles/mactech-…-creens102/
/A
were you able to compile OF as a screensaver? I was asking memo about it and he said I would need to replace glut.
I wasn’t using OF I’m afraid, just plain C++ and some Objective-C.
/A
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
ofAppCocoaWindow now exists:
http://forum.openframeworks.cc/t/ofappcocoawindow—everything-but-fullscreen/2200/1
SWEET YEAH!
Damn yea!
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:
http://forum.soft32.com/mac/Including-f-…-44390.html
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!
http://cocoadevcentral.com/articles/000089.php
Code posted in next post.
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.
Theo
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.
no idea
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.
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
[quote author=“theo”]Okay I have OF running as a screensaver.
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. [/quote]
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
HTH,
Stephan
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.
Theo
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
PREVIEW:
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 )
ofAppScreenSaverWindow::setupOpenGL()
startAnimation ( this is also a screensaver view callback - gets called before the animation starts )
firstFrame!
setup called! ( we call testApp::setup in ofAppScreenSaverWindow on the first update loop )
//the main loop
update();
draw();
–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 )
initWithFrame
ofAppScreenSaverWindow::ofAppScreenSaverWindow()
FULL FULL FULL FULL FULL FULL FULL FULL FULL
ofAppScreenSaverWindow::setupOpenGL()
startAnimation
firstFrame! //why are there two?
firstFrame! //what are there two?
setup called!
//the main loop
update()
draw()
–now we move the mouse and exit fullscreen
stopAnimation ( stopping the fullscreen animation )
PREVIEW:
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:
http://www.cocoadev.com/index.pl?DebuggingScreensavers
I will post an updated example project that should have a lot of these pointer fixes in.
Theo
Hey everyone-
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,
colin
Hey Guys,
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,
/roger
Hi guys,
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?
Thanks,
Nuno
HI! It’s the only thread on screensaver I found… Anyone got some news?