• 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
Is there anything pathological with the following NSView simple subclass?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Halting a cocoa application?
  • Next by Date: Re: How many times will a sub-classed NSView be instantiated in a simple Cocoa App?
  • Previous by thread: Re: Halting a cocoa application?
  • Next by thread: unwanted tooltip in NSOutlineView (as "outLineTableColumn")
  • Index(es):
    • Date
    • Thread