Advertisement
Guest User

Untitled

a guest
Apr 28th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #import<Foundation/Foundation.h>
  2. #import<AppKit/AppKit.h>
  3. #include<OpenGL/gl.h>
  4.  
  5.  
  6. @interface ApplicationDelegate:NSObject<NSApplicationDelegate>{
  7. }
  8. @end
  9.  
  10. @interface WindowDelegate:NSObject<NSWindowDelegate>{
  11. }
  12. @end
  13.  
  14. @interface OpenGLView:NSOpenGLView{
  15. }
  16. -(BOOL)acceptsFirstResponder;
  17. -(void)keyDown:(NSEvent *)theEvent;
  18.  
  19. -(void)drawRect:(NSRect)bounds;
  20. @end
  21.  
  22.  
  23. NSWindow *window;
  24.  
  25. @implementation ApplicationDelegate{
  26. }
  27. -(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication{
  28. return(YES);
  29. }
  30. -(void)applicationWillFinishLaunching:(NSNotification *)aNotification{
  31. NSMenu *menu=[[NSMenu alloc]init];
  32. [menu addItemWithTitle:@"Quit"
  33. action:@selector(terminate:)
  34. keyEquivalent:@"Q"];
  35. [NSApp setMainMenu:menu];
  36.  
  37. NSRect mainRect=[[NSScreen mainScreen]frame];
  38. window=[[NSWindow alloc]initWithContentRect:[[NSScreen mainScreen]frame]
  39. styleMask:NSBorderlessWindowMask
  40. backing:NSBackingStoreBuffered
  41. defer:YES];
  42. WindowDelegate *windowDelegate=[[WindowDelegate alloc]init];
  43. [window setDelegate:windowDelegate];
  44. [window setLevel:NSMainMenuWindowLevel+1];
  45. [window setOpaque:YES];
  46. [window setHidesOnDeactivate:YES];
  47.  
  48. NSOpenGLPixelFormatAttribute attr[]={
  49. 0,
  50. };
  51. NSOpenGLPixelFormat *openGLPixelFormat=[[NSOpenGLPixelFormat alloc]initWithAttributes:attr];
  52. NSRect viewRect=NSMakeRect(0.0,0.0,mainRect.size.width,mainRect.size.height);
  53. OpenGLView *openGLView=[[OpenGLView alloc]initWithFrame:viewRect pixelFormat:openGLPixelFormat];
  54.  
  55. [window setContentView:openGLView];
  56. [window makeFirstResponder:openGLView];
  57. }
  58. -(void)applicationDidFinishLaunching:(NSNotification *)aNotification{
  59. [window makeKeyAndOrderFront:self];
  60. }
  61. -(void)applicationWillTerminate:(NSNotification *)aNotification{
  62. }
  63. @end
  64.  
  65. @implementation WindowDelegate{
  66. }
  67. @end
  68.  
  69. @implementation OpenGLView{
  70. }
  71. -(BOOL)acceptsFirstResponder{
  72. return(YES);
  73. }
  74. -(void)keyDown:(NSEvent *)theEvent{
  75. [NSApp terminate:self];
  76. }
  77.  
  78. -(void)drawRect:(NSRect)bounds{
  79. glClearColor(1.,0.,0.,0.);
  80. glClear(GL_COLOR_BUFFER_BIT);
  81. glFlush();
  82. }
  83. @end
  84.  
  85.  
  86. int main(void){
  87. [NSApplication sharedApplication];
  88. [NSApp setDelegate:[ApplicationDelegate new]];
  89. [NSApp run];
  90. return(0);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement