Merge branch 'master' into multi-monitor

Conflicts:
	.gitignore
	examples/CMakeLists.txt
	include/GL/glfw3.h
	src/CMakeLists.txt
	src/internal.h
	src/win32_platform.h
	src/win32_window.c
	src/x11_fullscreen.c
	src/x11_platform.h
	tests/listmodes.c
This commit is contained in:
Camilla Berglund
2012-07-05 16:15:01 +02:00
82 changed files with 4090 additions and 6527 deletions
+28 -39
View File
@@ -1,69 +1,58 @@
set(STATIC_DEPS libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
set(SHARED_DEPS libglfwShared ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
link_libraries(glfw ${OPENGL_glu_LIBRARY})
if (BUILD_SHARED_LIBS)
add_definitions(-DGLFW_DLL)
link_libraries(${OPENGL_gl_LIBRARY} ${MATH_LIBRARY})
else()
link_libraries(${glfw_LIBRARIES})
endif()
include_directories(${GLFW_SOURCE_DIR}/include
${GLFW_SOURCE_DIR}/support
${OPENGL_INCLUDE_DIR})
add_executable(clipboard clipboard.c getopt.c)
add_executable(defaults defaults.c)
target_link_libraries(defaults ${STATIC_DEPS})
add_executable(dynamic dynamic.c)
target_link_libraries(dynamic ${SHARED_DEPS})
add_executable(events events.c)
target_link_libraries(events ${STATIC_DEPS})
add_executable(fsaa fsaa.c getopt.c)
target_link_libraries(fsaa ${STATIC_DEPS})
add_executable(fsfocus fsfocus.c)
target_link_libraries(fsfocus ${STATIC_DEPS})
add_executable(gamma gamma.c getopt.c)
target_link_libraries(gamma ${STATIC_DEPS})
add_executable(glfwinfo glfwinfo.c getopt.c)
target_link_libraries(glfwinfo ${STATIC_DEPS})
add_executable(iconify iconify.c getopt.c)
target_link_libraries(iconify ${STATIC_DEPS})
add_executable(joysticks joysticks.c)
target_link_libraries(joysticks ${STATIC_DEPS})
add_executable(listmodes listmodes.c)
target_link_libraries(listmodes ${STATIC_DEPS})
add_executable(modes modes.c getopt.c)
add_executable(peter peter.c)
target_link_libraries(peter ${STATIC_DEPS})
add_executable(reopen reopen.c)
target_link_libraries(reopen ${STATIC_DEPS})
add_executable(accuracy WIN32 MACOSX_BUNDLE accuracy.c)
target_link_libraries(accuracy ${STATIC_DEPS})
set_target_properties(accuracy PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Accuracy")
add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c)
target_link_libraries(sharing ${STATIC_DEPS})
set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing")
add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c)
target_link_libraries(tearing ${STATIC_DEPS})
set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing")
add_executable(title WIN32 MACOSX_BUNDLE title.c)
target_link_libraries(title ${STATIC_DEPS})
set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title")
add_executable(windows WIN32 MACOSX_BUNDLE windows.c)
target_link_libraries(windows ${STATIC_DEPS})
set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows")
set(WINDOWS_BINARIES accuracy sharing tearing title windows)
set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify
joysticks listmodes peter reopen)
set(CONSOLE_BINARIES clipboard defaults events fsaa fsfocus gamma glfwinfo
iconify joysticks modes peter reopen)
if(MSVC)
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
LINK_FLAGS "/ENTRY:mainCRTStartup")
endif(MSVC)
if (MSVC)
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
LINK_FLAGS "/ENTRY:mainCRTStartup")
endif()
if (APPLE)
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION}
MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL})
endif()
+4 -3
View File
@@ -29,6 +29,7 @@
//
//========================================================================
#define GLFW_INCLUDE_GLU
#include <GL/glfw3.h>
#include <stdio.h>
@@ -49,7 +50,7 @@ static void window_size_callback(GLFWwindow window, int width, int height)
gluOrtho2D(0.f, window_width, 0.f, window_height);
}
static void mouse_position_callback(GLFWwindow window, int x, int y)
static void cursor_position_callback(GLFWwindow window, int x, int y)
{
cursor_x = x;
cursor_y = y;
@@ -59,7 +60,7 @@ int main(void)
{
GLFWwindow window;
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
@@ -74,7 +75,7 @@ int main(void)
exit(EXIT_FAILURE);
}
glfwSetMousePosCallback(mouse_position_callback);
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
+153
View File
@@ -0,0 +1,153 @@
//========================================================================
// Clipboard test program
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This program is used to test the clipboard functionality.
//
//========================================================================
#include <GL/glfw3.h>
#include <stdio.h>
#include <stdlib.h>
#include "getopt.h"
static void usage(void)
{
printf("Usage: clipboard [-h]\n");
}
static GLboolean control_is_down(GLFWwindow window)
{
return glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) ||
glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL);
}
static void key_callback(GLFWwindow window, int key, int action)
{
if (action != GLFW_PRESS)
return;
switch (key)
{
case GLFW_KEY_ESCAPE:
glfwCloseWindow(window);
break;
case GLFW_KEY_V:
if (control_is_down(window))
{
const char* string;
string = glfwGetClipboardString(window);
if (string)
printf("Clipboard contains \"%s\"\n", string);
else
printf("Clipboard does not contain a string\n");
}
break;
case GLFW_KEY_C:
if (control_is_down(window))
{
const char* string = "Hello GLFW World!";
glfwSetClipboardString(window, string);
printf("Setting clipboard to \"%s\"\n", string);
}
break;
}
}
static void size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
}
static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error in %s\n", description);
}
int main(int argc, char** argv)
{
int ch;
GLFWwindow window;
while ((ch = getopt(argc, argv, "h")) != -1)
{
switch (ch)
{
case 'h':
usage();
exit(EXIT_SUCCESS);
default:
usage();
exit(EXIT_FAILURE);
}
}
glfwSetErrorCallback(error_callback);
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Clipboard Test", NULL);
if (!window)
{
glfwTerminate();
fprintf(stderr, "Failed to open GLFW window\n");
exit(EXIT_FAILURE);
}
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(size_callback);
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.5f, 0.5f, 0.5f, 0);
while (glfwIsWindow(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.8f, 0.2f, 0.4f);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
glfwSwapBuffers();
glfwWaitEvents();
}
glfwTerminate();
exit(EXIT_SUCCESS);
}
+1 -1
View File
@@ -69,7 +69,7 @@ int main(void)
int i, width, height;
GLFWwindow window;
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
-91
View File
@@ -1,91 +0,0 @@
//========================================================================
// Dynamic linking test
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test came about as the result of bug #3060461
//
//========================================================================
#define GLFW_DLL
#include <GL/glfw3.h>
#include <stdio.h>
#include <stdlib.h>
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
}
int main(void)
{
GLFWwindow window;
int major, minor, rev;
glfwGetVersion(&major, &minor, &rev);
printf("GLFW header version: %i.%i.%i\n",
GLFW_VERSION_MAJOR,
GLFW_VERSION_MINOR,
GLFW_VERSION_REVISION);
printf("GLFW library version: %i.%i.%i\n", major, minor, rev);
printf("GLFW library version string: %s\n", glfwGetVersionString());
if (major != GLFW_VERSION_MAJOR ||
minor != GLFW_VERSION_MINOR ||
rev != GLFW_VERSION_REVISION)
{
fprintf(stderr, "GLFW library version mismatch\n");
exit(EXIT_FAILURE);
}
if (!glfwInit(NULL))
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Dynamic Linking Test", NULL);
if (!window)
{
glfwTerminate();
fprintf(stderr, "Failed to open GLFW window\n");
exit(EXIT_FAILURE);
}
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
while (glfwIsWindow(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwPollEvents();
}
glfwTerminate();
exit(EXIT_SUCCESS);
}
+27 -9
View File
@@ -40,8 +40,9 @@
#include <ctype.h>
#include <locale.h>
static GLboolean keyrepeat = 0;
static GLboolean systemkeys = 1;
static GLboolean keyrepeat = GL_FALSE;
static GLboolean systemkeys = GL_TRUE;
static GLboolean closeable = GL_TRUE;
static unsigned int counter = 0;
static const char* get_key_name(int key)
@@ -243,7 +244,7 @@ static void window_size_callback(GLFWwindow window, int width, int height)
static int window_close_callback(GLFWwindow window)
{
printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime());
return 1;
return closeable;
}
static void window_refresh_callback(GLFWwindow window)
@@ -282,14 +283,22 @@ static void mouse_button_callback(GLFWwindow window, int button, int action)
printf(" was %s\n", get_action_name(action));
}
static void mouse_position_callback(GLFWwindow window, int x, int y)
static void cursor_position_callback(GLFWwindow window, int x, int y)
{
printf("%08x at %0.3f: Mouse position: %i %i\n", counter++, glfwGetTime(), x, y);
printf("%08x at %0.3f: Cursor position: %i %i\n", counter++, glfwGetTime(), x, y);
}
static void scroll_callback(GLFWwindow window, int x, int y)
static void cursor_enter_callback(GLFWwindow window, int entered)
{
printf("%08x at %0.3f: Scroll: %i %i\n", counter++, glfwGetTime(), x, y);
printf("%08x at %0.3f: Cursor %s window\n",
counter++,
glfwGetTime(),
entered ? "entered" : "left");
}
static void scroll_callback(GLFWwindow window, double x, double y)
{
printf("%08x at %0.3f: Scroll: %0.3f %0.3f\n", counter++, glfwGetTime(), x, y);
}
static void key_callback(GLFWwindow window, int key, int action)
@@ -325,6 +334,14 @@ static void key_callback(GLFWwindow window, int key, int action)
printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
break;
}
case GLFW_KEY_C:
{
closeable = !closeable;
printf("(( closing %s ))\n", closeable ? "enabled" : "disabled");
break;
}
}
}
@@ -353,7 +370,7 @@ int main(void)
setlocale(LC_ALL, "");
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
@@ -367,7 +384,8 @@ int main(void)
glfwSetWindowFocusCallback(window_focus_callback);
glfwSetWindowIconifyCallback(window_iconify_callback);
glfwSetMouseButtonCallback(mouse_button_callback);
glfwSetMousePosCallback(mouse_position_callback);
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetCursorEnterCallback(cursor_enter_callback);
glfwSetScrollCallback(scroll_callback);
glfwSetKeyCallback(key_callback);
glfwSetCharCallback(char_callback);
+2 -1
View File
@@ -29,6 +29,7 @@
//
//========================================================================
#define GLFW_INCLUDE_GLU
#include <GL/glfw3.h>
#include <GL/glext.h>
@@ -81,7 +82,7 @@ int main(int argc, char** argv)
}
}
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
+1 -1
View File
@@ -75,7 +75,7 @@ int main(void)
{
GLFWwindow window;
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
+24 -9
View File
@@ -35,11 +35,20 @@
#include "getopt.h"
#define STEP_SIZE 0.1f
static GLfloat gamma = 1.0f;
static void usage(void)
{
printf("Usage: gammatest [-h] [-f]\n");
printf("Usage: gamma [-h] [-f]\n");
}
static void set_gamma(float value)
{
gamma = value;
printf("Gamma: %f\n", gamma);
glfwSetGamma(gamma);
}
static void key_callback(GLFWwindow window, int key, int action)
@@ -50,20 +59,26 @@ static void key_callback(GLFWwindow window, int key, int action)
switch (key)
{
case GLFW_KEY_ESCAPE:
{
glfwCloseWindow(window);
break;
}
case GLFW_KEY_KP_ADD:
case GLFW_KEY_Q:
gamma += 0.1f;
printf("Gamma: %f\n", gamma);
glfwSetGamma(gamma);
{
set_gamma(gamma + STEP_SIZE);
break;
}
case GLFW_KEY_KP_SUBTRACT:
case GLFW_KEY_W:
gamma -= 0.1f;
printf("Gamma: %f\n", gamma);
glfwSetGamma(gamma);
{
if (gamma - STEP_SIZE > 0.f)
set_gamma(gamma - STEP_SIZE);
break;
}
}
}
@@ -96,7 +111,7 @@ int main(int argc, char** argv)
}
}
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
@@ -124,7 +139,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
printf("Gamma: %f\n", gamma);
set_gamma(1.f);
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);
+3 -3
View File
@@ -51,7 +51,7 @@
static void usage(void)
{
printf("Usage: version [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n");
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("available strategies: " STRATEGY_NAME_NONE " " STRATEGY_NAME_LOSE "\n");
}
@@ -183,7 +183,7 @@ int main(int argc, char** argv)
glfwSetErrorCallback(error_callback);
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
@@ -263,7 +263,7 @@ int main(int argc, char** argv)
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: %s (0x%08x)\n", get_profile_name(mask), mask);
printf("OpenGL profile parsed by GLFW: %s\n",
get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE)));
+3 -1
View File
@@ -62,6 +62,8 @@ static void key_callback(GLFWwindow window, int key, int action)
static void size_callback(GLFWwindow window, int width, int height)
{
printf("%0.2f Size %ix%i\n", glfwGetTime(), width, height);
glViewport(0, 0, width, height);
}
@@ -90,7 +92,7 @@ int main(int argc, char** argv)
}
}
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
+168 -94
View File
@@ -1,142 +1,216 @@
/*========================================================================
* This is a small test application for GLFW.
* joystick input test.
*========================================================================*/
//========================================================================
// Joystick input test
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test displays the state of every button and axis of every connected
// joystick and/or gamepad
//
//========================================================================
#include <GL/glfw3.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX_AXES 10
#define MAX_BUTTONS 30
struct JoystickState
typedef struct Joystick
{
int present;
int num_axes;
int num_buttons;
float axes[MAX_AXES];
unsigned char buttons[MAX_BUTTONS];
};
GLboolean present;
float* axes;
unsigned char* buttons;
int axis_count;
int button_count;
} Joystick;
static struct JoystickState states[GLFW_JOYSTICK_LAST + 1];
static Joystick joysticks[GLFW_JOYSTICK_LAST - GLFW_JOYSTICK_1 + 1];
int running;
int keyrepeat = 0;
int systemkeys = 1;
static int joystick_count = 0;
/*========================================================================
* Retrieve joystick states
*========================================================================*/
static void updateJoysticksState(void)
static void window_size_callback(GLFWwindow window, int width, int height)
{
int joy;
glViewport(0, 0, width, height);
}
for (joy = GLFW_JOYSTICK_1; joy < GLFW_JOYSTICK_LAST + 1; joy++)
static void draw_joystick(Joystick* j, int x, int y, int width, int height)
{
int i;
int axis_width, axis_height;
int button_width, button_height;
axis_width = width / j->axis_count;
axis_height = 3 * height / 4;
button_width = width / j->button_count;
button_height = height / 4;
for (i = 0; i < j->axis_count; i++)
{
printf("Updating information for joystick %d\n", joy);
states[joy].present = glfwGetJoystickParam(joy, GLFW_PRESENT);
if (states[joy].present == GL_TRUE)
float value = j->axes[i] / 2.f + 0.5f;
glColor3f(0.3f, 0.3f, 0.3f);
glRecti(x + i * axis_width,
y,
x + (i + 1) * axis_width,
y + axis_height);
glColor3f(1.f, 1.f, 1.f);
glRecti(x + i * axis_width,
y + (int) (value * (axis_height - 5)),
x + (i + 1) * axis_width,
y + 5 + (int) (value * (axis_height - 5)));
}
for (i = 0; i < j->button_count; i++)
{
if (j->buttons[i])
glColor3f(1.f, 1.f, 1.f);
else
glColor3f(0.3f, 0.3f, 0.3f);
glRecti(x + i * button_width,
y + axis_height,
x + (i + 1) * button_width,
y + axis_height + button_height);
}
}
static void draw_joysticks(void)
{
int i, width, height;
glfwGetWindowSize(glfwGetCurrentContext(), &width, &height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.f, width, height, 0.f, 1.f, -1.f);
glMatrixMode(GL_MODELVIEW);
for (i = 0; i < sizeof(joysticks) / sizeof(Joystick); i++)
{
Joystick* j = joysticks + i;
if (j->present)
{
states[joy].num_axes = glfwGetJoystickPos(joy, states[joy].axes, MAX_AXES);
states[joy].num_buttons = glfwGetJoystickButtons(joy, states[joy].buttons, MAX_BUTTONS);
draw_joystick(j,
0, i * height / joystick_count,
width, height / joystick_count);
}
}
}
/*========================================================================
* Print out the state of all joysticks on the standard output
*========================================================================*/
static void displayJoysticksState(void)
static void refresh_joysticks(void)
{
int joy;
int i;
for (joy = GLFW_JOYSTICK_1; joy < GLFW_JOYSTICK_LAST + 1; joy++)
for (i = 0; i < sizeof(joysticks) / sizeof(Joystick); i++)
{
printf("Joystick %d: %s\n", joy, (states[joy].present == GL_TRUE ? "present" : "not connected"));
Joystick* j = joysticks + i;
if (states[joy].present == GL_TRUE)
if (glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_PRESENT))
{
if (states[joy].num_axes > 0)
int axis_count, button_count;
axis_count = glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_AXES);
if (axis_count != j->axis_count)
{
printf(" axes: %.3f", states[joy].axes[0]);
for (i = 1; i < states[joy].num_axes; i++)
printf(", %.3f", states[joy].axes[i]);
printf("\n");
j->axis_count = axis_count;
j->axes = realloc(j->axes, j->axis_count * sizeof(float));
}
else
printf(" axes: none\n");
if (states[joy].num_buttons > 0)
glfwGetJoystickPos(GLFW_JOYSTICK_1 + i, j->axes, j->axis_count);
button_count = glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_BUTTONS);
if (button_count != j->button_count)
{
printf(" buttons: 00 => %c", ((states[joy].buttons[0] == GLFW_PRESS) ? 'P' : 'R'));
for (i = 1; i < states[joy].num_buttons; i++)
printf(", %02d => %c", i, ((states[joy].buttons[i] == GLFW_PRESS) ? 'P' : 'R'));
printf("\n");
j->button_count = button_count;
j->buttons = realloc(j->buttons, j->button_count);
}
glfwGetJoystickButtons(GLFW_JOYSTICK_1 + i, j->buttons, j->button_count);
if (!j->present)
{
printf("Found joystick %i with %i axes, %i buttons\n",
i + 1, j->axis_count, j->button_count);
joystick_count++;
}
j->present = GL_TRUE;
}
else
{
if (j->present)
{
free(j->axes);
free(j->buttons);
memset(j, 0, sizeof(Joystick));
printf("Lost joystick %i\n", i + 1);
joystick_count--;
}
else
printf(" buttons: none\n");
}
}
}
int main(void)
{
double start;
double t;
double update;
GLFWwindow window;
/* Initialise GLFW */
if (!glfwInit(NULL))
memset(joysticks, 0, sizeof(joysticks));
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
printf("The program will work for 20 seconds and display every seconds the state of the joysticks\n");
printf("Your computer is going to be very slow as the program is doing an active loop .....\n");
start = glfwGetTime();
update = start;
/* print the initial state of all joysticks */
updateJoysticksState();
printf("\n");
displayJoysticksState();
running = GL_TRUE;
/* Main loop */
while (running)
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Joystick Test", NULL);
if (!window)
{
/* Get time */
t = glfwGetTime();
glfwTerminate();
/* Display the state of all connected joysticks every secons */
if ((t - update) > 1.0)
{
update = t;
printf("\n");
updateJoysticksState();
printf("\n");
displayJoysticksState();
}
/* Check if the window was closed */
if ((t - start) > 20.0)
running = GL_FALSE;
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
/* Close OpenGL window and terminate GLFW */
glfwTerminate();
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
return 0;
while (glfwIsWindow(window))
{
glClear(GL_COLOR_BUFFER_BIT);
refresh_joysticks();
draw_joysticks();
glfwSwapBuffers();
glfwPollEvents();
}
glfwTerminate();
exit(EXIT_SUCCESS);
}
-62
View File
@@ -1,62 +0,0 @@
//========================================================================
// This is a small test application for GLFW.
// The program lists all available fullscreen video modes.
//========================================================================
#include <GL/glfw3.h>
#include <stdio.h>
#include <stdlib.h>
static void print_mode(GLFWvidmode* mode)
{
printf("%i x %i x %i (%i %i %i)\n",
mode->width, mode->height,
mode->redBits + mode->greenBits + mode->blueBits,
mode->redBits, mode->greenBits, mode->blueBits);
}
int main(void)
{
GLFWmonitor monitor;
GLFWvidmode dtmode, modes[400];
int modecount, i;
if (!glfwInit(NULL))
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
// Show desktop video mode
glfwGetDesktopMode(&dtmode);
printf("Desktop mode: ");
print_mode(&dtmode);
monitor = NULL;
while ((monitor = glfwGetNextMonitor(monitor)))
{
printf("Monitor name: %s\n"
"Physical dimensions: %dmm x %dmm\n"
"Logical position: (%d,%d)\n",
glfwGetMonitorString(monitor, GLFW_MONITOR_NAME),
glfwGetMonitorParam(monitor, GLFW_MONITOR_PHYSICAL_WIDTH),
glfwGetMonitorParam(monitor, GLFW_MONITOR_PHYSICAL_HEIGHT),
glfwGetMonitorParam(monitor, GLFW_MONITOR_SCREEN_POS_X),
glfwGetMonitorParam(monitor, GLFW_MONITOR_SCREEN_POS_Y));
// List available video modes
modecount = glfwGetVideoModes(monitor, modes, sizeof(modes) / sizeof(GLFWvidmode));
printf("Available modes:\n");
for (i = 0; i < modecount; i++)
{
printf("%3i: ", i);
print_mode(modes + i);
}
}
exit(EXIT_SUCCESS);
}
+257
View File
@@ -0,0 +1,257 @@
//========================================================================
// Video mode test
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
//
// This test enumerates or verifies video modes
//
//========================================================================
#include <GL/glfw3.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "getopt.h"
static GLFWwindow window = NULL;
enum Mode
{
LIST_MODE,
TEST_MODE
};
static void usage(void)
{
printf("Usage: modes [-t]\n");
printf(" modes -h\n");
}
static const char* format_mode(GLFWvidmode* mode)
{
static char buffer[512];
snprintf(buffer, sizeof(buffer),
"%i x %i x %i (%i %i %i)",
mode->width, mode->height,
mode->redBits + mode->greenBits + mode->blueBits,
mode->redBits, mode->greenBits, mode->blueBits);
buffer[sizeof(buffer) - 1] = '\0';
return buffer;
}
static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
}
static void window_size_callback(GLFWwindow window, int width, int height)
{
printf("Window resized to %ix%i\n", width, height);
glViewport(0, 0, width, height);
}
static int window_close_callback(GLFWwindow dummy)
{
window = NULL;
return GL_TRUE;
}
static void key_callback(GLFWwindow dummy, int key, int action)
{
if (key == GLFW_KEY_ESCAPE)
{
glfwCloseWindow(window);
window = NULL;
}
}
static GLFWvidmode* get_video_modes(GLFWmonitor monitor, size_t* found)
{
size_t count = 0;
GLFWvidmode* modes = NULL;
for (;;)
{
count += 256;
modes = realloc(modes, sizeof(GLFWvidmode) * count);
*found = glfwGetVideoModes(monitor, modes, count);
if (*found < count)
break;
}
return modes;
}
static void list_modes(GLFWmonitor monitor)
{
size_t count, i;
GLFWvidmode desktop_mode;
glfwGetDesktopMode(&desktop_mode);
printf("Desktop mode: %s\n", format_mode(&desktop_mode));
GLFWvidmode* modes = get_video_modes(monitor, &count);
printf("Monitor %s:\n", glfwGetMonitorString(monitor, GLFW_MONITOR_NAME));
for (i = 0; i < count; i++)
{
printf("%3u: %s", (unsigned int) i, format_mode(modes + i));
if (memcmp(&desktop_mode, modes + i, sizeof(GLFWvidmode)) == 0)
printf(" (desktop mode)");
putchar('\n');
}
free(modes);
}
static void test_modes(GLFWmonitor monitor)
{
int width, height;
size_t i, count;
GLFWvidmode* modes = get_video_modes(monitor, &count);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetKeyCallback(key_callback);
for (i = 0; i < count; i++)
{
GLFWvidmode* mode = modes + i;
glfwOpenWindowHint(GLFW_RED_BITS, mode->redBits);
glfwOpenWindowHint(GLFW_GREEN_BITS, mode->greenBits);
glfwOpenWindowHint(GLFW_BLUE_BITS, mode->blueBits);
printf("Testing mode %u on monitor %s: %s",
(unsigned int) i,
glfwGetMonitorString(monitor, GLFW_MONITOR_NAME),
format_mode(mode));
window = glfwOpenWindow(mode->width, mode->height,
GLFW_FULLSCREEN, "Video Mode Test",
NULL);
if (!window)
{
printf("Failed to enter mode %u: %s\n",
(unsigned int) i,
format_mode(mode));
continue;
}
glfwSetTime(0.0);
glfwSwapInterval(1);
while (glfwGetTime() < 5.0)
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwPollEvents();
if (!window)
{
printf("User terminated program\n");
exit(EXIT_SUCCESS);
}
}
if (glfwGetWindowParam(window, GLFW_RED_BITS) != mode->redBits ||
glfwGetWindowParam(window, GLFW_GREEN_BITS) != mode->greenBits ||
glfwGetWindowParam(window, GLFW_BLUE_BITS) != mode->blueBits)
{
printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n",
glfwGetWindowParam(window, GLFW_RED_BITS),
glfwGetWindowParam(window, GLFW_GREEN_BITS),
glfwGetWindowParam(window, GLFW_BLUE_BITS),
mode->redBits,
mode->greenBits,
mode->blueBits);
}
glfwGetWindowSize(window, &width, &height);
if (width != mode->width || height != mode->height)
{
printf("*** Size mismatch: %ix%i instead of %ix%i\n",
width, height,
mode->width, mode->height);
}
printf("Closing window\n");
glfwCloseWindow(window);
glfwPollEvents();
window = NULL;
}
free(modes);
}
int main(int argc, char** argv)
{
int ch, mode = LIST_MODE;
GLFWmonitor monitor = NULL;
while ((ch = getopt(argc, argv, "th")) != -1)
{
switch (ch)
{
case 'h':
usage();
exit(EXIT_SUCCESS);
case 't':
mode = TEST_MODE;
break;
default:
usage();
exit(EXIT_FAILURE);
}
}
argc -= optind;
argv += optind;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
while ((monitor = glfwGetNextMonitor(monitor)))
{
if (mode == LIST_MODE)
list_modes(monitor);
else if (mode == TEST_MODE)
test_modes(monitor);
}
exit(EXIT_SUCCESS);
}
+9 -9
View File
@@ -1,5 +1,5 @@
//========================================================================
// Mouse cursor bug test
// Cursor input bug test
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
@@ -41,7 +41,7 @@ static int cursor_y;
static GLboolean open_window(void);
static void toggle_mouse_cursor(GLFWwindow window)
static void toggle_cursor(GLFWwindow window)
{
if (glfwGetInputMode(window, GLFW_CURSOR_MODE) == GLFW_CURSOR_CAPTURED)
{
@@ -55,9 +55,9 @@ static void toggle_mouse_cursor(GLFWwindow window)
}
}
static void mouse_position_callback(GLFWwindow window, int x, int y)
static void cursor_position_callback(GLFWwindow window, int x, int y)
{
printf("Mouse moved to: %i %i (%i %i)\n", x, y, x - cursor_x, y - cursor_y);
printf("Cursor moved to: %i %i (%i %i)\n", x, y, x - cursor_x, y - cursor_y);
cursor_x = x;
cursor_y = y;
}
@@ -69,7 +69,7 @@ static void key_callback(GLFWwindow window, int key, int action)
case GLFW_KEY_SPACE:
{
if (action == GLFW_PRESS)
toggle_mouse_cursor(window);
toggle_cursor(window);
break;
}
@@ -98,11 +98,11 @@ static GLboolean open_window(void)
if (!window_handle)
return GL_FALSE;
glfwGetMousePos(window_handle, &cursor_x, &cursor_y);
printf("Mouse position: %i %i\n", cursor_x, cursor_y);
glfwGetCursorPos(window_handle, &cursor_x, &cursor_y);
printf("Cursor position: %i %i\n", cursor_x, cursor_y);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetMousePosCallback(mouse_position_callback);
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetKeyCallback(key_callback);
glfwSwapInterval(1);
@@ -111,7 +111,7 @@ static GLboolean open_window(void)
int main(void)
{
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
+1 -1
View File
@@ -84,7 +84,7 @@ static GLboolean open_window(int width, int height, int mode)
{
double base;
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
return GL_FALSE;
+7 -3
View File
@@ -27,6 +27,7 @@
//
//========================================================================
#define GLFW_INCLUDE_GLU
#include <GL/glfw3.h>
#include <stdio.h>
@@ -92,8 +93,6 @@ static void draw_quad(GLuint texture)
glBindTexture(GL_TEXTURE_2D, texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glColor3f(0.6f, 0.f, 0.6f);
glBegin(GL_QUADS);
glTexCoord2f(0.f, 0.f);
@@ -117,7 +116,7 @@ int main(int argc, char** argv)
GLuint texture;
int x, y;
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
@@ -142,6 +141,11 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
// Set drawing color for the first context and copy it to the second
glfwMakeContextCurrent(windows[0]);
glColor3f(0.6f, 0.f, 0.6f);
glfwCopyContext(windows[0], windows[1], GL_CURRENT_BIT);
// Put the second window to the right of the first one
glfwGetWindowPos(windows[0], &x, &y);
glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
+24 -3
View File
@@ -34,23 +34,42 @@
#include <stdlib.h>
#include <math.h>
static int swap_interval;
static void set_swap_interval(int value)
{
char title[256];
swap_interval = value;
glfwSwapInterval(swap_interval);
sprintf(title, "Tearing detector (interval %i)", swap_interval);
glfwSetWindowTitle(glfwGetCurrentContext(), title);
}
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
}
static void key_callback(GLFWwindow window, int key, int action)
{
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
set_swap_interval(!swap_interval);
}
int main(void)
{
float position;
GLFWwindow window;
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Tearing Detector", NULL);
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "", NULL);
if (!window)
{
glfwTerminate();
@@ -59,8 +78,10 @@ int main(void)
exit(EXIT_FAILURE);
}
set_swap_interval(1);
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
glfwSetKeyCallback(key_callback);
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
+1 -1
View File
@@ -41,7 +41,7 @@ int main(void)
{
GLFWwindow window;
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
+1 -1
View File
@@ -46,7 +46,7 @@ int main(void)
GLboolean running = GL_TRUE;
GLFWwindow windows[4];
if (!glfwInit(NULL))
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n",
glfwErrorString(glfwGetError()));