• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to do Blitters in Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to do Blitters in Cocoa


  • Subject: Re: How to do Blitters in Cocoa
  • From: Shawn Erickson <email@hidden>
  • Date: Fri, 17 Oct 2003 15:07:59 -0700

On Friday, October 17, 2003, at 01:37 PM, Lee A Morgan wrote:

Hi all I posted this to the mac-games-dev list and didn't get much help so I figured its pretty close to general app direct pixel access.

What's the "proper" way to do a custom blit in Cocoa (that is not using QuickDraw, OpenGL or Quartz).
In the past when I programmed in Carbon I would simply use QuickDraw to setup two GWorlds then get the base address of them and copy them pixels from one to another. However it doesn't seem to be the Cocoa way of doing this...and thats what I would like to learn.

What I need is a way to setup a few GWorld like buffers to hold a few sprites then a blank buffer to do some custom drawing. Then blit them to the window's buffer. Then I would just tell then window to flush the buffer. I know how to do the blitting; I just need to know how to setup blank buffers and load images into them.

Thanks for all the help.

FYI I can't use OpenGL because its not hardware accelerated on the low end machine I have to support, I can't use Quartz cause its way to slow on even the faster machines and I could use QuickDraw but like I said it I would rather learn the "Cocoa way" of doing this.

In my opinion the proper way to do this is to not bypass what Quartz can do for you (Cocoa's imaging abilities is built on Quartz 2D / QuartzCompositor).

You may want to look this site over... http://www.sugarcubesoftware.com/csk/

Anyway you likely want to consider NSImage and NSBitmapImageRep. If read over this page [1] you can get an idea of how to create a NSBitmapImageRep if you need to draw its content dynamically or of course it can be loaded in from a already rendered image stored in a supported format. However using NSImage directly should generally be sufficient in this case.

So assuming you generate an NSImage that contains the sprite tiles in it you likely want to get the NSBitmapImageRep cached (the prior page outlines how to do that as well) in off an screen window. This window will be managed by the QuartzCompositor and hence benefit from QuartzExtreme. Then use NSImage's compositeToPoint:fromRect:operation: or compositeToPoint:fromRect:operation:fraction: to do the drawing of sprite tiles. On systems that support QE the video hardware should do the blitting for you going from vram to vram (not 100% sure about this) and on none QE system it will used an appropriately optimized blitter.

At least that is my rough understanding.

Just make sure clip your frame rate to something reasonable like 30 or 60 fps.

-Shawn

[1] http://developer.apple.com/documentation/Cocoa/Conceptual/DrawImages/ Tasks/CachingRepresentations.html#//apple_ref/doc/uid/20000816
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >How to do Blitters in Cocoa (From: Lee A Morgan <email@hidden>)

  • Prev by Date: Re: How to do Blitters in Cocoa
  • Next by Date: OpenGL Nurbs Surface/Dynamic Multi-Dimensional C Arrays Questions
  • Previous by thread: Re: How to do Blitters in Cocoa
  • Next by thread: OpenGL Nurbs Surface/Dynamic Multi-Dimensional C Arrays Questions
  • Index(es):
    • Date
    • Thread