Updated some examples and tests to new API.

This commit is contained in:
Camilla Berglund
2010-09-09 19:18:18 +02:00
parent 0c4b67795d
commit b0ce8006e3
8 changed files with 114 additions and 84 deletions

View File

@@ -37,7 +37,7 @@
static int cursor_x = 0, cursor_y = 0;
static int window_width = 640, window_height = 480;
static void window_size_callback(int width, int height)
static void window_size_callback(GLFWwindow window, int width, int height)
{
window_width = width;
window_height = height;
@@ -49,7 +49,7 @@ static void window_size_callback(int width, int height)
gluOrtho2D(0.f, window_width, 0.f, window_height);
}
static void mouse_position_callback(int x, int y)
static void mouse_position_callback(GLFWwindow window, int x, int y)
{
cursor_x = x;
cursor_y = y;
@@ -57,13 +57,16 @@ static void mouse_position_callback(int x, int y)
int main(void)
{
GLFWwindow window;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
}
if (!glfwOpenWindow(window_width, window_height, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
window = glfwOpenWindow(window_width, window_height, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
if (!window)
{
glfwTerminate();
@@ -71,9 +74,9 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwSetWindowTitle("Cursor Inaccuracy Detector");
glfwSetMousePosCallback(mouse_position_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowTitle(window, "Cursor Inaccuracy Detector");
glfwSetMousePosCallback(window, mouse_position_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSwapInterval(1);
glClearColor(0, 0, 0, 0);
@@ -81,7 +84,7 @@ int main(void)
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
while (glfwGetWindowParam(GLFW_OPENED))
while (glfwIsWindow(window))
{
glClear(GL_COLOR_BUFFER_BIT);
@@ -95,6 +98,7 @@ int main(void)
glEnd();
glfwSwapBuffers();
glfwPollEvents();
}
glfwTerminate();

View File

@@ -67,6 +67,7 @@ static Param parameters[] =
int main(void)
{
int i, width, height;
GLFWwindow window;
if (!glfwInit())
{
@@ -74,7 +75,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();
@@ -82,16 +84,20 @@ int main(void)
exit(1);
}
glfwGetWindowSize(&width, &height);
glfwGetWindowSize(window, &width, &height);
printf("window size: %ix%i\n", width, height);
for (i = 0; (size_t) i < sizeof(parameters) / sizeof(parameters[0]); i++)
{
printf("%s: %i\n", parameters[i].name, glfwGetWindowParam(parameters[i].param));
printf("%s: %i\n",
parameters[i].name,
glfwGetWindowParam(window, parameters[i].param));
}
glfwCloseWindow();
glfwCloseWindow(window);
window = NULL;
glfwTerminate();
exit(0);
}

View File

@@ -162,7 +162,7 @@ static const char* get_character_string(int character)
return result;
}
static void window_size_callback(int width, int height)
static void window_size_callback(GLFWwindow window, int width, int height)
{
printf("%08x at %0.3f: Window size: %i %i\n",
counter++,
@@ -173,18 +173,18 @@ static void window_size_callback(int width, int height)
glViewport(0, 0, width, height);
}
static int window_close_callback(void)
static int window_close_callback(GLFWwindow window)
{
printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime());
return 1;
}
static void window_refresh_callback(void)
static void window_refresh_callback(GLFWwindow window)
{
printf("%08x at %0.3f: Window refresh\n", counter++, glfwGetTime());
}
static void mouse_button_callback(int button, int action)
static void mouse_button_callback(GLFWwindow window, int button, int action)
{
const char* name = get_button_name(button);
@@ -196,17 +196,17 @@ static void mouse_button_callback(int button, int action)
printf(" was %s\n", get_action_name(action));
}
static void mouse_position_callback(int x, int y)
static void mouse_position_callback(GLFWwindow window, int x, int y)
{
printf("%08x at %0.3f: Mouse position: %i %i\n", counter++, glfwGetTime(), x, y);
}
static void mouse_wheel_callback(int position)
static void mouse_wheel_callback(GLFWwindow window, int position)
{
printf("%08x at %0.3f: Mouse wheel: %i\n", counter++, glfwGetTime(), position);
}
static void key_callback(int key, int action)
static void key_callback(GLFWwindow window, int key, int action)
{
const char* name = get_key_name(key);
@@ -228,9 +228,9 @@ static void key_callback(int key, int action)
{
keyrepeat = !keyrepeat;
if (keyrepeat)
glfwEnable(GLFW_KEY_REPEAT);
glfwEnable(window, GLFW_KEY_REPEAT);
else
glfwDisable(GLFW_KEY_REPEAT);
glfwDisable(window, GLFW_KEY_REPEAT);
printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled");
break;
@@ -240,9 +240,9 @@ static void key_callback(int key, int action)
{
systemkeys = !systemkeys;
if( systemkeys )
glfwEnable(GLFW_SYSTEM_KEYS);
glfwEnable(window, GLFW_SYSTEM_KEYS);
else
glfwDisable(GLFW_SYSTEM_KEYS);
glfwDisable(window, GLFW_SYSTEM_KEYS);
printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
break;
@@ -250,7 +250,7 @@ static void key_callback(int key, int action)
}
}
static void char_callback(int character, int action)
static void char_callback(GLFWwindow window, int character, int action)
{
printf("%08x at %0.3f: Character 0x%04x", counter++, glfwGetTime(), character);
@@ -259,6 +259,8 @@ static void char_callback(int character, int action)
int main(void)
{
GLFWwindow window;
setlocale(LC_ALL, "");
if (!glfwInit())
@@ -269,7 +271,8 @@ int main(void)
printf("Library initialized\n");
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();
@@ -279,28 +282,29 @@ int main(void)
printf("Window opened\n");
glfwSetWindowTitle("Event Linter");
glfwSetWindowTitle(window, "Event Linter");
glfwSwapInterval(1);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowRefreshCallback(window_refresh_callback);
glfwSetMouseButtonCallback(mouse_button_callback);
glfwSetMousePosCallback(mouse_position_callback);
glfwSetMouseWheelCallback(mouse_wheel_callback);
glfwSetKeyCallback(key_callback);
glfwSetCharCallback(char_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetWindowRefreshCallback(window, window_refresh_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
glfwSetMousePosCallback(window, mouse_position_callback);
glfwSetMouseWheelCallback(window, mouse_wheel_callback);
glfwSetKeyCallback(window, key_callback);
glfwSetCharCallback(window, char_callback);
printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled");
printf("System keys should be %s\n", systemkeys ? "enabled" : "disabled");
printf("Main loop starting\n");
while (glfwGetWindowParam(GLFW_OPENED) == GL_TRUE)
while (glfwIsWindow(window) == GL_TRUE)
{
glfwWaitEvents();
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwPollEvents();
}
glfwTerminate();

View File

@@ -38,13 +38,15 @@
#define GL_MULTISAMPLE_ARB 0x809D
#endif
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);
}
int main(void)
{
GLFWwindow window;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
@@ -53,7 +55,8 @@ int main(void)
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
if (!glfwOpenWindow(400, 400, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
window = glfwOpenWindow(400, 400, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
if (!window)
{
glfwTerminate();
@@ -61,11 +64,11 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwSetWindowTitle("Aliasing Detector");
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowTitle(window, "Aliasing Detector");
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSwapInterval(1);
int samples = glfwGetWindowParam(GLFW_FSAA_SAMPLES);
int samples = glfwGetWindowParam(window, GLFW_FSAA_SAMPLES);
if (samples)
printf("Context reports FSAA is supported with %i samples\n", samples);
else
@@ -74,7 +77,7 @@ int main(void)
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.f, 1.f, 0.f, 1.f);
while (glfwGetWindowParam(GLFW_OPENED))
while (glfwIsWindow(window))
{
GLfloat time = (GLfloat) glfwGetTime();
@@ -97,6 +100,7 @@ int main(void)
glRectf(-0.25f, -0.25f, 0.25f, 0.25f);
glfwSwapBuffers();
glfwPollEvents();
}
glfwTerminate();

View File

@@ -36,32 +36,33 @@
#include <stdlib.h>
static GLboolean cursor_enabled = GL_TRUE;
static GLFWwindow window_handle = NULL;
static GLboolean open_window(void);
static void toggle_mouse_cursor(void)
static void toggle_mouse_cursor(GLFWwindow window)
{
if (cursor_enabled)
glfwDisable(GLFW_MOUSE_CURSOR);
glfwDisable(window, GLFW_MOUSE_CURSOR);
else
glfwEnable(GLFW_MOUSE_CURSOR);
glfwEnable(window, GLFW_MOUSE_CURSOR);
cursor_enabled = !cursor_enabled;
}
static void mouse_position_callback(int x, int y)
static void mouse_position_callback(GLFWwindow window, int x, int y)
{
printf("Mouse moved to: %i %i\n", x, y);
}
static void key_callback(int key, int action)
static void key_callback(GLFWwindow window, int key, int action)
{
switch (key)
{
case GLFW_KEY_SPACE:
{
if (action == GLFW_PRESS)
toggle_mouse_cursor();
toggle_mouse_cursor(window);
break;
}
@@ -70,7 +71,7 @@ static void key_callback(int key, int action)
{
if (action == GLFW_PRESS)
{
glfwCloseWindow();
glfwCloseWindow(window);
open_window();
}
@@ -79,7 +80,7 @@ static void key_callback(int key, int action)
}
}
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);
}
@@ -88,17 +89,18 @@ static GLboolean open_window(void)
{
int x, y;
if (!glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
window_handle = glfwOpenWindow(0, 0, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
if (!window_handle)
return GL_FALSE;
glfwSetWindowTitle("Peter Detector");
glfwSetWindowTitle(window_handle, "Peter Detector");
glfwGetMousePos(&x, &y);
glfwGetMousePos(window_handle, &x, &y);
printf("Mouse position: %i %i\n", x, y);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetMousePosCallback(mouse_position_callback);
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(window_handle, window_size_callback);
glfwSetMousePosCallback(window_handle, mouse_position_callback);
glfwSetKeyCallback(window_handle, key_callback);
glfwSwapInterval(1);
return GL_TRUE;
@@ -122,7 +124,7 @@ int main(void)
glClearColor(0.f, 0.f, 0.f, 0.f);
while (glfwGetWindowParam(GLFW_OPENED))
while (glfwIsWindow(window_handle))
{
glClear(GL_COLOR_BUFFER_BIT);