2012-07-22 13 views
6

मैं NSOpenGLView के कस्टम कार्यान्वयन में कोर प्रोफाइल कैसे बनाऊंगा? मुझे किस विधि को ओवरराइड करना चाहिए और मुझे किस कोड को रखना चाहिए?ओपनजीएल 3.2 डब्ल्यू/NSOpenGLView

अब तक मैं इस कोड है:

// Header File 
#import <Cocoa/Cocoa.h> 

@interface TCUOpenGLView : NSOpenGLView 

@end 

// Source File 
#import "TCUOpenGLView.h" 
#import <OpenGL/gl.h> 

@implementation TCUOpenGLView 

- (void)drawRect:(NSRect)dirtyRect { 
    glClear(GL_COLOR_BUFFER_BIT); 
    glFlush(); 
} 

@end 

उत्तर

10

एप्पल एक नमूना कोड GLEssentials बुलाया परियोजना से पता चलता है कि वास्तव में ऐसा करने के तरीके (ध्यान दें कि यह एक मैक ओएस एक्स और iOS नमूना कोड परियोजना है) है।

अनिवार्य रूप से आप उपयोग कर awakeFromNib तरीका लागू NSOpenGLView (नमूना कोड में NSGLView वर्ग) उपवर्ग करने की आवश्यकता होगी और निम्नलिखित:

- (void) awakeFromNib 
{ 
    NSOpenGLPixelFormatAttribute attrs[] = 
    { 
     NSOpenGLPFADoubleBuffer, 
     NSOpenGLPFADepthSize, 24, 
     // Must specify the 3.2 Core Profile to use OpenGL 3.2 
     NSOpenGLPFAOpenGLProfile, 
     NSOpenGLProfileVersion3_2Core, 
     0 
    }; 

    NSOpenGLPixelFormat *pf = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs] autorelease]; 

    if (!pf) 
    { 
     NSLog(@"No OpenGL pixel format"); 
    } 

    NSOpenGLContext* context = [[[NSOpenGLContext alloc] initWithFormat:pf shareContext:nil] autorelease]; 

    [self setPixelFormat:pf]; 

    [self setOpenGLContext:context]; 
} 

भी याद रखें कि यदि आप उस हटा दिया गया है किसी भी ओपन API कॉल का उपयोग 3.2 एपीआई से आपका ऐप क्रैश हो जाएगा। यहां 3.2 spec का PDF document है ताकि आप परिवर्तन देख सकें।