From 4f6fca0f6227f4a610b186f34cc55fd8ebfccc4d Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Tue, 12 Aug 2014 22:14:01 +0200 Subject: [PATCH] Port from GLFW 2 to 3 --- testbed/main.cc | 19 ++++++++++++------- wscript | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/testbed/main.cc b/testbed/main.cc index 11daaa4..59f5806 100644 --- a/testbed/main.cc +++ b/testbed/main.cc @@ -29,7 +29,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include +#include #include #include #include @@ -77,6 +77,8 @@ bool draw_map = false; /// Create a random distribution of points? bool random_distribution = false; +GLFWwindow* window = NULL; + template void FreeClear( C & cntr ) { for ( typename C::iterator it = cntr.begin(); it != cntr.end(); ++it ) { @@ -230,10 +232,11 @@ void Init() if (glfwInit() != GL_TRUE) ShutDown(1); // 800 x 600, 16 bit color, no depth, alpha or stencil buffers, windowed - if (glfwOpenWindow(window_width, window_height, 5, 6, 5, 0, 0, 0, GLFW_WINDOW) != GL_TRUE) + window = glfwCreateWindow(window_width, window_height, "Poly2Tri - C++", NULL, NULL); + if (!window) ShutDown(1); - glfwSetWindowTitle("Poly2Tri - C++"); + glfwMakeContextCurrent(window); glfwSwapInterval(1); glEnable(GL_BLEND); @@ -256,6 +259,8 @@ void MainLoop(const double zoom) bool running = true; while (running) { + glfwPollEvents(); + // calculate time elapsed, and the amount by which stuff rotates double current_time = glfwGetTime(), delta_rotate = (current_time - old_time) * rotations_per_tick * 360; @@ -263,11 +268,11 @@ void MainLoop(const double zoom) // escape to quit, arrow keys to rotate view // Check if ESC key was pressed or window was closed - running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED); + running = !glfwGetKey(window, GLFW_KEY_ESCAPE) && !glfwWindowShouldClose(window); - if (glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS) + if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS) rotate_y += delta_rotate; - if (glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS) + if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS) rotate_y -= delta_rotate; // z axis always rotates rotate_z += delta_rotate; @@ -280,7 +285,7 @@ void MainLoop(const double zoom) } // swap back and front buffers - glfwSwapBuffers(); + glfwSwapBuffers(window); } } diff --git a/wscript b/wscript index 34ebe73..543ee3e 100644 --- a/wscript +++ b/wscript @@ -19,9 +19,9 @@ from waflib.Tools.compiler_cxx import cxx_compiler cxx_compiler['win32'] = ['g++'] #Platform specific libs -if sys.platform == 'win32': +if sys.platform in ['win32', 'msys']: # MS Windows - sys_libs = ['glfw', 'opengl32'] + sys_libs = ['glfw3', 'opengl32'] elif sys.platform == 'darwin': # Apple OSX sys_libs = ['glfw']