summaryrefslogtreecommitdiff
path: root/examples/gl_basic.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/gl_basic.c')
-rw-r--r--examples/gl_basic.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/gl_basic.c b/examples/gl_basic.c
index 5a4d9e9..f92d491 100644
--- a/examples/gl_basic.c
+++ b/examples/gl_basic.c
@@ -30,6 +30,10 @@
#include <string.h>
#include <time.h>
+#ifdef __APPLE__
+# include <Cocoa/Cocoa.h>
+#endif
+
#include <waffle/waffle.h>
static const char *usage_message =
@@ -245,6 +249,37 @@ draw(struct waffle_window *window)
return true;
}
+#ifdef __APPLE__
+
+static NSAutoreleasePool *pool;
+
+static void
+cocoa_init(void)
+{
+ // From the NSApplication Class Reference:
+ // [...] if you do need to use Cocoa classes within the main()
+ // function itself (other than to load nib files or to instantiate
+ // NSApplication), you should create an autorelease pool before using
+ // the classes and then release the pool when you’re done.
+ pool = [[NSAutoreleasePool alloc] init];
+
+ // From the NSApplication Class Reference:
+ // The sharedApplication class method initializes the display
+ // environment and connects your program to the window server and the
+ // display server.
+ //
+ // It also creates the singleton NSApp if it does not yet exist.
+ [NSApplication sharedApplication];
+}
+
+static void
+cocoa_finish(void)
+{
+ [pool drain];
+}
+
+#endif // __APPLE__
+
int
main(int argc, char **argv)
{
@@ -261,6 +296,10 @@ main(int argc, char **argv)
struct waffle_context *ctx;
struct waffle_window *window;
+ #ifdef __APPLE__
+ cocoa_init();
+ #endif
+
ok = parse_args(argc, argv, &opts);
if (!ok)
exit(EXIT_FAILURE);
@@ -339,5 +378,9 @@ main(int argc, char **argv)
if (!ok)
error_waffle();
+ #ifdef __APPLE__
+ cocoa_finish();
+ #endif
+
return EXIT_SUCCESS;
}