Porting an Aquarium Screensaver

Nibbie
Posts: 3
Joined: 2011.02
Post: #1
Hi everyone,

My name is Alan and i'm completely new to programming on Mac. I have a rather elaborate screensaver out called Dream Aquarium (http://www.dreamaquarium.com) and i'd like to port it to mac OSX. I say it's an elaborate screensaver because it can also be run in stand-alone mode and has a custom openGL-based GUI which means it needs to accept mouse and keyboard input, and needs to be multi-monitor compliant, where each monitor is it's own fishtank, and uses sound. It also uses several hundred support/data files. I think it's really more similar to a game than a screensaver because it can be fairly interactive. Eventually i'd also like it to run as your desktop as a replacement for a background image. I'm looking for some advice on where to start, seeing as i really know almost nothing about the mac or xcode. Should i be starting with the ScreenSaverView class or is that too primitive and limiting for what i'm trying to do?

Is there some particular engine out there that sounds like it would suit my needs?
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
Apple's screen saver framework docs should be helpful. Sounds like you already found them though. I don't think you can make a normal OS X screen saver any other way.

Since the screen saver framework uses Obj-C, you might as well wrap the standalone application in a Cocoa program as well.

I think that you get multiple monitor support for free, not entirely sure though. Never actually made a screen saver, thought about it and skimmed the documentation, but never acted.

Lastly, there are already programs in existence for OS X that let you run a screen saver in place of a desktop picture, so you don't really need to worry about that.
http://www.macupdate.com/info.php/id/20716
http://www.macupdate.com/info.php/id/8340

EDIT: What do you know: http://www.cocoadev.com/index.pl?ScreenSaverEngine
Apparently running a screen saver in the background is trivial.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 283
Joined: 2006.05
Post: #3
You might want to have a look at the source for XScreenSaver. I don't know how easy it would be to make it support more than one monitor (perhaps it already does), but it looks very easy to drop existing code into it. And that way you'd also get Linux-compatibility for free.

The Apple docs Skorche linked to are probably more useful, but Xscreensaver might be worth checking out if you don't want to have to learn Obj-C.
Quote this message in a reply
Moderator
Posts: 770
Joined: 2003.04
Post: #4
Skorche Wrote:EDIT: What do you know: http://www.cocoadev.com/index.pl?ScreenSaverEngine
Apparently running a screen saver in the background is trivial.

OMG! I just tried that with the LotsaWater screensaver. Love This is so cool! Grin

Anyway, back on topic: I highly recommend SaverLab for testing/debugging your screensaver. It includes lots of useful options, like pausing and step-by-step animation.

It's free and has source code available too (and so does the screensaver I mentioned before)
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2011.02
Post: #5
Hey all, thanks for all the links and advice.

Skorche Wrote:Since the screen saver framework uses Obj-C, you might as well wrap the standalone application in a Cocoa program as well.
Skorche, can you explain this more? I guess i don't really know what Obj-C is, although i've noticed the code examples i've seen aren't quite c++. Like i said i'm unfamiliar with programming on the mac. Are you suggesting i write the aquarium as a standalone openGL c++ program and then have a simple cocoa screensaver framework that executes the standalone?

This is similar to what i'm doing now in the Windows version.
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #6
a framework is a bundle of code. On Mac OS X, OpenGL is distributed as a framework, Cocoa is distributed as a framework, as SDL and everything else. A framework is just an API. Objective-C is the language Cocoa (and the ScreenSaver framework/API) is programmed in. The framework doesn't execute it Rasp
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #7
I wouldn't be the one to ask for a good Cocoa/Obj-C tutorial, but I'm sure someone else will chime in. It would probably also be a good idea to poke around at http://www.idevapps.com/forum/

At least to give you a brief answer:

Cocoa is the standard GUI API on OS X, and Obj-C is the language that Cocoa applications are usually written in. Obj-C is an object oriented superset of C.

The route I'd imagine you would want to take would be to write a little Obj-C code to wrap up your screen saver functionality. You could use that with the ScreenSaver framework which really just needs a couple of methods to operate. Similarly, you'd create a Cocoa application that creates an OpenGL view and sends the input to your custom UI stuff.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 312
Joined: 2006.10
Post: #8
Thes tutorials should give you a good understanding of the ScreenSaver framework

http://cocoadevcentral.com/articles/000088.php
http://cocoadevcentral.com/articles/000089.php
Quote this message in a reply
Member
Posts: 440
Joined: 2002.09
Post: #9
I can't offer any more insight on creating screensavers on Mac OS X, but I just want to say Dream Aquarium looks very nice! I'm gonna give the demo a go on my XP box over the weekend but I'm looking forward to the Mac version Wink
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #10
Wow, that is amazing. I can just imagine putting that screensaver on a projector while waiting for my Keynote presentation to start.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2011.02
Post: #11
thanks! after digging in deeper, following links and realizing how much i need to learn about programming the mac, i've decided it's probably worth it to just hire somebody to create a 'scaffold' project that i can start plugging my existing code into. If anyone is interested and capable, i've posted a topic:

http://www.idevgames.com/forum/showthrea...post125850

thanks!
alan
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #12
I really think you are overestimating how much you need to know. Assuming that your OpenGL based GUI is modular, you really just need a couple hundred lines of Cocoa code create an OpenGL context and pass mouse/keyboard events.

Similarly with the actual screen saver module, you really just need to define a class with a draw method that calls your screen saver drawing code.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Nibbie
Posts: 3
Joined: 2011.02
Post: #13
I don't know anything about cocoa or obj-C. The good news is I've now managed to port the aquarium to OSX using GLUT and have it running in a single window. The part i'm still foggy on is how to make this a screensaver. I can probably figure out how to get it running using the cocoa screensaver framework by altering the examples, but i'm foggy as to how the screensaver framework would handle multiple screens, and if it's possible to override the fact that the screensaver quits anytime a mouse/keyboard event happens, which seems to be handled automatically and out of sight by this framework. Is it possible to, and how might i be able to override/intercept screensaver mouse and keyboard events?

Thanks,
alan
Quote this message in a reply
Member
Posts: 53
Joined: 2006.10
Post: #14
Wow! this is a really nice screen saver Smile
Quote this message in a reply
Post Reply