• 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
Fwd: Advice on offscreen drawing.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Advice on offscreen drawing.


  • Subject: Fwd: Advice on offscreen drawing.
  • From: Oscar Morales Vivó <email@hidden>
  • Date: Sun, 17 Mar 2002 23:01:24 +0100

That's something I would be interested, as I would like to use the NSOpenGLView class in the near future to render previews of the scene to be raytraced. It also seems it would be a very easily portable solution and one that doesn't do a lot of data copying around. Are there any code examples and/or use guides for that class?

Just one minor performance question (not like it really matters for a raytracer, but...). Is the glDrawPixels function fully optimized for the common no scaling case? Just want to know if it would do a simple blitting in that case...

Thanks a lot for your help:

Oscar Morales.

On Thursday, March 14, 2002, at 04:50 PM, Erik M. Buck wrote:

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.
_______________________________________________
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.

  • Prev by Date: Re: How to use a subclass of NSTextView inside a NSScrollView?
  • Next by Date: Solved :) Re: abstract object of class NSCFDictionary?
  • Previous by thread: Re: Advice on offscreen drawing.
  • Next by thread: Adding drawer
  • Index(es):
    • Date
    • Thread