Is there anything pathological with the following NSView simple subclass?
Is there anything pathological with the following NSView simple subclass?
- Subject: Is there anything pathological with the following NSView simple subclass?
- From: Graham Reitz <email@hidden>
- Date: Sat, 24 May 2008 19:22:15 -0500
I am endeavoring to learn openGL gui development on the Mac.
Any comments on the follow code would be greatly appreciated, i.e.
what's wrong, pathological and etc...
thanks,
graham
----Code---
// simple.h
#import <Cocoa/Cocoa.h>
@interface simple : NSView
{
@private
NSOpenGLContext *m_context;
NSOpenGLPixelFormat *m_pixel_format;
}
@end
// simple.m
#import "simple.h"
@implementation simple
- (id)initWithFrame:(NSRect)frameRect
{
if ((self = [super initWithFrame:frameRect]) != nil)
{
NSOpenGLPixelFormatAttribute attributes[] =
{
NSOpenGLPFAWindow,
NSOpenGLPFAAccelerated,
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAColorSize, 24,
NSOpenGLPFAAlphaSize, 8,
NSOpenGLPFADepthSize, 24,
NSOpenGLPFAMinimumPolicy, 0
};
if (m_pixel_format =
[[NSOpenGLPixelFormat alloc]
initWithAttributes:attributes])
{
// Create the openGL context
if (m_context = [[NSOpenGLContext alloc]
initWithFormat:m_pixel_format shareContext:nil])
{
NSLog(@"initWithFrame SUCCESS: OpenGL context
created");
}
else
{
NSLog(@"initWithFrame FAILURE: Unable to create
context");
#warning "Handle error condition?"
}
}
else
{
NSLog(@"initWithFrame FAILURE: Unable to match the
specified pixel format");
#warning "Handle error condition?"
}
}
return self;
}
- (void)lockFocus
{
// ensure we are ready to draw
[ super lockFocus ];
[m_context setView:self];
[m_context makeCurrentContext];
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden