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

whooleytoo

macrumors 604
Original poster
Aug 2, 2002
6,607
716
Cork, Ireland.
I'm starting a new (shareware/downloadware/commericalware/make-a-billionware) project which is going to require quite a lot of 2D graphing work (lots of rectangular/rounded rectangular shapes, with translucency, being resized/reshaped/dragged across the screen, grid displayed in background).

What's the best 2D API for this? The last time I did this kind of work was QuickDraw on MacOS8, and things seem to changed a bit since then. :)

I took a look at Quartz last night and it seemed quite straightforward. OpenGL, I'm guessing, would be more portable, but from my very limited exposure to it it doesn't seem as simple for basic 2D work.

Core Animation I guess would be a good option too, but it limits the target market far too much to be an option.

Anyone with experience in this area?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Quartz is easy (especially with Cocoa and NS* classes). OpenGL is not so easy, but there seem to be a bazillion different libraries for working with OpenGL and making stuff like this, I'd search around. If you're targeting Mac only and you're not writing a game, I'd suggest Quartz. If you want cross platform eventually, use OpenGL (or a library that utilizes it).
 

whooleytoo

macrumors 604
Original poster
Aug 2, 2002
6,607
716
Cork, Ireland.
Thanks!

I ultimately will be taking it cross platform, but don't mind implementing it in a OS-specific language/API/framework. Once I've done the design & data modelling, implementing the UI on another platform should be fairly straightforward anyway, it's not overly complex.

So I'm mostly looking now for an API/framework to quickly implement a UI for prototyping and proofing of the design and behaviour; once I'm happy I could still switch to OpenGL (or whatever) for the final implementation, if need be.

Is there any performance difference between Quartz and OpenGL? Although it's just 2D, there could be quite a lot of these shapes/objects on screen at once.
 

GeeYouEye

macrumors 68000
Dec 9, 2001
1,669
10
State of Denial
Use Quartz, yes. But if you need to buy a book on it, I can't urge enough staying away from Quartz 2D Graphics for Mac OS X Developers by R. Scott Thompson, unless there's a 2nd edition out. Why, you ask? First, because it's replete with minor technical mistakes that could add up. Second, parts of the code samples are glossed over completely, inserted without explanation. Third, because if there was ever a book in need of a copy-editor and proofreader, this is it. Function names are hyphenated and broken across lines, and then the second half of the word is misspelled. Code samples are labeled something like: "Example 3: complete Python source" when there was no example 2, and it's in C. It switches languages at random. Even in code samples, there's line breaks in the middle of function names. For example:
Code:
CGContestAddRect(cgContext, C
     GRectMake(-kHalfSize, -kHalfSize, kHalfSize, kHalfSize));

You get the idea. BTW, if you happen to find a better book, let me know.
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
Hi
I can't say which is the best for your application Quartz or OpenGL, but I think you may actually like/enjoy OpenGL and may not find 2-D that difficult. If you need to mix text with the shapes then that might be a bit problematic, but there would be a few advantages to using OpenGL. An obvious one is speed, but you could also add some eye-candy to your shapes, eg lighting, surface effects etc. You wouldn't need to worry about the rendering ordering of your shapes as this would be handled by OpenGL'S depth buffer. Also, if you think in the future you may want or need to use the 3rd dimension for the user interface, eg add some perspective to the shapes or use a snazzy 'wall' interface, then adopting OpenGL early on would make sense.

But don't listen to me… I like OpenGL too much!

b e n
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Is there any performance difference between Quartz and OpenGL? Although it's just 2D, there could be quite a lot of these shapes/objects on screen at once.

OpenGL will be faster. But it really depends on what you're doing. If you want to give more details on what you'll be doing, feel free :)
 

whooleytoo

macrumors 604
Original poster
Aug 2, 2002
6,607
716
Cork, Ireland.
Use Quartz, yes. But if you need to buy a book on it, I can't urge enough staying away from Quartz 2D Graphics for Mac OS X Developers by R. Scott Thompson, unless there's a 2nd edition out. [snip]
You get the idea. BTW, if you happen to find a better book, let me know.

Cheers for the info. I tend to dive straight in and tinker with the sample code; but considering I'm not very experienced with graphics programming a good book might be a good idea in this case. I'll let you know if I find anything useful

Hi
If you need to mix text with the shapes then that might be a bit problematic, but there would be a few advantages to using OpenGL. An obvious one is speed, but you could also add some eye-candy to your shapes, eg lighting, surface effects etc.

But don't listen to me… I like OpenGL too much!

:) Text is actually a necessity - every object will have a label, and if the object is 'minimised' the text will need to be abbreviated (or disappear) while if the object is 'maximised', more text may be displayed (clipped, of course, to the object bounds). I imagine something like this is possible with any graphics API, but may be more convenient with some. Would that be difficult with OpenGL?

OpenGL will be faster. But it really depends on what you're doing. If you want to give more details on what you'll be doing, feel free :)

Not telling! ;)

(I'm irrationally paranoid about two things - my idea being ripped off; and me spending months putting it together only to find myself being sued by 111 companies who already have identical software and patents to match! :p )

The more I think about it, performance shouldn't be an issue. Although there are many of these objects on screen, they'll all be virtually static unless the user is interacting with them so not a problem. Well, actually all the objects including the grid will be drifting in one direction, but v-e-r-y slowly so it shouldn't matter much.

So, the real benefit of OpenGL would be portability, not really speed. I think.
 

ExoticFish

macrumors 6502a
i've been working on a 2D game and started out using SDL. It's really easy to use and runs on more platforms than you can count. I wanted to add some 3D-ness to the game so I just switched everything over to OpenGL on top of SDL and it was pretty painless and not too difficult. And using SDL you can create text and easily convert it over to be an OpenGL texture (that's my next step).
 

whooleytoo

macrumors 604
Original poster
Aug 2, 2002
6,607
716
Cork, Ireland.
Thanks all!

Editing some text in-situ is necessary, but only for renaming objects so that can easily be done by overlaying a transparent text view, if need be.

Having been playing around with Quartz trying to get a feel of how the UI will look; and I'm struggling to get it looking well. With anti-aliasing the lines are too blurry for my liking, but with anti-aliasing off then curves (such as the rounded corners) look god-awful. I've tried altering the linewidth but it doesn't look great.

Also, I reckon I'll have to draw to off-screen buffers and then put the on-screen UI together layer by layer (i.e. background->grid->object containers->objects->overlay). CGLayer seems the way to do it, but is 10.4 only. That's not a disaster, but I'd like to include 10.3 if I can. Is there a way of drawing offscreen without CGLayers? Never mind this question - I can do this with bitmap contexts. I'll just need to take a look to see how the two approaches compare.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.