summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorChad Versace <chad.versace@linux.intel.com>2012-05-30 14:04:10 -0700
committerChad Versace <chad.versace@linux.intel.com>2012-05-30 17:42:29 -0700
commit45bffb402250eeeaf056f3eb2c5130f7b6501f87 (patch)
tree2121836e77dc76f66e23c3d26642d04761fed06d /examples
parente2f214de622987e1dd1ca493769990a1739d76cd (diff)
examples/gl_basic: Add support for CGL
The example was verified to work on MacOS 10.7. Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt7
-rw-r--r--examples/gl_basic.c43
2 files changed, 50 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 3578708..df94cf0 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -4,3 +4,10 @@
add_executable(gl_basic gl_basic.c)
target_link_libraries(gl_basic waffle)
+
+if("${CMAKE_SYSTEM_NAME}" STREQUAL Darwin)
+ set_target_properties(gl_basic
+ PROPERTIES
+ COMPILE_FLAGS "-ObjC"
+ )
+endif()
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;
}