棣栧厛錛屽垱寤轟竴涓狢ocoa紿楀彛紼嬪簭錛屾墦寮xib璁捐鐜錛岀偣Window榪涘叆紿楀彛璁捐鐣岄潰
鐒跺悗錛屽湪Object Library涓夋嫨OpenGL View鎷栧埌紿楀彛涓婏細(xì)

鎺ヤ笅鏉ヨ瀹炵幇鎴戜滑鑷繁鐨刅iew銆?br />鏂板緩涓涓狾bjectC class錛屽悕瀛椾負(fù)MyOpenGLView錛屼慨鏀逛唬鐮侊細(xì)
MyOpenGLView.h鏂囦歡錛?br />#import <Cocoa/Cocoa.h>
@interface MyOpenGLView : NSOpenGLView
{
}
-(void) drawRect:(NSRect)dirtyRect;
@end
MyOpenGLView.m
#import "MyOpenGLView.h"
#import <OpenGL/gl.h>
static void drawObjects()
{
glColor3f(1.0f, 0.85f, 0.35f);
glBegin(GL_TRIANGLES);
{
glVertex3f( 0.0, 0.6, 0.0);
glVertex3f( -0.2, -0.3, 0.0);
glVertex3f( 0.2, -0.3 ,0.0);
}
glEnd();
}
@implementation MyOpenGLView
-(void)drawRect:(NSRect)dirtyRect
{
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
drawObjects();
glFlush();
}
@end
鑷畾涔夌殑鎺т歡綾繪湁浜?jiǎn)锛屽湪閫変腑涓婇潰鎷栧埌紿楀彛涓婄殑OpenGL Object錛屽湪Show the Identity Inspector璁劇疆闈㈡澘涓緗叾Custom Class涓篗yOpenGLView銆傚ぇ鍔熷憡鎴愶細(xì)

璺熷湪Windows涓婁嬌鐢∣penGL鐩告瘮錛孋ocoa鏂逛究寰堝銆?img src ="http://www.shnenglu.com/mythma/aggbug/203523.html" width = "1" height = "1" />
]]>