Posted: March 13th, 2010 | Author: Thomas | Filed under: Apple, Development, SGI, Software | Tags: Apple, Cocoa, Development, IRIX, Objective-C, Screensaver, Xcode | 4 Comments »
My favorite screensaver of all times is Electropaint. It has its origins in the IRIX OS. The word “mesmerize” was always one of the things I connected with this screensaver. Electropaint™ is a US Trademark of Tristram Visual, www.tristram.com. But since IRIX is gone for good, Electropaint was on the same route …
Fortunatly, there is a good clone of Electropaint for Mac OS X. An older release can be found in Lloyd’s Lounge. Some time later a universal binary of the screensaver for Intel Macs was made available by Alexander von Below.
Since the release of Mac OS X 10.6 “Snow Leopard” all screensavers need to be 64 bit and use Garbage Collection. Apple posted a TN about the requirement and how to adjust the build settings. Otherwise Mac OS X will not allow the use of the older screensaver module.
So I took the source code and adjusted the build settings according to the TN. A few minutes later, a new build of ElectropaintOSX was ready. Another few minutes later the updated DMG file for easy download was assembled. As my contribution to the project was very small, I increased the version to 0.3.1 — indicating that this is the same codebase as in version 0.3 (Minor change: int and float were replaced by NSUInteger and CGFloat).

I do no longer have an 10.4 SDK on my computer, so I built ElectropaintOSX only for Mac OS X 10.5 and 10.6. And I do no longer have any computer with Mac OS X 10.5, so I could not test the build on Leopard. But it should be OK. If not, try the built supplied by Alexander von Below.
So, here is the link to the DMG file that contains the screensaver and the source code. Happy screensaving.
ElectropaintOSX 0.3.1
Requires: Mac OS X 10.5 or better
Posted: July 22nd, 2009 | Author: Thomas | Filed under: Apple, CUDA, Development | Tags: Cocoa, CUDA, Development, Objective-C, Xcode | No Comments »
In the last blog entry it was discussed what needs to be installed to get a combination of CUDA, Objective-C and Xcode up and running. This part of the series shows how to actually build a very simple project that uses CUDA and Objective-C.
It is assumed that CUDA 2.2, the NVCuda plug-in and the template are installed at their default locations. Furthermore a basic understanding of Objective-C, Xcode and the IB is required.
This is a step by step guide, how to build the simple project:
- Launch Xcode and create a cocoa application project
File > New Project… > Mac OS X > Applications > Cocoa Application
- Name the project “CUDA_Demo_1”.
- Drag the file “/usr/local/cuda/lib/libcudart.dylib” into the project (under the blue icon in the Groups & Files window of Xcode). Copying is not required, but does not hurt either.
- Create a new file where we put the CUDA code into.
File > New File… > Mac OS X > Other > Empty File
- Name the new file “cudaCompute.cu”.
- Copy the “Listing One” of Part 1 from Dr. Dobbs excellent CUDA tutorial into the newly created file cudaCompute.cu. Change the line:
int main(void)
into the following line
extern “C” void cudaCompute(void)
And do not forget the closing bracket in the last line. It is missing in the code of Dr. Dobb’s “Listing One”.
- Add a new class that will be the AppController instance
File > New File… > Mac OS X > Cocoa > Objective-C class
- Name the new class files (.m and .h) AppController
- Declare a IBAction method that will handle a button press in AppController.h
- (IBAction)buttonPressed:(id)sender;
- Declare the cudaCompute function in AppController.h
void cudaCompute(void);
- Implement buttonPressed: in Appcontroller.m
- (IBAction)buttonPressed:(id)sender
{
cudaCompute();
NSLog(@"The function cudaCompute was called.");
}
- Open the MainMenu.xib, put an Object (from the Controller Group) into the xib, set the object to be of the class AppController. Add a button to the window and hook the button to the buttonPressed: action of the AppController class.
- Finally set some options before building the project:
Project > Edit Project Settings > Build
- NVIDIA CUDA – CodeGeneration > Device Emulation > Off
- NVIDIA CUDA – CodeGeneration > Host Compilation > C
- Linking > Runpath Search Paths > /usr/local/cuda/lib
- Linking > Other Linker Flags > -lcuda -lcudart
- Search Paths > Library Search Paths > /usr/local/cuda/lib
- Search Paths > User Header Search Paths > /usr/local/cuda/include (activate the recursive flag – it will display /usr/local/cuda/include/**)
- Build the project. Look at the output. Not much to see there. But this is actually a working CUDA with Objective-C example.
Add some printf statements to see the output the input values of the assert command in cudaCompute.cu. This might help to understand and verify that the application worked as it is supposed to. The project file that can be downloaded here – CUDA_Demo_1 – includes a version of cudaCompute.cu with some additional output and comments.
Some notes about this project:
- It is a very simple example and not even using a true CUDA kernel. The example is about mixing CUDA, Objective-C and Xcode — not about state of the art GPU programming.
- The project settings for the section NVIDIA CUDA – CodeGeneration will only be displayed if there is at least one .cu file included in the project.
- libcudart.dylib is the cuda runtime dynamic library
- Xcode seems to remember some settings as new defaults. So I might have missed to mention a change to a required option. Please inform me if you have some problems with the example, I will try to figure it out.
- Hint: Have a look at the CUDA C:C++ App template for the correct build settings.
- NVIDIA released CUDA 2.3 SDK today. Everything above is valid for CUDA 2.2 SDK. No guarantees for 2.3 – though looking at the release notes there seem to be no obvious show stoppers.
- Thanks to “TheBaron” from the #cuda channel of irc.freenode.net for answering my questions with lots of patience.
The next part of this series will most likely deal with the question, how to move data between Cocoa NSArrays and plain C arrays. And I have to learn more about CUDA. So when looking a my schedule, do not expect Part 3 to arrive soon™.
CUDA, Objective-C and Xcode — Part 2
CUDA, Objective-C and Xcode — Part 1
Posted: July 20th, 2009 | Author: Thomas | Filed under: Apple, CUDA, Development | Tags: Cocoa, CUDA, Objective-C, Xcode | 5 Comments »
Xcode is the preferred integrated development enviroment (IDE) for most Cocoa developers. It offers good support for a variety of languages, esp. C, C++ and Objective-C. It is possible to extend Xcode to handle matters which Apple does not support out of the box. This post shows how to integrate CUDA with Xcode.
This howto guide was written for Xcode 3.1.3, Mac OS X 10.5.7 and CUDA 2.2. Keep in mind, that later versions may break the following procedure.
To use CUDA the basic files from NVIDIA are required.
- CUDA Toolkit 2.2 for Mac OS
- CUDA SDK 2.2.1 code samples for Mac OS
- (optional) CUDA Visual Profiler v1.2 for Mac OS
When installing these files, take care to choose custom install and mark the CUDA.kext to be installed. See the note on my earlier post about this.
In the next step two files are required: a plug-in to introduce .cu files to Xcode and a template to set up Xcode for CUDA programming. You can download both files from the NVIDA forum in the CUDA on Mac OS X section, specifically posting #29 in this thread. Some very talented guy called Paul T. Thompson created a plug-in and a template. Download the two files labeled “CUDA_Projects.zip” and “NVCuda.pbplugin.zip”.
As described by Paul, these files need to be copied to specific places in your $HOME directory. Here’s the summary:
“CUDA_Projects.zip”
- Extract the file CUDA_Projects.zip
- Copy the folder CUDA Projects to the folder
$HOME/Library/Application Support/Developer/Shared/Xcode/Project Templates/
If some of the folders do not exist in your $HOME folder, simply create them.
“NVCuda.pbplugin.zip”
- Extract the file NVCuda.plugin.zip
- Copy the file NVCuda.plugin to the folder
$HOME/Library/Application Support/Developer/Shared/Xcode/Plug-ins/
Again, if some folders do not exist in your $HOME folder, simply create them.
Basically, that is all, what needs to be done. Launch Xcode and verify the correct installation of CUDA and the plug-in as well as the template. When creating a New Project… , there should be a new choice if the template was copied to the correct location:
User Templates > CUDA Projects > CUDA C:C++ App

Select this and create a new CUDA C:C++ App. To verify the NVCuda.pbplugin, select
Project > Edit Project Settings > Build
Near the bottom of the list should be a section named NVIDIA CUDA – CodeGeneration. If you see this, the plug-in was installed correctly. By default, Device Emulation is active. In the screenshot below it is deactivated.

So far — so good. In a soon™ to be published follow up I will explain how to combine Cocoa and CUDA.
Posted: May 22nd, 2009 | Author: Thomas | Filed under: Apple, Development | Tags: Apple, Cocoa, Development, Xcode | No Comments »
Before the availibility of Objective-C 2.0 the usage of Key-Value Coding accessors required some boiler plate code. Objective-C 2.0 introduced the @property and @synthesize directives and reduced a lot of boiler plate code into two simple statements. Which is kind of nice.
Nevertheless there might be circumstances that force you to implement KVC accessors manually. But you do not have to type all the accessor methods code by yourself. Xcode can take care of this task. Here is how to do this.
Within you .h file, create the property you need for your application. Let us assume you need an array like this:
…
NSArray *someArray;
…
Select the whole line where you just defined your NSArray instance variable and go to the script menu (it is the one with the ancient scroll icon). Select the command
Script Menu > Code > Place Accessor Decls on Clipboard
Next, paste the declarations to your .h file. Select the whole line with your NSArray instance variable again, this time select the command
Script Menu > Code > Place Accessor Defs on Clipboard
and paste the content of the clipboard to your .m file in the @implementation part of your code.
While this is only a minor help for properties of the NSArray class, try the same for the NSMutableArray class. Now we are talking about time saving. Thanks, Xcode team!
Posted: January 25th, 2009 | Author: Thomas | Filed under: Apple, Development, Software, iPhone | Tags: Apple, Cocoa, ColorRef, Development, iPhone | No Comments »
Meine erste iPhone Anwendung hat es in den App Store geschafft: ColorRef. Hier ist der Direktlink zum App Store.
ColorRef ist ein kleines Programm zum verwalten von Farbpaletten. Es können Farbpaletten – sogenannte Themes – angelegt werden. Einem Theme können Farben hinzugefügt werden. Der eigentliche Nutzen ist, dass zu den Farben die entsprechenden RGB-Werte angezeigt werden können. Über einen Klick auf eine Farbe wird die Anzeige des RGB-Wertes zwischen Dezimal-, Hexadezimal- und CoreGraphics-Format umgeschaltet.
Warum das Ganze, wenn doch alle Programme von Adobe ein gutes Farbpalettenmanagement mitbringen und Mac OS X die Farbpalette sogar Systemweit bei Cocoa Anwendungen anbietet? Die triviale Antwort: Die ganzen anderen Anwendungen. Es ist leichter, die Farbwerte schnell auf dem iPhone nachzusehen, als erst Anwendung A zu starten, dort Farbwerte herauszusuchen, Fenster passend auf dem Monitor verschieben oder sich Notizen zu machen, um diese Farben in Anwendung B zu verwenden. ColorRef ist der digitale Notizzettel für Farbwerte.
Daher hoffe ich, dass dem einen oder anderen ColorRef gefällt. Verbesserungsvorschläge und Hinweise zu Bugs sind gerne gesehen … ein paar Ideen habe ich auch schon.
P.S.
Chapter 35 – Challenge: Teil I habe ich geschafft, Teil II wird die Download Statistik zeigen.
Posted: November 9th, 2008 | Author: Thomas | Filed under: Apple, Development | Tags: Apple, Cocoa, Development | No Comments »
Heute bin ich bei Kapitel 35 von Aaron Hillegass Buch »Cocoa Programming for Mac OS X« angekommen. Nachdem ich die zweite Ausgabe wegen eines freizeitraubenden Projekts im (bezahlten) Job nie bis zum Ende erarbeitete, habe ich das bei der dritten Ausgabe des Buches endlich geschafft.
Das Buch ist die Empfehlung für alle, die sich mit Cocoa beschäftigen wollen. Kenntnisse in C und ein solides Englisch sind als Voraussetzung empfehlenswert. Thematisch wird das meiste abgedeckt, was von einer Mac Anwendung an Funktionalität erwartet wird. Grundlegende Konzepte werden soweit erklärt, dass verständlich wird, wie Cocoa funktioniert. Auch CoreData, CoreAnimation und OpenGL werden kurz angesprochen. Beispiele und Aufgaben vertiefen das Wissen.
Besonders gefällt die ständige Motivation durch Aaron, weitergehende Informationen zu suchen, um alle Details zu verstehen oder Varianten auszuprobieren. Infos findet man auf den Developer Seiten bei Apple und in der umfangreichen Dokumentation, die Xcode begleitet. Aaron Hillegass bringt den Leser auf den richtigen Weg, um die Einstiegshürde in Cocoa zu nehmen.
Nachdem ich also das Buch durchgearbeitet habe, verbleibt die letzte Challenge aus Chapter 35:
Challenge
Write a Cocoa application and get someone (not yourself) to use it.
Wenn es soweit ist, werde ich das Programm hier auf Crimson-Magic zur Verfügung stellen. CU soon.