Merge branch 'master' into joystickname

Conflicts:
	src/x11_joystick.c
This commit is contained in:
Camilla Berglund
2012-11-08 15:55:25 +01:00
43 changed files with 589 additions and 393 deletions

View File

@@ -86,10 +86,6 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetKeyCallback(key_callback);
window = glfwCreateWindow(window_width, window_height, GLFW_WINDOWED, "", NULL);
if (!window)
{
@@ -99,6 +95,10 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwSetCursorPosCallback(window, cursor_position_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
glfwGetWindowSize(window, &width, &height);

View File

@@ -137,9 +137,9 @@ int main(int argc, char** argv)
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetKeyCallback(window, key_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f);

View File

@@ -363,18 +363,6 @@ int main(void)
printf("Library initialized\n");
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowRefreshCallback(window_refresh_callback);
glfwSetWindowFocusCallback(window_focus_callback);
glfwSetWindowIconifyCallback(window_iconify_callback);
glfwSetMouseButtonCallback(mouse_button_callback);
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetCursorEnterCallback(cursor_enter_callback);
glfwSetScrollCallback(scroll_callback);
glfwSetKeyCallback(key_callback);
glfwSetCharCallback(char_callback);
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL);
if (!window)
{
@@ -386,6 +374,18 @@ int main(void)
printf("Window opened\n");
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetWindowRefreshCallback(window, window_refresh_callback);
glfwSetWindowFocusCallback(window, window_focus_callback);
glfwSetWindowIconifyCallback(window, window_iconify_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
glfwSetCursorPosCallback(window, cursor_position_callback);
glfwSetCursorEnterCallback(window, cursor_enter_callback);
glfwSetScrollCallback(window, scroll_callback);
glfwSetKeyCallback(window, key_callback);
glfwSetCharCallback(window, char_callback);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);

View File

@@ -93,9 +93,6 @@ int main(int argc, char** argv)
else
printf("Requesting that FSAA not be available\n");
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwWindowHint(GLFW_FSAA_SAMPLES, samples);
window = glfwCreateWindow(800, 400, GLFW_WINDOWED, "Aliasing Detector", NULL);
@@ -107,6 +104,9 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
glfwSetKeyCallback(window, key_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);

View File

@@ -96,9 +96,9 @@ int main(void)
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
glfwSetWindowFocusCallback(window_focus_callback);
glfwSetKeyCallback(window_key_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowFocusCallback(window, window_focus_callback);
glfwSetKeyCallback(window, window_key_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
while (running)
{

View File

@@ -151,9 +151,9 @@ int main(int argc, char** argv)
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowSizeCallback(size_callback);
glfwSetKeyCallback(window, key_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetWindowSizeCallback(window, size_callback);
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f);

View File

@@ -42,60 +42,74 @@
#define strcasecmp(x, y) _stricmp(x, y)
#endif
#define API_OPENGL "gl"
#define API_OPENGL_ES "es"
#define PROFILE_NAME_CORE "core"
#define PROFILE_NAME_COMPAT "compat"
#define PROFILE_NAME_ES2 "es2"
#define STRATEGY_NAME_NONE "none"
#define STRATEGY_NAME_LOSE "lose"
static void usage(void)
{
printf("Usage: glfwinfo [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n");
printf("available profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT " " PROFILE_NAME_ES2 "\n");
printf("Usage: glfwinfo [-h] [-a API] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n");
printf("available APIs: " API_OPENGL " " API_OPENGL_ES "\n");
printf("available profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT "\n");
printf("available strategies: " STRATEGY_NAME_NONE " " STRATEGY_NAME_LOSE "\n");
}
static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s in %s\n", glfwErrorString(error), description);
fprintf(stderr, "Error: %s\n", description);
}
static const char* get_glfw_profile_name(int profile)
static const char* get_client_api_name(int api)
{
if (profile == GLFW_OPENGL_COMPAT_PROFILE)
return PROFILE_NAME_COMPAT;
else if (profile == GLFW_OPENGL_CORE_PROFILE)
return PROFILE_NAME_CORE;
else if (profile == GLFW_OPENGL_ES2_PROFILE)
return PROFILE_NAME_ES2;
if (api == GLFW_OPENGL_API)
return "OpenGL";
else if (api == GLFW_OPENGL_ES_API)
return "OpenGL ES";
return "unknown";
return "Unknown API";
}
static const char* get_profile_name(GLint mask)
static const char* get_profile_name_gl(GLint mask)
{
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
return PROFILE_NAME_COMPAT;
return "compatibility";
if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
return PROFILE_NAME_CORE;
return "core";
return "unknown";
}
static void list_extensions(int major, int minor)
static const char* get_profile_name_glfw(int profile)
{
if (profile == GLFW_OPENGL_COMPAT_PROFILE)
return "compatibility";
if (profile == GLFW_OPENGL_CORE_PROFILE)
return "core";
return "unknown";
}
static void list_extensions(int api, int major, int minor)
{
int i;
GLint count;
const GLubyte* extensions;
printf("OpenGL context supported extensions:\n");
printf("%s context supported extensions:\n", get_client_api_name(api));
if (major > 2)
if (api == GLFW_OPENGL_API && major > 2)
{
PFNGLGETSTRINGIPROC glGetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi");
if (!glGetStringi)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glGetIntegerv(GL_NUM_EXTENSIONS, &count);
@@ -147,7 +161,7 @@ static GLboolean valid_version(void)
int main(int argc, char** argv)
{
int ch, profile = 0, strategy = 0, major = 1, minor = 0, revision;
int ch, api = 0, profile = 0, strategy = 0, major = 1, minor = 0, revision;
GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE;
GLint flags, mask;
GLFWwindow window;
@@ -155,10 +169,20 @@ int main(int argc, char** argv)
if (!valid_version())
exit(EXIT_FAILURE);
while ((ch = getopt(argc, argv, "dfhlm:n:p:r:")) != -1)
while ((ch = getopt(argc, argv, "a:dfhlm:n:p:r:")) != -1)
{
switch (ch)
{
case 'a':
if (strcasecmp(optarg, API_OPENGL) == 0)
api = GLFW_OPENGL_API;
else if (strcasecmp(optarg, API_OPENGL_ES) == 0)
api = GLFW_OPENGL_ES_API;
else
{
usage();
exit(EXIT_FAILURE);
}
case 'd':
debug = GL_TRUE;
break;
@@ -182,8 +206,6 @@ int main(int argc, char** argv)
profile = GLFW_OPENGL_CORE_PROFILE;
else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0)
profile = GLFW_OPENGL_COMPAT_PROFILE;
else if (strcasecmp(optarg, PROFILE_NAME_ES2) == 0)
profile = GLFW_OPENGL_ES2_PROFILE;
else
{
usage();
@@ -226,6 +248,9 @@ int main(int argc, char** argv)
glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, minor);
}
if (api != 0)
glfwWindowHint(GLFW_CLIENT_API, api);
if (debug)
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
@@ -245,66 +270,88 @@ int main(int argc, char** argv)
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
if (!window)
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
// Report OpenGL version
printf("OpenGL context version string: \"%s\"\n", glGetString(GL_VERSION));
// Report client API version
api = glfwGetWindowParam(window, GLFW_CLIENT_API);
major = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MAJOR);
minor = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MINOR);
revision = glfwGetWindowParam(window, GLFW_OPENGL_REVISION);
printf("OpenGL context version parsed by GLFW: %u.%u.%u\n", major, minor, revision);
printf("%s context version string: \"%s\"\n",
get_client_api_name(api),
glGetString(GL_VERSION));
// Report OpenGL context properties
printf("%s context version parsed by GLFW: %u.%u.%u\n",
get_client_api_name(api),
major, minor, revision);
if (major >= 3)
// Report client API context properties
if (api == GLFW_OPENGL_API)
{
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
printf("OpenGL context flags (0x%08x):", flags);
if (major >= 3)
{
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
printf("%s context flags (0x%08x):", get_client_api_name(api), flags);
if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
printf(" forward-compatible");
if (flags & 0)
printf(" debug");
putchar('\n');
if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
printf(" forward-compatible");
if (flags & 0)
printf(" debug");
putchar('\n');
printf("OpenGL context flags parsed by GLFW:");
printf("%s context flags parsed by GLFW:", get_client_api_name(api));
if (glfwGetWindowParam(window, GLFW_OPENGL_FORWARD_COMPAT))
printf(" forward-compatible");
if (glfwGetWindowParam(window, GLFW_OPENGL_DEBUG_CONTEXT))
printf(" debug");
putchar('\n');
if (glfwGetWindowParam(window, GLFW_OPENGL_FORWARD_COMPAT))
printf(" forward-compatible");
if (glfwGetWindowParam(window, GLFW_OPENGL_DEBUG_CONTEXT))
printf(" debug");
putchar('\n');
}
if (major > 3 || (major == 3 && minor >= 2))
{
int profile = glfwGetWindowParam(window, GLFW_OPENGL_PROFILE);
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
printf("%s profile mask (0x%08x): %s\n",
get_client_api_name(api),
mask,
get_profile_name_gl(mask));
printf("%s profile mask parsed by GLFW: %s\n",
get_client_api_name(api),
get_profile_name_glfw(profile));
}
}
if (major > 3 || (major == 3 && minor >= 2))
{
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
printf("OpenGL profile mask (0x%08x): %s\n", mask, get_profile_name(mask));
printf("OpenGL profile mask parsed by GLFW: %s\n",
get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE)));
}
printf("%s context renderer string: \"%s\"\n",
get_client_api_name(api),
glGetString(GL_RENDERER));
printf("%s context vendor string: \"%s\"\n",
get_client_api_name(api),
glGetString(GL_VENDOR));
printf("OpenGL context debug flag saved by GLFW: %s\n",
glfwGetWindowParam(window, GLFW_OPENGL_DEBUG_CONTEXT) ? "true" : "false");
printf("OpenGL context renderer string: \"%s\"\n", glGetString(GL_RENDERER));
printf("OpenGL context vendor string: \"%s\"\n", glGetString(GL_VENDOR));
if (major > 1)
{
printf("OpenGL context shading language version: \"%s\"\n",
printf("%s context shading language version: \"%s\"\n",
get_client_api_name(api),
glGetString(GL_SHADING_LANGUAGE_VERSION));
}
// Report OpenGL extensions
// Report client API extensions
if (list)
list_extensions(major, minor);
list_extensions(api, major, minor);
glfwTerminate();
exit(EXIT_SUCCESS);

View File

@@ -70,16 +70,29 @@ static void key_callback(GLFWwindow window, int key, int action)
static void window_size_callback(GLFWwindow window, int width, int height)
{
printf("%0.2f Size %ix%i\n", glfwGetTime(), width, height);
printf("%0.2f Window resized to %ix%i\n", glfwGetTime(), width, height);
glViewport(0, 0, width, height);
}
static void window_focus_callback(GLFWwindow window, int activated)
{
printf("%0.2f Window %s\n",
glfwGetTime(),
activated ? "activated" : "deactivated");
}
static void window_iconify_callback(GLFWwindow window, int iconified)
{
printf("%0.2f Window %s\n",
glfwGetTime(),
iconified ? "iconified" : "restored");
}
int main(int argc, char** argv)
{
int width, height, ch;
int mode = GLFW_WINDOWED;
GLboolean active = -1, iconified = -1;
GLFWwindow window;
while ((ch = getopt(argc, argv, "fh")) != -1)
@@ -131,26 +144,20 @@ int main(int argc, char** argv)
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetKeyCallback(window, key_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetWindowFocusCallback(window, window_focus_callback);
glfwSetWindowIconifyCallback(window, window_iconify_callback);
printf("Window is %s and %s\n",
glfwGetWindowParam(window, GLFW_ICONIFIED) ? "iconified" : "restored",
glfwGetWindowParam(window, GLFW_ACTIVE) ? "active" : "inactive");
glEnable(GL_SCISSOR_TEST);
while (!closed)
{
if (iconified != glfwGetWindowParam(window, GLFW_ICONIFIED) ||
active != glfwGetWindowParam(window, GLFW_ACTIVE))
{
iconified = glfwGetWindowParam(window, GLFW_ICONIFIED);
active = glfwGetWindowParam(window, GLFW_ACTIVE);
printf("%0.2f %s %s\n",
glfwGetTime(),
iconified ? "Iconified" : "Restored",
active ? "Active" : "Inactive");
}
glfwGetWindowSize(window, &width, &height);
glScissor(0, 0, width, height);

View File

@@ -200,7 +200,7 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);

View File

@@ -117,10 +117,6 @@ static void test_modes(void)
int i, count;
GLFWvidmode* modes = glfwGetVideoModes(&count);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetKeyCallback(key_callback);
for (i = 0; i < count; i++)
{
GLFWvidmode* mode = modes + i;
@@ -143,6 +139,10 @@ static void test_modes(void)
continue;
}
glfwSetWindowSizeCallback(window_handle, window_size_callback);
glfwSetWindowCloseCallback(window_handle, window_close_callback);
glfwSetKeyCallback(window_handle, key_callback);
glfwMakeContextCurrent(window_handle);
glfwSwapInterval(1);
@@ -157,6 +157,8 @@ static void test_modes(void)
if (!window_handle)
{
printf("User terminated program\n");
glfwTerminate();
exit(EXIT_SUCCESS);
}
}
@@ -224,6 +226,7 @@ int main(int argc, char** argv)
else if (mode == TEST_MODE)
test_modes();
glfwTerminate();
exit(EXIT_SUCCESS);
}

View File

@@ -102,9 +102,9 @@ static GLboolean open_window(void)
glfwGetCursorPos(window_handle, &cursor_x, &cursor_y);
printf("Cursor position: %i %i\n", cursor_x, cursor_y);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(window_handle, window_size_callback);
glfwSetCursorPosCallback(window_handle, cursor_position_callback);
glfwSetKeyCallback(window_handle, key_callback);
return GL_TRUE;
}
@@ -120,6 +120,8 @@ int main(void)
if (!open_window())
{
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
glfwTerminate();
exit(EXIT_FAILURE);
}
@@ -138,6 +140,8 @@ int main(void)
if (!open_window())
{
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
glfwTerminate();
exit(EXIT_FAILURE);
}

View File

@@ -102,9 +102,9 @@ static GLboolean open_window(int width, int height, int mode)
glfwMakeContextCurrent(window_handle);
glfwSwapInterval(1);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(window_handle, window_size_callback);
glfwSetWindowCloseCallback(window_handle, window_close_callback);
glfwSetKeyCallback(window_handle, key_callback);
printf("Opening %s mode window took %0.3f seconds\n",
get_mode_name(mode),
@@ -132,7 +132,10 @@ int main(int argc, char** argv)
for (;;)
{
if (!open_window(640, 480, (count & 1) ? GLFW_FULLSCREEN : GLFW_WINDOWED))
{
glfwTerminate();
exit(EXIT_FAILURE);
}
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
@@ -156,6 +159,8 @@ int main(int argc, char** argv)
{
close_window();
printf("User closed window\n");
glfwTerminate();
exit(EXIT_SUCCESS);
}
}

View File

@@ -62,8 +62,8 @@ static GLFWwindow open_window(const char* title, GLFWwindow share)
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetKeyCallback(key_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetKeyCallback(window, key_callback);
return window;
}
@@ -137,6 +137,8 @@ int main(int argc, char** argv)
if (!windows[0])
{
fprintf(stderr, "Failed to open first GLFW window: %s\n", glfwErrorString(glfwGetError()));
glfwTerminate();
exit(EXIT_FAILURE);
}
@@ -149,6 +151,8 @@ int main(int argc, char** argv)
if (!windows[1])
{
fprintf(stderr, "Failed to open second GLFW window: %s\n", glfwErrorString(glfwGetError()));
glfwTerminate();
exit(EXIT_FAILURE);
}

View File

@@ -73,17 +73,17 @@ int main(void)
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "", NULL);
if (!window)
{
glfwTerminate();
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
set_swap_interval(window, swap_interval);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetKeyCallback(window, key_callback);
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);

View File

@@ -28,6 +28,8 @@
//
//========================================================================
#include "tinycthread.h"
#include <GL/glfw3.h>
#include <stdio.h>
@@ -35,8 +37,6 @@
#include <math.h>
#include <assert.h>
#include "tinycthread.h"
typedef struct
{
GLFWwindow window;

View File

@@ -51,13 +51,15 @@ int main(void)
if (!window)
{
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED))
{
@@ -66,6 +68,7 @@ int main(void)
glfwWaitEvents();
}
glfwTerminate();
exit(EXIT_SUCCESS);
}

View File

@@ -60,6 +60,7 @@ int main(void)
{
fprintf(stderr, "Failed to open GLFW window: %s\n",
glfwErrorString(glfwGetError()));
glfwTerminate();
exit(EXIT_FAILURE);
}