views:

456

answers:

2

I made a scrolling tile 2D video game in visual basic a few years back. I am translating it to Cocoa for the Mac. Is there a framework that would allow me to use BitBlt? Or is there an equivalent to BitBlt without using OpenGL? Thanks!

+2  A: 

You should probably start with Core Graphics

Azeem.Butt
Within that, the closest to a bit blitter equivalent is the CGContextDrawLayerAtPoint function used in the myDrawFlag example code. See:http://developer.apple.com/mac/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_layers/dq_layers.html#//apple_ref/doc/uid/TP30001066-CH219-TPXREF101
Matt Gallagher
thanks! I'm pretty sure that doesn't allow you to copy from one image... what is black (and not white) in the other image (it's vector mask). It seems to be very helpful for copying tiles or rects and snippets of images that you create, but not copying existing files that are preloaded as an NSImage in Objective-C/Cocoa... and certainly not copying those images based on its vector mask. Correct me if I am wrong about that, though.
Brian
You can draw images directly into a CGLayer. You can also mask when you do this. You don't have to use a CGLayer though (it's just fastest because it caches on the graphics card). If you want actual blend modes, you need to use CGContextSetBlendMode and CGContextDrawImage.
Matt Gallagher
+1  A: 

As Matt mentioned, you probably want CGContextDrawImage and CGContextSetBlendMode.

First, you need to create a CGImageRef from the image data. You do this with a data provider. If you already have the image loaded in memory, then you should use CGDataProviderCreateDirect. That data provider will be a parameter to CGImageCreate.

Next, in your Cocoa view's drawRect: method, you'll want to get the current context like this: CGContextRef cgContext = [[NSGraphicsContext currentContext] graphicsPort];

Then use CGContextDrawImage to draw the image.

As Matt mentioned, you can control blending with CGContextSetBlendMode.

Doug Richardson