2D Graphics question...

Post: #1
Hi all,

I've done quite a bit of 2D sprite-based programming in the past, and now I'm working on updating the code (making it OSX-compatible, etc.). I've read Mark S.'s book, which includes carbonized code but doesn't discuss custom blitting, so I'm not sure if my old approach (moving data manually using the gworld base address and rowbytes) still applies in Carbon/OSX. Also, I'm wondering if there are better approaches I should consider, such as using CopyBits or OpenGL to take advantage of hardware acceleration.

Basically, I'm wondering what is the best way to handle 2D sprite-based graphics in the Carbon/OSX environment.

Thanks very much for any input.
Quote this message in a reply
Post: #2
I would consider using OpenGL. It is very fast, hardware accelerated, und gives you scaling/rotating for free.
Quote this message in a reply
Posts: 201
Joined: 2002.06
Post: #3
OpenGL would be the fastest blitter, but CopyBits would probably be easier for you to add into your code because it sounds like you are porting a Classic app, correct?
Quote this message in a reply
Posts: 268
Joined: 2005.04
Post: #4
Your custom blitter will still work in Carbon code, so if you're just porting a classic app that's the way to go. But if you're writing a new app, I'd go with OpenGL, as it'll be way faster if the computer has hardware acceleration. You could also add CopyBits as an option to your app that uses a custom blitter, as it uses the same data format and is accelerated (right?).
Quote this message in a reply
Post: #5
Check out SpriteWorld's BlitPixie:
It runs about 50% faster than CopyBits() using the SpriteWorld 3 test application on my eMac. Maybe if the video card was better than a GeForce2MX CopyBits() with it's hardware acceleration would be better, but since most people don't have the latest card BlitPixie will be faster overall, I think.
Quote this message in a reply
Posts: 869
Joined: 2003.01
Post: #6
Well, you are forgetting about all the nifty things you get with OpenGL, such as free transparency, rotation, zooming, image filtering. Plus, you always have the option of replacing your sprites with actual 3D models with a little effort when the time has come for it.

And it is probably no harder to do than writing a blitter. Been there. And I believe Apple has some sample code about doing this in Cocoa, but the usual NeHe infusion should help, as with all OpenGL.
Quote this message in a reply
Post: #7
Thanks for the feedback. I'm building my 3D engine in OpenGL, of course, but hadn't thought of using it for 2D also. I assume you just use glRasterPos(), glDrawPixels(), etc. Or is it better to use glOrtho2D() and render polygons with the graphics mapped to them?

For creating a fullscreen context and changing the color depth of the screen, I gather you have to use DrawSprocket, unless you're in OSX, in which case you can use AGL. Am I correct about that?

Thanks for all the info. I think with the above questions answered I'll be all set.
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #8
Use glOrtho and textured polygons. That way your pixel data (sprites, tiles, whatever) gets stored in VRAM, which is way fast Smile

DrawSprocket for full-screen & res switching on Mac OS 9 or Mac OS X, AGL or CGDirectDisplay for Mac OS X only.
Quote this message in a reply
Post Reply