iDevGames Forums
Printing OpenGL View in Window - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Printing OpenGL View in Window (/thread-3401.html)



Printing OpenGL View in Window - skyhawk - Mar 21, 2007 10:21 AM

So I have a window with many icons, and within this window I have an openGL view. Like so:
[Image: Picture10.png]

however, when I print it out, I get this:
[Image: pics10-2.png]

My print function is rather simple:
Code:
-(IBAction)printMyWindow:(id)sender;
{
    [[NSApp mainWindow] print:NULL];
}

Any help as to get my OpenGL view to print without biting my upper lip off?


Printing OpenGL View in Window - ThemsAllTook - Mar 21, 2007 10:28 AM

Maybe if you do something like this in the OpenGLView before printing?

Code:
- (void) copyGLToBackingStore {
  NSSize size;
  void * buffer;
  
  [[self openGLContext] makeCurrentContext];
  size = [self bounds].size;
  
  buffer = malloc(size.width * size.height * 4);
  glReadPixels(0, 0, size.width, size.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
  
  [self lockFocus];
  NSDrawBitmap([self bounds], size.width, size.height, 8, 4, 32, (size.width * 4), NO, NO, NSDeviceRGBColorSpace, (const unsigned char **) &buffer);
  [self unlockFocus];
  
  free(buffer);
  
  [[self window] flushWindow];
}



Printing OpenGL View in Window - skyhawk - Mar 21, 2007 10:34 AM

I actually tried that, but it didn't change anything sadly.


Printing OpenGL View in Window - unknown - Mar 21, 2007 02:05 PM

Code:
- (void)print:(id)sender
{
    NSImage * im = [[NSImage alloc] initWithSize:[self bounds].size];
    
// copy the gl contents to the image via what alex said or other method

    NSImageView * imView = [[NSImageView alloc] initWithFrame:[self bounds]];
    [imView setImage: im];
    [imView print:nil];
}