2D Graphics question... - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: 2D Graphics question... (/thread-6945.html)
2D Graphics question... - Jesse - Jul 6, 2003 12:56 PM
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.
2D Graphics question... - mutle - Jul 6, 2003 01:41 PM
I would consider using OpenGL. It is very fast, hardware accelerated, und gives you scaling/rotating for free.
2D Graphics question... - geezusfreeek - Jul 6, 2003 03:38 PM
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?
2D Graphics question... - Bachus - Jul 6, 2003 03:56 PM
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?).
2D Graphics question... - Patrick - Jul 6, 2003 04:02 PM
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.
2D Graphics question... - DoG - Jul 6, 2003 04:17 PM
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.
2D Graphics question... - Jesse - Jul 6, 2003 08:18 PM
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.
2D Graphics question... - OneSadCookie - Jul 6, 2003 08:44 PM
Use glOrtho and textured polygons. That way your pixel data (sprites, tiles, whatever) gets stored in VRAM, which is way fast
DrawSprocket for full-screen & res switching on Mac OS 9 or Mac OS X, AGL or CGDirectDisplay for Mac OS X only.