1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <OpenGL/glext.h>
@interface MyView : NSOpenGLView
{
}
@end
@implementation MyView
- (id)initWithFrame:(NSRect)frame
{
const NSOpenGLPixelFormatAttribute attrs[] = { 0 };
return [super initWithFrame:frame pixelFormat:[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs]];
}
- (void)drawRect:(NSRect)rect
{
// your OpenGL commands here
}
@end
MyView *createWindow(float x, float y, float width, float height)
{
NSWindow *w = [[NSWindow alloc] initWithContentRect:NSMakeRect(x,y,width,height)
styleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask
backing:NSBackingStoreRetained
defer:NO];
MyView *view = [[MyView alloc] initWithFrame:[w frame]];
[w makeKeyAndOrderFront:nil];
return view;
}
int main( int argc, char **argv)
{
createWindow(30,40,300,400);
} |
Partager