Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import<Foundation/Foundation.h>
- #import<AppKit/AppKit.h>
- #include<OpenGL/gl.h>
- @interface ApplicationDelegate:NSObject<NSApplicationDelegate>{
- }
- @end
- @interface WindowDelegate:NSObject<NSWindowDelegate>{
- }
- @end
- @interface OpenGLView:NSOpenGLView{
- }
- -(BOOL)acceptsFirstResponder;
- -(void)keyDown:(NSEvent *)theEvent;
- -(void)drawRect:(NSRect)bounds;
- @end
- NSWindow *window;
- @implementation ApplicationDelegate{
- }
- -(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication{
- return(YES);
- }
- -(void)applicationWillFinishLaunching:(NSNotification *)aNotification{
- NSMenu *menu=[[NSMenu alloc]init];
- [menu addItemWithTitle:@"Quit"
- action:@selector(terminate:)
- keyEquivalent:@"Q"];
- [NSApp setMainMenu:menu];
- NSRect mainRect=[[NSScreen mainScreen]frame];
- window=[[NSWindow alloc]initWithContentRect:[[NSScreen mainScreen]frame]
- styleMask:NSBorderlessWindowMask
- backing:NSBackingStoreBuffered
- defer:YES];
- WindowDelegate *windowDelegate=[[WindowDelegate alloc]init];
- [window setDelegate:windowDelegate];
- [window setLevel:NSMainMenuWindowLevel+1];
- [window setOpaque:YES];
- [window setHidesOnDeactivate:YES];
- NSOpenGLPixelFormatAttribute attr[]={
- 0,
- };
- NSOpenGLPixelFormat *openGLPixelFormat=[[NSOpenGLPixelFormat alloc]initWithAttributes:attr];
- NSRect viewRect=NSMakeRect(0.0,0.0,mainRect.size.width,mainRect.size.height);
- OpenGLView *openGLView=[[OpenGLView alloc]initWithFrame:viewRect pixelFormat:openGLPixelFormat];
- [window setContentView:openGLView];
- [window makeFirstResponder:openGLView];
- }
- -(void)applicationDidFinishLaunching:(NSNotification *)aNotification{
- [window makeKeyAndOrderFront:self];
- }
- -(void)applicationWillTerminate:(NSNotification *)aNotification{
- }
- @end
- @implementation WindowDelegate{
- }
- @end
- @implementation OpenGLView{
- }
- -(BOOL)acceptsFirstResponder{
- return(YES);
- }
- -(void)keyDown:(NSEvent *)theEvent{
- [NSApp terminate:self];
- }
- -(void)drawRect:(NSRect)bounds{
- glClearColor(1.,0.,0.,0.);
- glClear(GL_COLOR_BUFFER_BIT);
- glFlush();
- }
- @end
- int main(void){
- [NSApplication sharedApplication];
- [NSApp setDelegate:[ApplicationDelegate new]];
- [NSApp run];
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement