1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-26 12:18:51 -05:00

Updated some tests to new API.

This commit is contained in:
Camilla Berglund 2010-09-09 19:22:47 +02:00
parent b0ce8006e3
commit b54334a451
2 changed files with 22 additions and 16 deletions

View File

@ -38,6 +38,7 @@
#include <stdio.h>
#include <stdlib.h>
static GLFWwindow window_handle = NULL;
static GLboolean closed = GL_FALSE;
static const char* get_mode_name(int mode)
@ -53,19 +54,19 @@ static const char* get_mode_name(int mode)
}
}
static void window_size_callback(int width, int height)
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
}
static int window_close_callback(void)
static int window_close_callback(GLFWwindow window)
{
printf("Close callback triggered\n");
closed = GL_TRUE;
window_handle = NULL;
return 0;
}
static void key_callback(int key, int action)
static void key_callback(GLFWwindow window, int key, int action)
{
if (action != GLFW_PRESS)
return;
@ -83,16 +84,17 @@ static int open_window(int width, int height, int mode)
{
double base = glfwGetTime();
if (!glfwOpenWindow(width, height, 0, 0, 0, 0, 16, 0, mode))
window_handle = glfwOpenWindow(width, height, 0, 0, 0, 0, 16, 0, mode);
if (!window_handle)
{
fprintf(stderr, "Failed to create %s mode GLFW window\n", get_mode_name(mode));
return 0;
}
glfwSetWindowTitle("Window Re-opener");
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetKeyCallback(key_callback);
glfwSetWindowTitle(window_handle, "Window Re-opener");
glfwSetWindowSizeCallback(window_handle, window_size_callback);
glfwSetWindowCloseCallback(window_handle, window_close_callback);
glfwSetKeyCallback(window_handle, key_callback);
glfwSwapInterval(1);
printf("Opening %s mode window took %0.3f seconds\n",
@ -106,7 +108,8 @@ static void close_window(void)
{
double base = glfwGetTime();
glfwCloseWindow();
glfwCloseWindow(window_handle);
window_handle = NULL;
printf("Closing window took %0.3f seconds\n", glfwGetTime() - base);
}
@ -152,7 +155,7 @@ int main(int argc, char** argv)
if (closed)
close_window();
if (!glfwGetWindowParam(GLFW_OPENED))
if (!glfwIsWindow(window_handle))
{
printf("User closed window\n");

View File

@ -34,7 +34,7 @@
#include <stdlib.h>
#include <math.h>
static void window_size_callback(int width, int height)
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
}
@ -42,6 +42,7 @@ static void window_size_callback(int width, int height)
int main(void)
{
float position;
GLFWwindow window;
if (!glfwInit())
{
@ -49,7 +50,8 @@ int main(void)
exit(1);
}
if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
window = glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
if (!window)
{
glfwTerminate();
@ -57,8 +59,8 @@ int main(void)
exit(1);
}
glfwSetWindowTitle("Tearing Detector");
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowTitle(window, "Tearing Detector");
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSwapInterval(1);
glClearColor(0.f, 0.f, 0.f, 0.f);
@ -68,7 +70,7 @@ int main(void)
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
glMatrixMode(GL_MODELVIEW);
while (glfwGetWindowParam(GLFW_OPENED) == GL_TRUE)
while (glfwIsWindow(window) == GL_TRUE)
{
glClear(GL_COLOR_BUFFER_BIT);
@ -76,6 +78,7 @@ int main(void)
glRectf(position - 0.25f, -1.f, position + 0.25f, 1.f);
glfwSwapBuffers();
glfwPollEvents();
}
glfwTerminate();