View Full Version : need help understanding cocoa code
Byron Clarke
2005.06.25, 08:46 PM
fullScreenGLContext =
[[NSOpenGLContext alloc] initWithFormat:fullScreenPixelFormat
shareContext:[self openGLContext]];
lisa "can I sit here"
comic store owner "yes, but only if you answer me these questions three!"
If I'm understanding this correctly, this first allocates memory for a new NSOpenGLContext object, then it is initiated with the pixelformat defined by fullScreenPixelFormat and finally is shared with the current context?
I'm still trying to wrap my head around the concept (or rather implementing) of objects, classes, allocating memory, messaging.
OneSadCookie
2005.06.25, 09:28 PM
basically, you're right.
-initWithPixelFormat:shareContext: is one operation.
it's shared with the current object's GL context, rather than the current context. I'd guess that the current object is an NSOpenGLView of some kind.
Byron Clarke
2005.06.26, 04:05 PM
I get tons of errors when I try to compile this, How do I gain access to CG methods? Common sense says that their should be a framework to import, but I can't find any CG headers.
-(IBAction)fadeOut:(id)sender
{
CGSetDisplayTransferByFormula(gCGDisplayID,
&gGammaRedMin,
&gGammaRedMax * 0.5f,
&gGammaRedGamma,
&gGammaGreenMin,
&gGammaGreenMax * 0.5f,
&gGammaGreenGamma,
&gGammaBlueMin,
&gGammaBlueMax * 0.5f,
&gGammaBlueGamma);
}
Taxxodium
2005.06.26, 04:49 PM
Import the Quartz.framework. And by importing I mean add it to your project and use the #import thingy
OneSadCookie
2005.06.26, 06:10 PM
wrong.
Just #include <ApplicationServices/ApplicationServices.h>
no need to add any additional frameworks if you've already got Cocoa.
Byron Clarke
2005.06.26, 06:21 PM
Implementation of Step1View
#import "Step1View.h"
#import <OpenGL/gl.h>
#import <ApplicationServices/ApplicationServices.h>
@implementation Step1View
-(id)initWithFrame:(NSRect)frameRect
{
CGGetDisplayTransferByFormula(gCGDisplayID,
&gGammaRedMin,
&gGammaRedMax,
&gGammaRedGamma,
&gGammaGreenMin,
&gGammaGreenMax,
&gGammaGreenGamma,
&gGammaBlueMin,
&gGammaBlueMax,
&gGammaBlueGamma);
gGammaBrightness = 1.0;
NSOpenGLPixelFormatAttribute MyAttributes[] =
{
NSOpenGLPFAWindow,
NSOpenGLPFASingleRenderer,
NSOpenGLPFANoRecovery,
NSOpenGLPFAScreenMask,
CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDispla y),
NSOpenGLPFADoubleBuffer,
0
};
NSOpenGLPixelFormat* pixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:MyAttributes];
if (pixelFormat == nil)
{
return nil;
}
[pixelFormat autorelease];
MyAttributes[0] = NSOpenGLPFAFullScreen;
NSOpenGLPixelFormat* fullScreenPixelFormat =
[[NSOpenGLPixelFormat alloc] initWithAttributes:MyAttributes];
if (fullScreenPixelFormat == nil)
{
return nil;
}
[fullScreenPixelFormat autorelease];
self = [super initWithFrame:frameRect pixelFormat:pixelFormat];
if (self == nil)
{
return nil;
}
fullScreenGLContext =
[[NSOpenGLContext alloc] initWithFormat:fullScreenPixelFormat
shareContext:[self openGLContext]];
if (fullScreenGLContext == nil)
{
[self dealloc];
return nil;
}
fullScreen = NO;
[NSTimer scheduledTimerWithTimeInterval:0.001
target:self
selector:@selector(drawRect:)
userInfo:nil
repeats:YES];
return self;
}
- (void)dealloc
{
[fullScreenGLContext release];
}
-(void)drawRect:(NSRect)rect
{
glClear(GL_COLOR_BUFFER_BIT);
glRotatef(0.1f, 0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glVertex2f(-0.75f, -0.75f);
glVertex2f( 0.75f, -0.75f);
glVertex2f( 0.75f, 0.75f);
glVertex2f(-0.75f, 0.75f);
glEnd();
[[NSOpenGLContext currentContext] flushBuffer];
}
-(IBAction)toggleFullScreen:(id)sender
{
if(fullScreen)
{
[fullScreenGLContext clearDrawable];
[[self openGLContext] makeCurrentContext];
CGReleaseAllDisplays();
fullScreen = NO;
}
else
{
CGCaptureAllDisplays();
[fullScreenGLContext setFullScreen];
[fullScreenGLContext makeCurrentContext];
fullScreen = YES;
}
}
-(IBAction)fadeOut:(id)sender
{
CGSetDisplayTransferByFormula(gCGDisplayID,
&gGammaRedMin,
&gGammaRedMax * 0.5f,
&gGammaRedGamma,
&gGammaGreenMin,
&gGammaGreenMax * 0.5f,
&gGammaGreenGamma,
&gGammaBlueMin,
&gGammaBlueMax * 0.5f,
&gGammaBlueGamma);
}
@end
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.