Merge branch 'master' of github.com:raedwulf/glfw into clipboard

Conflicts:
	src/CMakeLists.txt
	tests/CMakeLists.txt
This commit is contained in:
Tai Chi Minh Ralph Eastwood
2012-02-19 06:29:48 +00:00
47 changed files with 3272 additions and 761 deletions
+44 -27
View File
@@ -1,39 +1,66 @@
link_libraries(libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
set(STATIC_DEPS libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
set(SHARED_DEPS libglfwShared ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
include_directories(${GLFW_SOURCE_DIR}/include
${GLFW_SOURCE_DIR}/support
${OPENGL_INCLUDE_DIR})
add_executable(clipboard clipboard.c)
target_link_libraries(clipboard ${STATIC_DEPS})
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(peter peter.c)
target_link_libraries(peter ${STATIC_DEPS})
add_executable(reopen reopen.c)
target_link_libraries(reopen ${STATIC_DEPS})
if(APPLE)
# Set fancy names for bundles
add_executable(Accuracy MACOSX_BUNDLE accuracy.c)
add_executable(Sharing MACOSX_BUNDLE sharing.c)
add_executable(Tearing MACOSX_BUNDLE tearing.c)
add_executable(Windows MACOSX_BUNDLE windows.c)
else()
# Set boring names for executables
add_executable(accuracy WIN32 accuracy.c)
add_executable(sharing WIN32 sharing.c)
add_executable(tearing WIN32 tearing.c)
add_executable(windows WIN32 windows.c)
endif(APPLE)
add_executable(accuracy WIN32 MACOSX_BUNDLE accuracy.c)
target_link_libraries(accuracy ${STATIC_DEPS})
set(WINDOWS_BINARIES accuracy sharing tearing windows)
set(CONSOLE_BINARIES clipboard defaults events fsaa fsfocus gamma glfwinfo iconify
add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c)
target_link_libraries(sharing ${STATIC_DEPS})
add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c)
target_link_libraries(tearing ${STATIC_DEPS})
add_executable(title WIN32 MACOSX_BUNDLE title.c)
target_link_libraries(title ${STATIC_DEPS})
add_executable(windows WIN32 MACOSX_BUNDLE windows.c)
target_link_libraries(windows ${STATIC_DEPS})
set(WINDOWS_BINARIES accuracy sharing tearing title windows)
set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify
joysticks listmodes peter reopen)
if(MSVC)
@@ -42,13 +69,3 @@ if(MSVC)
LINK_FLAGS "/ENTRY:mainCRTStartup")
endif(MSVC)
if(CYGWIN)
# Set cross-compile and subsystem compile and link flags
set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
COMPILE_FLAGS "-mno-cygwin")
set_target_properties(${WINDOWS_BINARIES} PROPERTIES
LINK_FLAGS "-mno-cygwin -mwindows")
set_target_properties(${CONSOLE_BINARIES} PROPERTIES
LINK_FLAGS "-mno-cygwin -mconsole")
endif(CYGWIN)
+91
View File
@@ -0,0 +1,91 @@
//========================================================================
// 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())
{
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);
}
+14 -11
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)
@@ -230,7 +231,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)
@@ -298,10 +299,7 @@ static void key_callback(GLFWwindow window, int key, int action)
case GLFW_KEY_R:
{
keyrepeat = !keyrepeat;
if (keyrepeat)
glfwEnable(window, GLFW_KEY_REPEAT);
else
glfwDisable(window, GLFW_KEY_REPEAT);
glfwSetInputMode(window, GLFW_KEY_REPEAT, keyrepeat);
printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled");
break;
@@ -310,14 +308,19 @@ static void key_callback(GLFWwindow window, int key, int action)
case GLFW_KEY_S:
{
systemkeys = !systemkeys;
if (systemkeys)
glfwEnable(window, GLFW_SYSTEM_KEYS);
else
glfwDisable(window, GLFW_SYSTEM_KEYS);
glfwSetInputMode(window, GLFW_SYSTEM_KEYS, systemkeys);
printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
break;
}
case GLFW_KEY_C:
{
closeable = !closeable;
printf("(( closing %s ))\n", closeable ? "enabled" : "disabled");
break;
}
}
}
+1 -1
View File
@@ -91,7 +91,7 @@ int main(void)
}
glfwSwapInterval(1);
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
glfwSetWindowFocusCallback(window_focus_callback);
glfwSetKeyCallback(window_key_callback);
+23 -8
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;
}
}
}
@@ -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);
+1 -1
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");
}
+2
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);
}
+3 -6
View File
@@ -35,7 +35,6 @@
#include <stdio.h>
#include <stdlib.h>
static GLboolean cursor_captured = GL_FALSE;
static GLFWwindow window_handle = NULL;
static int cursor_x;
static int cursor_y;
@@ -44,18 +43,16 @@ static GLboolean open_window(void);
static void toggle_mouse_cursor(GLFWwindow window)
{
if (cursor_captured)
if (glfwGetInputMode(window, GLFW_CURSOR_MODE) == GLFW_CURSOR_CAPTURED)
{
printf("Released cursor\n");
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL);
}
else
{
printf("Captured cursor\n");
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
}
cursor_captured = !cursor_captured;
}
static void mouse_position_callback(GLFWwindow window, int x, int y)
+5 -2
View File
@@ -92,8 +92,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);
@@ -142,6 +140,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);
+23 -2
View File
@@ -34,11 +34,30 @@
#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;
@@ -50,7 +69,7 @@ int main(void)
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);
+70
View File
@@ -0,0 +1,70 @@
//========================================================================
// UTF-8 window title 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 sets a UTF-8 window title
//
//========================================================================
#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;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "English 日本語 русский язык 官話", NULL);
if (!window)
{
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
glfwSwapInterval(1);
glfwSetWindowSizeCallback(window_size_callback);
while (glfwIsWindow(window) == GL_TRUE)
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
glfwWaitEvents();
}
exit(EXIT_SUCCESS);
}