From 569fcf994bf99fd4e06275312fc1a15c5bd029b2 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 26 Aug 2012 17:11:32 +0200 Subject: [PATCH] Add vsync. --- src/OGKDisplay.h | 3 ++- src/OGKDisplay.m | 5 +++++ tests/TestMain.m | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/OGKDisplay.h b/src/OGKDisplay.h index 04547eb..41369fa 100644 --- a/src/OGKDisplay.h +++ b/src/OGKDisplay.h @@ -32,7 +32,8 @@ typedef enum ogk_display_flags_t { OGK_DISPLAY_FLAGS_RESIZABLE = 0x02, OGK_DISPLAY_FLAGS_OPENGL = 0x04, OGK_DISPLAY_FLAGS_OPENGL_3 = 0x08, - OGK_DISPLAY_FLAGS_OPENGL_3_ONLY = 0x10 + OGK_DISPLAY_FLAGS_OPENGL_3_ONLY = 0x10, + OGK_DISPLAY_FLAGS_VSYNC = 0x20 } ogk_display_flags_t; @interface OGKDisplay: OFObject diff --git a/src/OGKDisplay.m b/src/OGKDisplay.m index 0534807..908e869 100644 --- a/src/OGKDisplay.m +++ b/src/OGKDisplay.m @@ -81,6 +81,11 @@ static OFDataArray *allegroDisplays = nil; if (flags & OGK_DISPLAY_FLAGS_OPENGL_3_ONLY) allegroFlags |= ALLEGRO_OPENGL_FORWARD_COMPATIBLE; + if (flags & OGK_DISPLAY_FLAGS_VSYNC) + al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_SUGGEST); + else + al_set_new_display_option(ALLEGRO_VSYNC, 0, ALLEGRO_SUGGEST); + al_set_new_display_flags(allegroFlags); display = al_create_display(size.width, size.height); diff --git a/tests/TestMain.m b/tests/TestMain.m index f67620b..0e9ef0c 100644 --- a/tests/TestMain.m +++ b/tests/TestMain.m @@ -87,7 +87,9 @@ OF_APPLICATION_DELEGATE(TestMain) - (void)applicationDidFinishLaunching { - ogk_display_flags_t flags = OGK_DISPLAY_FLAGS_RESIZABLE; + ogk_display_flags_t flags = + OGK_DISPLAY_FLAGS_RESIZABLE | + OGK_DISPLAY_FLAGS_VSYNC; display = [[OGKDisplay alloc] initWithSize: of_dimension(640, 480) position: of_point(200, 200)