Re: NSOpenGLContext and window re-opening
Re: NSOpenGLContext and window re-opening
- Subject: Re: NSOpenGLContext and window re-opening
- From: publiclook <email@hidden>
- Date: Fri, 25 Apr 2003 18:58:00 -0400
I seem to recall answering this question before, but if you searched
the archives and didn't find it, my memory must be faulty.
I use the following implementation of the -reshape method and it
handles view resizing, scaling via NSView bounds manipulation, as well
as window unhide:
- (void)reshape
/*" Sets the receiver's viewport and coordinate system to reflect
changes to the visible portion of the view "*/
{
NSRect visibleRect = [self visibleRect];
NSRect superVisibleRect = visibleRect;
// Conversion captures any scaling in effect
superVisibleRect = [self convertRect:superVisibleRect toView:[self
superview]];
[[self openGLContext] makeCurrentContext];
// Setup some basic OpenGL stuff
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glClearColor(0.0, 0.0, 0.0, 1.0);
glColor4f(1.0, 1.0, 1.0, 1.0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_TEXTURE_RECTANGLE_EXT);
glEnable(GL_TEXTURE_2D);
// Optimization: discard texture pixels that are too transparent
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.05);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// reset the viewport to new dimensions
glViewport(0, 0, superVisibleRect.size.width,
superVisibleRect.size.height);
glOrtho(NSMinX(visibleRect), NSMaxX(visibleRect), NSMinY(visibleRect),
NSMaxY(visibleRect), -1.0, 1.0);
[self setNeedsDisplay:YES];
}
I implement -initWithFrame:pixelFormat: to call -reshape. The -reshape
method seems to be called automatically whenever necessary after that.
- (id)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat
*)pixFmt
/*" Designated initializer "*/
{
self = [super initWithFrame:frameRect pixelFormat:pixFmt];
[self reshape];
return self;
}
This code enables my subclass of NSOpenGLView to work correctly inside
a scroll view even if the document view of the scroll view is resized
or scaled.
On Friday, April 25, 2003, at 12:36 PM, Cedric Vuillet wrote:
I have a big problem with an OpenGl context in an NSWindow.
When I open the window with the OpenGL view, it works great, but when
I close and re-open the window, the OpenGL view is white and doesn't
draw anything.
Do you know what is the problem?
What can I do to resolve this problem?
I tried makeCurrentContext but it does not work at all.
I think this is a known problem because I have seen the same in other
forums, but there is no response...
What can I do?
--
adnX__________________________
Ingenierie / developpement Mac
Cedric Vuillet
______________________________
Standard : 04 72 13 24 14
Ligne directe : 04 76 15 33 09
_______________________________________________
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.