oc-opengl
#import <Cocoa/Cocoa.h> #import <OpenGL/OpenGL.h> #import <OpenGL/gl3.h> @interface OpenGLView : NSOpenGLView @end @implementation OpenGLView -(id)initWithFrame:(NSRect)frameRect { self = [super initWithFrame:frameRect]; return self; } -(void)drawRect:(NSRect)dirtyRect { glClearColor(1.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glFlush(); } @end @interface MyDele : NSObject<NSApplicationDelegate> @end @implementation MyDele -(void) applicationDidFinishLaunching:(NSNotification *)notification { NSRect rect = NSMakeRect(35, 35, 1024, 800); NSWindowStyleMask style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskResizable; NSWindow * window = [[NSWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:YES]; OpenGLView * view = [[OpenGLView alloc] initWithFrame:rect]; [window setContentView:view]; [NSApp beginModalSessionForWindow:window]; } -(BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { return TRUE; } @end int main(int argc, const char ** argv) { @autoreleasepool { MyDele * del = [[MyDele alloc] init]; [[NSApplication sharedApplication] setDelegate: del]; NSApplicationMain(argc, argv); } }