• 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: OpenGL printing/image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OpenGL printing/image


  • Subject: Re: OpenGL printing/image
  • From: Charles Brokaw <email@hidden>
  • Date: Wed, 15 Jan 2003 09:03:38 -0800

This works for me, but there may be an easier way:
Hope this helps.

- (NSData*)makeTIFFFromThisView{
unsigned char* planes[1];
unsigned int length;
NSImage* image;
NSBitmapImageRep* bitmap;
NSSize size; // these are float values.
NSMutableData* buffer;

size.width = _myglWidth;
size.height = _myglHeight;
length = (unsigned int)(size.height*size.width*3);

buffer= [NSMutableData dataWithLength :length];

glReadBuffer(GL_BACK);
glPixelStorei(GL_PACK_ALIGNMENT, 4); // force 4 byte alignment
glReadPixels(0, 0, _myglWidth, _myglHeight, GL_RGB, GL_UNSIGNED_BYTE,
[buffer mutableBytes]);
planes[0] = (unsigned char*)[buffer mutableBytes]; // illegal conversion from NSMutableData to unsigned int

bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes :planes
pixelsWide :_myglWidth
pixelsHigh :_myglHeight
bitsPerSample :8
samplesPerPixel :3
hasAlpha :NO
isPlanar :NO
colorSpaceName :NSDeviceRGBColorSpace
bytesPerRow :(_myglWidth*3)
bitsPerPixel :24];
image = [[NSImage alloc] initWithSize :size];
[image setFlipped :YES];
[image lockFocus];
[bitmap drawInRect :NSMakeRect(0, 0, size.width, size.height)];
[image unlockFocus];

return [image TIFFRepresentation];
}
- (void)savePanelDidEnd :(NSSavePanel*) sheet
returnCode :(int)returnCode
contextInfo :(void*)contextInfo{
NSData* viewTIFF;

if(returnCode ==0) return; // User did not click OK

[[self OGLview] setNeedsDisplay :YES]; // make sure view is up to date
viewTIFF=[[self OGLview] makeTIFFFromThisView];

if([viewTIFF writeToFile :[sheet filename] atomically :NO]==NO){
NSRunAlertPanel(nil, @"Cannot save file '%@' : %s",nil,nil,nil,
[sheet filename], strerror(errno));
}
// [viewTIFF release];
}
On Wednesday, January 15, 2003, at 04:42 AM, Simon Bovet wrote:

Has anyone tried to print an NSOpenGLView, or make an NSImage from it? It's surely easy, but if someone has a ready-made solution, it could spare me some time!

So thanks for any help!
Simon
_______________________________________________
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: ANN: Rainjul Open Sources WebObjects-Based Aizai Channel Server
  • Next by Date: Re: NSProxy
  • Previous by thread: Re: OpenGL printing/image
  • Next by thread: Getting Processor Usage
  • Index(es):
    • Date
    • Thread