• 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: NSOpenGLView and resizable NSWindow problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: NSOpenGLView and resizable NSWindow problem


  • Subject: RE: NSOpenGLView and resizable NSWindow problem
  • From: "Werner Sharp" <email@hidden>
  • Date: Tue, 31 Oct 2006 13:12:49 -0800
  • Thread-topic: NSOpenGLView and resizable NSWindow problem

Thanks for the quick reply.

I compared the differences and isolated it down to one tiny bit.  If I
add this...

- (void) reshape
{
	[[self openGLContext] update];
}

...then my subclass of NSOpenGLView works correctly.

I get white flickering in both versions when I drag the window under the
dock sometimes.  I'm not sure why that is.

-Werner

-----Original Message-----
From: cocoa-dev-bounces+wsharp=email@hidden
[mailto:cocoa-dev-bounces+wsharp=email@hidden] On Behalf Of
Simone Tellini
Sent: Tuesday, October 31, 2006 11:51 AM
To: email@hidden
Subject: Re: NSOpenGLView and resizable NSWindow problem


On Tue, 31 Oct 2006 11:21:48 -0800
"Werner Sharp" <email@hidden> wrote:

WS> I'm trying to programmatically create a NSOpenGLView inside a
NSWindow
WS> and I'm having trouble getting the NSOpenGLView to correct resize.
This

I had the same problem (plus others) with NSOpenGLView. Eventually, I
ditched it and subclassed NSView with the following code:

//--------------------------------------------------------------------
- (id)initWithFrame: (NSRect)frameRect
{
    static NSOpenGLPixelFormatAttribute attrs[] =
	{
        NSOpenGLPFANoRecovery,
		NSOpenGLPFAWindow,
        NSOpenGLPFAColorSize,
(NSOpenGLPixelFormatAttribute)24,
        NSOpenGLPFADepthSize,
(NSOpenGLPixelFormatAttribute)16,
        NSOpenGLPFADoubleBuffer,
        NSOpenGLPFAAccelerated,
		NSOpenGLPFASampleBuffers,
(NSOpenGLPixelFormatAttribute)1,
		NSOpenGLPFASamples,
(NSOpenGLPixelFormatAttribute)4,
        (NSOpenGLPixelFormatAttribute)0
    };

    self = [super initWithFrame: frameRect];

    if( self ) {
		NSNotificationCenter *nc = [NSNotificationCenter
defaultCenter];

		pixelFormat = [[NSOpenGLPixelFormat alloc]
initWithAttributes: attrs];
		glContext   = [[NSOpenGLContext alloc] initWithFormat:
pixelFormat shareContext: nil];

		[nc addObserver: self
			   selector: @selector( reshape )
				   name:
NSViewFrameDidChangeNotification
				 object: self];

		ready  = NO;
    }

    return( self );
}
//--------------------------------------------------------------------
- (void)dealloc
{
	[[NSNotificationCenter defaultCenter] removeObserver: self];

	[glContext release];
	[pixelFormat release];
	[super dealloc];
}
//--------------------------------------------------------------------
- (BOOL)isOpaque
{
	return( YES );
}
//--------------------------------------------------------------------
- (BOOL)isFlipped
{
	return( YES );
}
//--------------------------------------------------------------------
- (void)reshape
{
	NSSize	size = [self frame].size;
	BOOL	setCtx = [NSOpenGLContext currentContext] != glContext;

	[glContext update];

	if( setCtx )
		[glContext makeCurrentContext];

	glViewport( 0, 0, (GLint) size.width, (GLint) size.height );

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();

	gluPerspective( 40.0, size.width / size.height, 1.0f, 1000.0f );

	if( setCtx )
		[NSOpenGLContext clearCurrentContext];
}
//--------------------------------------------------------------------
- (void)drawRect: (NSRect) rect
{
	[glContext setView: self];
	[glContext makeCurrentContext];

	if( !ready ) {

		// here I call a method to create some glLists, etc...
		[self reshape];

		ready = YES;
	}

	// render the scene

	[glContext flushBuffer];

	[NSOpenGLContext clearCurrentContext];
}
//----------------------------------------------------------------------
-----


So far this solution seems to work well. It also proved a lot easier
than getting NSOpenGLView to work as it should ;-)

Any improvement is welcome.

--
Simone Tellini
http://tellini.info

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: NSOpenGLView and resizable NSWindow problem (From: Simone Tellini <email@hidden>)

  • Prev by Date: Re: sort, cut and paste
  • Next by Date: Re: Can you populate an NSTableView with an NSEnumerator?
  • Previous by thread: Re: NSOpenGLView and resizable NSWindow problem
  • Next by thread: Display a NSView under another NSView
  • Index(es):
    • Date
    • Thread