Printing OpenGL View in Window

Moderator
Posts: 916
Joined: 2002.10
Post: #1
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?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
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];
}
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #3
I actually tried that, but it didn't change anything sadly.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
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];
}

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL view first frame flickers garbage mk12 8 6,614 Sep 4, 2010 06:06 PM
Last Post: mk12
  When to create custom OpenGL view instead of subclass NSOpenGL view Coyote 37 21,791 Oct 20, 2009 08:16 PM
Last Post: Coyote
  How do I place all of my UI elements to be subviews of another view/window? xenocide 2 2,725 Feb 1, 2009 08:32 PM
Last Post: xenocide
  opengl view question Leroy 3 3,236 Jul 23, 2007 11:08 PM
Last Post: AnotherJake
  Porting SDL to Cocoa OpenGL view--texture problem smittyz 7 5,054 Jul 21, 2007 07:53 PM
Last Post: smittyz