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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to