View Full Version : Using Carbon API in Cocoa Apps
geezusfreeek
2002.06.10, 11:37 AM
I'm pretty new to the whole Cocoa thing. I want to use Quickdraw in my Cocoa application. How do I do this? From what I've read, Quickdraw is the only graphics API on Mac OS X with decent speeds.
wadesworld
2002.06.10, 12:00 PM
Link in the Carbon framework and call the Carbon functions. Carbon is fully-available to Cocoa apps.
Wade
geezusfreeek
2002.06.10, 01:12 PM
That's it? Just link it? Man, and here I was thinking that I had to do some other special modification in Project Builder or something. Thanks!
jefftkd
2002.06.10, 01:32 PM
If you want to use Interface Builder and Quickdraw, just use the NSQuickdrawView (icon like the Finder) control.
Just overwrite drawRect and do all your drawing in there. There is a nice method (qdPort) so you can do:
- (void)drawRect: (NSRect)rect {
GrafPort *g = [self qdPort];
/* Use g just like normal */
}
HTH,
Jeff :cool:
geezusfreeek
2002.06.10, 01:37 PM
Ah, thank you thank you thank you! That's what I was looking for! I just didn't know how to word it.
Jeff Binder
2002.06.10, 05:15 PM
Originally posted by geezusfreeek
From what I've read, Quickdraw is the only graphics API on Mac OS X with decent speeds.
Don't forget OpenGL :-) .
geezusfreeek
2002.06.10, 05:31 PM
Oh ya. But I don't have any OpenGL experience anyway. I'll learn it eventually.
geezusfreeek
2002.06.10, 05:40 PM
I just stumbled across some CoreGraphics stuff. How does this compare to QuickDraw and OpenGL, as far as speed goes? It looks easy. Is it related to Quartz in some way?
OneSadCookie
2002.06.10, 07:07 PM
CoreGraphics is Quartz.
geezusfreeek
2002.06.10, 08:02 PM
Okay. There's the sign of a beginner for you. ;)
Chris Burkhardt
2002.06.10, 08:17 PM
Isn't CoreGraphics a lower level API that Quartz is based on (Quartz calls CG functions)?
geezusfreeek
2002.06.10, 08:24 PM
That's what I was thinking (and hoping).
OneSadCookie
2002.06.10, 08:31 PM
I imagine that the Cocoa drawing routines may well call the CoreGraphics functions, in which case calling the CG stuff directly may be slightly faster.
Anyone care to benchmark?
Feanor
2002.06.11, 01:00 AM
CoreGraphics and Quartz are exactly alike. There are no "Quartz" functions, that's just the marketing name Steve came up with. Uh, not me, but I'm sure you're right -- you call the method, the AppKit calls the CGfunction equivalent.
The idea that QuickDraw is faster than Quartz seems absurd, but I guess its possible. I was under the impression that QuickDraw just called CoreGraphics equivalents. Now, stuff like bezier paths and all that fancy PDF stuff is going to be slow, sure, but the usual bit copy stuff should be faster in OS X. But I'm not much for 2D. You all may as well learn OpenGL because that's the future on OS X starting with Jaguar. EVERYTHING you see on screen ends up as OpenGL from now on. You may as well cut to the chase.
For those who like to troll around Apple's documentation pages online, there has recently appeared a programming topic entitled "Drawing Directly to the Screen" -- description forthcoming (of course!). Hopefully a new API in Jaguar?
OneSadCookie
2002.06.11, 02:21 AM
You can already get direct access to the screen buffer memory using CGDirectDisplay...
I wonder whether any of the blitting routines on OS X < 10.2 are hardware accelerated at all... given that they must all composite from in-memory buffers to in-memory buffers, I'd guess the CPU is the fastest way.
QuickDraw doesn't call into Quartz in any way AFAIK... I'm pretty sure all the Quartz stuff does anti-aliasing and deals with fractional coordinates and things, none of which QuickDraw has to deal with. I suspect most of QuickDraw is still the same code that ran on your Mac 128K :)
geezusfreeek
2002.06.11, 11:01 AM
Do you use CGDirectDisply to get an address to the main screen itself, or to a buffer that you can then blit over?
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.