Re: Advice on offscreen drawing.
Re: Advice on offscreen drawing.
- Subject: Re: Advice on offscreen drawing.
- From: "Erik M. Buck" <email@hidden>
- Date: Thu, 14 Mar 2002 09:50:58 -0600
In addition to the excellent example provided by Dennis below, another
technique is to use OpenGL. OpenGL works nicely plain with RGBA 32 bit
data.
Inside the drawRect: method of an OpenGLView subclass, use the following
code"
glRasterPos2i(0, 0); // specify the position to draw the bitmap
glPixelZoom(1.0, 1.0); // specify no scaling
// pixelData is a pointer to imageWidth * imageHeight * 32 bit pixel data.
glDrawPixels(imageWidth, imageHeight, GL_RGBA, pixelData);
// (I didn't compile this so there might be some mistakes.)
----- Original Message -----
From: "Dennis De Mars" <email@hidden>
>
>
- (NSImage*)imageFromPixmap:(UInt32*)pixmapData width:(int)pixmapWidth
>
height:(int)pixmapHeight
>
{
>
>
NSBitmapImageRep* bitmap;
>
unsigned char* pixels;
>
NSImage* theImage;
>
bitmap = [[NSBitmapImageRep alloc]
>
initWithBitmapDataPlanes: NULL // Let the class allocate
>
it
>
pixelsWide: pixmapWidth
>
pixelsHigh: pixmapHeight
>
bitsPerSample: 8 // Each component is 8
>
bits (one byte)
>
samplesPerPixel: 4 // Number of components (R, G,
>
B, alpha)
>
hasAlpha: YES
>
isPlanar: NO
>
colorSpaceName: NSDeviceRGBColorSpace
>
bytesPerRow: 0 // 0 means: Let the class figure it out
>
bitsPerPixel: 0 // 0 means: Let the class
>
figure it out
>
];
>
>
pixels = [bitmap bitmapData];
>
memcpy(pixels, pixMapData, pixmapHeight* pixmapWidth*sizeof(UInt32));
>
theImage = [[NSImage alloc] initWithSize: imageSize];
>
[theImage addRepresentation: bitmap];
>
>
return theImage;
>
}
>
>
(I didn't compile this so there might be some mistakes.)
_______________________________________________
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.