Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ba747heavy

macrumors newbie
Original poster
Oct 4, 2005
17
0
New Mexico
At least, I think what I'm interested in is carbon.

My situation is that I am writing an OpenGL application in C. My intent is cross platform compatability, so the code I am writing is going to be as much as possible "safe" code. However, in the area of the UI I need to be able to set the menu bar, and open up sub windows so the user can alter some settings. I've done some googling and basically it seems that OGL gives me the ability to create context menus on mouse clicks, but that isn't what I need.

So what I am looking for is any tutorial or reference that will show how to include and use Carbon, preferably without creating an XCode project and using the interface builder, etc.

Thanks!

Fred Clausen
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
ba747heavy said:
At least, I think what I'm interested in is carbon.

My situation is that I am writing an OpenGL application in C. My intent is cross platform compatability, so the code I am writing is going to be as much as possible "safe" code. However, in the area of the UI I need to be able to set the menu bar, and open up sub windows so the user can alter some settings. I've done some googling and basically it seems that OGL gives me the ability to create context menus on mouse clicks, but that isn't what I need.

So what I am looking for is any tutorial or reference that will show how to include and use Carbon, preferably without creating an XCode project and using the interface builder, etc.

Thanks!

Fred Clausen
There are books written by Apple and third party writers that can help you. Every book involves the use of Xcode. And with Carbon and Interface builder, it's easy to include OpenGL to your projects. Why don't you want to use Xcode? Integration with C and the OpenGL API and Carbon API is very good in Xcode.

With XCode, comes the Reference Library which contains a very good reference for Carbon. Alternatively, you can look here, or buy a book.
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
I agree with Soulstorm's post--nothing to add there. But here's an idea, if you don't want to jump into Xcode:

Just use Xcode to setup a skeletal Carbon & OpenGL project--it doesn't have to do anything but include Carbon and OpenGL and compile and link. Make a copy of the build log and then quit Xcode. Look at the build log and the source files and use them as a guide to setting up your #includes and make file.
- - - -
Also a few notes about cross-platform development:

Keep the platform specific code separate from the cross-platform code!!!

Define your interface from the cross-platform code into the platform specific code. Keep it simple. For your situation, if I read it correctly, you might use something like this for the settings interface:

MySettings.h
...
struct MySettings {
Int32 setting1;
Int32 setting2;
...
};

bool doSettingsDlg(MySettings* pSettings);
...
MySettings.h is a cross-platform file--this file can be included in your cross-platform code.

Then you would have multiple implementations of MySettings.c, one for each platform you want to support. I usually make a subfolder in my source code folder for each platform. So, you'd have osx/MySettings.c, win/MySettings.c, and linix/MySettings.c (or whatever). You compile and link the one that matches whatever platform you are building for.

Also, (this is important), you ONLY #include carbon.h, windows.h, or whatever in the platform specific .c files. Never #include the platform specific api headers in the cross-platform code. This keeps you honest. If you accidentally try to use a platform specific function, it's a compile error! Nice and easy. I forces you to keep your code clean and separate.

So in win/MySettings.c you have:
...
#include "windows.h"
...
// windows implementation of doSettingsDlg(MySettings* pSettings)
bool doSettingsDlg(MySettings* pSettings)
{
// TODO: implement code to load settings from pSettings into a dialog box
// and then invoke the dialog box
}


And in osx/MySettings.c you have:
...
#include "carbon.h"
...
// osx carbon implementation of doSettingsDlg(MySettings* pSettings)
bool doSettingsDlg(MySettings* pSettings)
{
// TODO: implement code to load settings from pSettings into a dialog box
// and then invoke the dialog box
}
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
I must also add that cross-platform code does not exist when programming for Carbon. Carbon API routines don't have any similarities with the ones at windows. So, a few guidelines would be these:

In order to be as cross-platform as I can, I make my application as follows:

I build the main application routines separately from the main.cpp file (yes, I program in C++). In the main.cpp file I only add the interface (command line-like interface). So what I have is the spine of my program with only the necessary routines.

After that, I only have to change the interface file (which in this case is the main.cpp file) with the one thhat suits my platform better. When I program in carbon, I delete the main.cpp file and I rebuild it to include the command event handlers, and then I call the functions that are defined in the separate files.

I would follow the same method in windows, too.

Finally, if you want cross-platform compatibility, have you considered, Qt?
 

ba747heavy

macrumors newbie
Original poster
Oct 4, 2005
17
0
New Mexico
Thanks for the helpful posts! I've pretty much laid out my program as you recommend; the common routines in a common set of files, and the UI/OS Specific calls go into a separate area.

I'm very interested in the Qt code. That may be the perfect solution. Thanks again.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.