View Full Version : OS X API question: Carbon or Cocoa with C++
macphip
2002.07.31, 03:17 AM
i am starting in programming for os x, with a knowledge in C and am learning C++. i am unsure which API to learn&use with C++, carbon or cocoa.
i have been looking at this apple page (http://developer.apple.com/techpubs/macosx/Darwin/PortingUNIX/graphicalports/Cocoa.html) but i'm unsure wether it means i can use C++ with cocoa directly or if i must do some work with objective-C in order to use it.
can c++ be used with cocoa the same as C with carbon?
can c++ be used with CARBON same as C?
and, which API would be best/simplest with C++, especially for game development?
thanks all, for the help
OneSadCookie
2002.07.31, 04:53 AM
* You can't use Cocoa with C++. Objective C and Java are your options for Cocoa.
* Carbon can be programmed from any of C, C++ or Objective C.
* Cocoa is the easier and the better-documented of the two APIs
* There's not much difference between them from a game-development perspective. My impression is that you have to learn less to use Cocoa for game development, OTOH there are probably more Carbon examples.
* You should probably learn OpenGL as your graphics API. It's much simpler than QuickDraw, and much more flexible, portable and faster than either QuickDraw or Quartz.
* If you decide to use OpenGL, you can learn either GLUT (very easy) or SDL (slightly harder) rather than either Carbon or Cocoa. Both GLUT and SDL are cross-platform, and significantly simpler than either Carbon or Cocoa. SDL is specifically targeted at games, and GLUT contains game-specific features.
macphip
2002.07.31, 03:49 PM
so what does it mean, in the page i linked to above, where apple talks about 'objective-c being expanded to support c and c++'? hopefully with OS 10.2 jaguar's release and new developer tools, much new documentation will be introduced. its all so spotty and contradicting at this point.
GoodDoug
2002.07.31, 04:20 PM
To directly interface with Cocoa, you need to use: Objective-C, Java or Objective-C++. So you can do C++ stuff with Cocoa... you just need to do it in Objective-C++ which works just fine.
OneSadCookie
2002.07.31, 04:32 PM
The only languages that Cocoa can be used from are Objective C and Java. However, Objective C is a superset of C, so you can put normal C code into a Cocoa application. You still have to interact with Cocoa using Objective C. With MacOSX 10.1, Apple introduced "Objective C++", which allows you to write both Objective C and C++ code in the same file, just as you could always write Objective C and C code in the same file.
Does that clarify the issue?
macphip
2002.07.31, 08:26 PM
sorry to be a bother..
ABOUT LANGUAGES:
so i can run regular c, c++, and objective c++ code inside of a cocoa application, and without juming through hoops to boot--but cocoa calls themselves must be made in objective-c, right?
then i want to learn cocoa! can anyone recommend a good cocoa book?
ABOUT GRAPHICS:
obviously, a 3rd-party graphics API will be simpler, making the application more portable. plus..apple's API's are never simple
what is the best API for 2D graphics game programming, in everyone's opinion?
* quickdraw in carbon (not supported in cocoa, right?)
* quartz 2d in carbon or cocoa
* openGL w/ GLUT or SDL
* quesa
* something else?
does it even make sence to use openGL for 2d?
OneSadCookie
2002.07.31, 09:03 PM
You're right about the language thing. I'm (pretty successfully) learning Cocoa from the Apple tutorials and documentation. That's not for the faint of heart, however....
It does indeed make sense to use OpenGL for 2D, and in my opinion it's the only really sensible choice. Why waste your time trying to optimize your graphics in a dedicated 2D API when you could do it in OpenGL and have it run fast enough in the first place?
Some other points:
There are Quartz interfaces in Cocoa and from straight C, but it's entirely independent of Carbon. That doesn't mean you can't use Quartz with Carbon, though.
You can use QuickDraw in Cocoa if you jump through a couple of hoops. Why you'd want to, though, is beyond me ;)
You can use OpenGL with any of Carbon, Cocoa, GLUT, SDL, and any number of other APIs.
macphip
2002.07.31, 10:01 PM
awesome! one last thing, the GLUT site on openGL.org seems quite dated, it doesnt have anything on a mac version. is there another site? yeah, i dont think i can teach mac openGL to myself without some reference site, and GLUT sounds like a good place to start (unless SDL would be better :D )
OneSadCookie
2002.07.31, 10:32 PM
GLUT hasn't changed much in the last goodness knows how long; all the example programs you'll find around the web should still work.
On MacOSX, you have to include <GLUT/glut.h> rather than <GL/glut.h>, and <OpenGL/gl.h> and <OpenGL/glu.h> rather than <GL/gl.h> and <GL/glu.h>. There are a few functions that aren't implemented on the Mac (full screen, game mode, warp pointer).
If you're working with MacOSX GLUT is already installed, just add OpenGL.framework, GLUT.framework and Cocoa.framework to your project. If you're working with MacOS9 GLUT comes with the OpenGL 1.2.1 SDK, along with example projects, &c.
There are GLUT examples in /Developer/Examples on MacOSX and in the OpenGL 1.2.1 SDK for MacOS9.
Mars_999
2002.07.31, 10:41 PM
If your concern is games for Mac OSX learn SDL. Its awesome, and you can do 2D in it without OpenGL if you want to. If you need to do 3D you can use OpenGL in SDL. SDL works with C/C++ and other languages but I don't remember them!! =) SDL handles events and has a timer and all sorts of libs that do cool stuff. I use it and love it. I also use C++ and OpenGL. I use SDL for events and music or sound, and OpenGL for all GFX. I wouldn't learn Cocoa unless you planned on doing apps or making a game that was Cocoa only. SDL runs off of Cocoa anyway, but you don't need to see it since its put away and you can just code in C or C++. HTH =)
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.