Merge branch 'master' into multi-display-support

Conflicts:
	src/CMakeLists.txt
	src/input.c
This commit is contained in:
Marcel Metz 2011-11-22 16:06:24 +01:00
commit 4c6681bad6
17 changed files with 448 additions and 334 deletions

View File

@ -36,7 +36,7 @@ endif (WIN32)
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Set up GLFW for Xlib and GLX on Unix-like systems with X Windows # Set up GLFW for Xlib and GLX on Unix-like systems with X Windows
#-------------------------------------------------------------------- #--------------------------------------------------------------------
if (UNIX AND NOT APPLE AND NOT CYGWIN) if (UNIX AND NOT APPLE)
message(STATUS "Building GLFW for X11 and GLX on a Unix-like system") message(STATUS "Building GLFW for X11 and GLX on a Unix-like system")
# Define the platform identifier # Define the platform identifier
@ -52,7 +52,7 @@ if (UNIX AND NOT APPLE AND NOT CYGWIN)
include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/CheckX11Extensions.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/CheckX11Extensions.cmake)
# Check for XRandR (modern resolution switching extension) # Check for XRandR (modern resolution switching extension)
CHECK_X11_XRANDR() check_x11_xrandr()
if (X11_XRANDR_FOUND) if (X11_XRANDR_FOUND)
set(_GLFW_HAS_XRANDR 1) set(_GLFW_HAS_XRANDR 1)
list(APPEND GLFW_INCLUDE_DIR ${X11_XRANDR_INCLUDE_DIR}) list(APPEND GLFW_INCLUDE_DIR ${X11_XRANDR_INCLUDE_DIR})
@ -60,7 +60,7 @@ if (UNIX AND NOT APPLE AND NOT CYGWIN)
endif(X11_XRANDR_FOUND) endif(X11_XRANDR_FOUND)
# Check for Xf86VidMode (fallback legacy resolution switching extension) # Check for Xf86VidMode (fallback legacy resolution switching extension)
CHECK_X11_XF86VIDMODE() check_x11_xf86vidmode()
if (X11_XF86VIDMODE_FOUND) if (X11_XF86VIDMODE_FOUND)
set(_GLFW_HAS_XF86VIDMODE 1) set(_GLFW_HAS_XF86VIDMODE 1)
list(APPEND GLFW_INCLUDE_DIR ${X11_XF86VIDMODE_INCLUDE_DIR}) list(APPEND GLFW_INCLUDE_DIR ${X11_XF86VIDMODE_INCLUDE_DIR})
@ -68,17 +68,17 @@ if (UNIX AND NOT APPLE AND NOT CYGWIN)
endif(X11_XF86VIDMODE_FOUND) endif(X11_XF86VIDMODE_FOUND)
# Check for Xkb (X keyboard extension) # Check for Xkb (X keyboard extension)
CHECK_FUNCTION_EXISTS(XkbQueryExtension _GLFW_HAS_XKB) check_function_exists(XkbQueryExtension _GLFW_HAS_XKB)
# Check for glXGetProcAddress # Check for glXGetProcAddress
CHECK_FUNCTION_EXISTS(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS) check_function_exists(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS)
if (NOT _GLFW_HAS_GLXGETPROCADDRESS) if (NOT _GLFW_HAS_GLXGETPROCADDRESS)
CHECK_FUNCTION_EXISTS(glXGetProcAddressARB _GLFW_HAS_GLXGETPROCADDRESSARB) check_function_exists(glXGetProcAddressARB _GLFW_HAS_GLXGETPROCADDRESSARB)
endif (NOT _GLFW_HAS_GLXGETPROCADDRESS) endif (NOT _GLFW_HAS_GLXGETPROCADDRESS)
if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB) if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB)
CHECK_FUNCTION_EXISTS(glXGetProcAddressEXT _GLFW_HAS_GLXGETPROCADDRESSEXT) check_function_exists(glXGetProcAddressEXT _GLFW_HAS_GLXGETPROCADDRESSEXT)
endif (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB) endif (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB)
if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND
@ -89,10 +89,15 @@ if (UNIX AND NOT APPLE AND NOT CYGWIN)
NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND
NOT _GLFW_HAS_GLXGETPROCADDRESSEXT) NOT _GLFW_HAS_GLXGETPROCADDRESSEXT)
find_library(LIBRT rt)
if (LIBRT)
list(APPEND GLFW_LIBRARIES ${LIBRT})
endif(LIBRT)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(_GLFW_USE_LINUX_JOYSTICKS 1) set(_GLFW_USE_LINUX_JOYSTICKS 1)
endif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") endif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
endif(UNIX AND NOT APPLE AND NOT CYGWIN) endif(UNIX AND NOT APPLE)
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Set up GLFW for Cocoa and NSOpenGL on Mac OS X # Set up GLFW for Cocoa and NSOpenGL on Mac OS X

View File

@ -38,10 +38,3 @@ if(MSVC)
LINK_FLAGS "/ENTRY:mainCRTStartup") LINK_FLAGS "/ENTRY:mainCRTStartup")
endif(MSVC) endif(MSVC)
if(CYGWIN)
# Set cross-compile and subsystem compile and link flags
set_target_properties(${WINDOWS_BINARIES} PROPERTIES
COMPILE_FLAGS "-mno-cygwin"
LINK_FLAGS "-mno-cygwin -mwindows")
endif(CYGWIN)

View File

@ -583,7 +583,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); glfwOpenWindowHint(GLFW_WINDOW_RESIZABLE, GL_FALSE);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

View File

@ -418,7 +418,7 @@ extern "C" {
#define GLFW_ACCUM_ALPHA_BITS 0x0002100A #define GLFW_ACCUM_ALPHA_BITS 0x0002100A
#define GLFW_AUX_BUFFERS 0x0002100B #define GLFW_AUX_BUFFERS 0x0002100B
#define GLFW_STEREO 0x0002100C #define GLFW_STEREO 0x0002100C
#define GLFW_WINDOW_NO_RESIZE 0x0002100D #define GLFW_WINDOW_RESIZABLE 0x0002100D
#define GLFW_FSAA_SAMPLES 0x0002100E #define GLFW_FSAA_SAMPLES 0x0002100E
#define GLFW_OPENGL_VERSION_MAJOR 0x0002100F #define GLFW_OPENGL_VERSION_MAJOR 0x0002100F
#define GLFW_OPENGL_VERSION_MINOR 0x00021010 #define GLFW_OPENGL_VERSION_MINOR 0x00021010

View File

@ -281,12 +281,14 @@ version of GLFW.</p>
<li>Added <code>GLFW_INCLUDE_GL3</code> macro for telling the GLFW header to include <code>gl3.h</code> header instead of <code>gl.h</code></li> <li>Added <code>GLFW_INCLUDE_GL3</code> macro for telling the GLFW header to include <code>gl3.h</code> header instead of <code>gl.h</code></li>
<li>Added <code>windows</code> simple multi-window test program</li> <li>Added <code>windows</code> simple multi-window test program</li>
<li>Added <code>sharing</code> simple OpenGL object sharing test program</li> <li>Added <code>sharing</code> simple OpenGL object sharing test program</li>
<li>Added <code>dynamic</code> simple dynamic linking test program</li>
<li>Added a parameter to <code>glfwOpenWindow</code> for specifying a context the new window's context will share objects with</li> <li>Added a parameter to <code>glfwOpenWindow</code> for specifying a context the new window's context will share objects with</li>
<li>Added initial window title parameter to <code>glfwOpenWindow</code></li> <li>Added initial window title parameter to <code>glfwOpenWindow</code></li>
<li>Added <code>glfwSetGamma</code>, <code>glfwSetGammaRamp</code> and <code>glfwGetGammaRamp</code> functions and <code>GLFWgammaramp</code> type for monitor gamma ramp control</li> <li>Added <code>glfwSetGamma</code>, <code>glfwSetGammaRamp</code> and <code>glfwGetGammaRamp</code> functions and <code>GLFWgammaramp</code> type for monitor gamma ramp control</li>
<li>Changed buffer bit depth parameters of <code>glfwOpenWindow</code> to window hints</li> <li>Changed buffer bit depth parameters of <code>glfwOpenWindow</code> to window hints</li>
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li> <li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li>
<li>Renamed <code>GLFW_WINDOW</code> token to <code>GLFW_WINDOWED</code></li> <li>Renamed <code>GLFW_WINDOW</code> token to <code>GLFW_WINDOWED</code></li>
<li>Renamed <code>GLFW_WINDOW_NO_RESIZE</code> to <code>GLFW_WINDOW_RESIZABLE</code></li>
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li> <li>Renamed <code>version</code> test to <code>glfwinfo</code></li>
<li>Replaced ad hoc build system with CMake</li> <li>Replaced ad hoc build system with CMake</li>
<li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li> <li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li>

View File

@ -3,18 +3,6 @@ if(WIN32)
add_definitions(-DWINVER=0x0501) add_definitions(-DWINVER=0x0501)
endif(WIN32) endif(WIN32)
if(CYGWIN)
# These lines are intended to remove the --export-all-symbols
# flag added in the Modules/Platform/CYGWIN.cmake file of the
# CMake distribution.
# This is a HACK. If you have trouble _linking_ the GLFW
# _shared_ library on Cygwin, try disabling this.
set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")
set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
endif(CYGWIN)
if(UNIX) if(UNIX)
if(_GLFW_HAS_XRANDR) if(_GLFW_HAS_XRANDR)
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr") set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr")
@ -71,13 +59,6 @@ if(WIN32)
IMPORT_SUFFIX "dll.lib") IMPORT_SUFFIX "dll.lib")
endif(WIN32) endif(WIN32)
if(CYGWIN)
# Build for the regular Win32 environment (not Cygwin)
set_target_properties(libglfwStatic libglfwShared PROPERTIES
COMPILE_FLAGS "-mwin32 -mno-cygwin"
LINK_FLAGS "-mwin32 -mno-cygwin")
endif(CYGWIN)
if(APPLE) if(APPLE)
# Append -fno-common to the compile flags to work around a bug in the Apple GCC # Append -fno-common to the compile flags to work around a bug in the Apple GCC
get_target_property(CFLAGS libglfwShared COMPILE_FLAGS) get_target_property(CFLAGS libglfwShared COMPILE_FLAGS)

View File

@ -109,7 +109,7 @@ static NSString* findAppName(void)
char** progname = _NSGetProgname(); char** progname = _NSGetProgname();
if (progname && *progname) if (progname && *progname)
{ {
// TODO: UTF8? // TODO: UTF-8?
return [NSString stringWithUTF8String:*progname]; return [NSString stringWithUTF8String:*progname];
} }
@ -202,7 +202,7 @@ int _glfwPlatformInit(void)
[GLFWApplication sharedApplication]; [GLFWApplication sharedApplication];
_glfwLibrary.NS.OpenGLFramework = _glfwLibrary.NS.OpenGLFramework =
CFBundleGetBundleWithIdentifier( CFSTR( "com.apple.opengl" ) ); CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
if (_glfwLibrary.NS.OpenGLFramework == NULL) if (_glfwLibrary.NS.OpenGLFramework == NULL)
{ {
_glfwSetError(GLFW_PLATFORM_ERROR, _glfwSetError(GLFW_PLATFORM_ERROR,

View File

@ -67,11 +67,8 @@
NSRect contentRect = NSRect contentRect =
[window->NS.window contentRectForFrameRect:[window->NS.window frame]]; [window->NS.window contentRectForFrameRect:[window->NS.window frame]];
window->width = contentRect.size.width;
window->height = contentRect.size.height;
if (_glfwLibrary.windowSizeCallback) _glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height);
_glfwLibrary.windowSizeCallback(window, window->width, window->height);
} }
- (void)windowDidMove:(NSNotification *)notification - (void)windowDidMove:(NSNotification *)notification
@ -87,24 +84,17 @@
mainScreenHeight - contentRect.origin.y - mainScreenHeight - contentRect.origin.y -
mainScreenOrigin.y - window->height); mainScreenOrigin.y - window->height);
window->positionX = flippedPos.x; _glfwInputWindowPos(window, flippedPos.x, flippedPos.y);
window->positionY = flippedPos.y;
} }
- (void)windowDidMiniaturize:(NSNotification *)notification - (void)windowDidMiniaturize:(NSNotification *)notification
{ {
window->iconified = GL_TRUE; _glfwInputWindowIconify(window, GL_TRUE);
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
} }
- (void)windowDidDeminiaturize:(NSNotification *)notification - (void)windowDidDeminiaturize:(NSNotification *)notification
{ {
window->iconified = GL_FALSE; _glfwInputWindowIconify(window, GL_FALSE);
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
} }
- (void)windowDidBecomeKey:(NSNotification *)notification - (void)windowDidBecomeKey:(NSNotification *)notification
@ -349,24 +339,15 @@ static int convertMacKeyCode(unsigned int macKeyCode)
- (void)mouseMoved:(NSEvent *)event - (void)mouseMoved:(NSEvent *)event
{ {
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ _glfwInputCursorMotion(window, [event deltaX], [event deltaY]);
window->mousePosX += [event deltaX];
window->mousePosY += [event deltaY];
}
else else
{ {
NSPoint p = [event locationInWindow]; NSPoint p = [event locationInWindow];
// Cocoa coordinate system has origin at lower left // Cocoa coordinate system has origin at lower left
window->mousePosX = p.x; p.y = [[window->NS.window contentView] bounds].size.height - p.y;
window->mousePosY = [[window->NS.window contentView] bounds].size.height - p.y;
}
if (_glfwLibrary.mousePosCallback) _glfwInputCursorMotion(window, p.x, p.y);
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
} }
} }
@ -587,7 +568,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
styleMask = NSTitledWindowMask | NSClosableWindowMask | styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask; NSMiniaturizableWindowMask;
if (!wndconfig->windowNoResize) if (wndconfig->resizable)
styleMask |= NSResizableWindowMask; styleMask |= NSResizableWindowMask;
} }
else else
@ -707,10 +688,10 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
NSPoint point = [[NSCursor currentCursor] hotSpot]; NSPoint point = [[NSCursor currentCursor] hotSpot];
window->mousePosX = point.x; window->cursorPosX = point.x;
window->mousePosY = point.y; window->cursorPosY = point.y;
window->windowNoResize = wndconfig->windowNoResize; window->resizable = wndconfig->resizable;
return GL_TRUE; return GL_TRUE;
} }

View File

@ -31,6 +31,119 @@
#include "internal.h" #include "internal.h"
//////////////////////////////////////////////////////////////////////////
////// GLFW internal API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Register keyboard activity
//========================================================================
void _glfwInputKey(_GLFWwindow* window, int key, int action)
{
GLboolean keyrepeat = GL_FALSE;
if (key < 0 || key > GLFW_KEY_LAST)
return;
// Are we trying to release an already released key?
if (action == GLFW_RELEASE && window->key[key] != GLFW_PRESS)
return;
// Register key action
if(action == GLFW_RELEASE && window->stickyKeys)
window->key[key] = GLFW_STICK;
else
{
keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
window->key[key] = (char) action;
}
// Call user callback function
if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat))
_glfwLibrary.keyCallback(window, key, action);
}
//========================================================================
// Register (keyboard) character activity
//========================================================================
void _glfwInputChar(_GLFWwindow* window, int character)
{
// Valid Unicode (ISO 10646) character?
if (!((character >= 32 && character <= 126) || character >= 160))
return;
if (_glfwLibrary.charCallback)
_glfwLibrary.charCallback(window, character);
}
//========================================================================
// Register scroll events
//========================================================================
void _glfwInputScroll(_GLFWwindow* window, int xoffset, int yoffset)
{
window->scrollX += xoffset;
window->scrollY += yoffset;
if (_glfwLibrary.scrollCallback)
_glfwLibrary.scrollCallback(window, xoffset, yoffset);
}
//========================================================================
// Register mouse button clicks
//========================================================================
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
{
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
return;
// Register mouse button action
if (action == GLFW_RELEASE && window->stickyMouseButtons)
window->mouseButton[button] = GLFW_STICK;
else
window->mouseButton[button] = (char) action;
if (_glfwLibrary.mouseButtonCallback)
_glfwLibrary.mouseButtonCallback(window, button, action);
}
//========================================================================
// Register cursor moves
//========================================================================
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
{
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
if (!x && !y)
return;
window->cursorPosX += x;
window->cursorPosY += y;
}
else
{
if (window->cursorPosX == x && window->cursorPosY == y)
return;
window->cursorPosX = x;
window->cursorPosY = y;
}
if (_glfwLibrary.mousePosCallback)
_glfwLibrary.mousePosCallback(window,
window->cursorPosX,
window->cursorPosY);
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW public API ////// ////// GLFW public API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -118,10 +231,10 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
// Return mouse position // Return mouse position
if (xpos != NULL) if (xpos != NULL)
*xpos = window->mousePosX; *xpos = window->cursorPosX;
if (ypos != NULL) if (ypos != NULL)
*ypos = window->mousePosY; *ypos = window->cursorPosY;
} }
@ -147,12 +260,12 @@ GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos)
} }
// Don't do anything if the mouse position did not change // Don't do anything if the mouse position did not change
if (xpos == window->mousePosX && ypos == window->mousePosY) if (xpos == window->cursorPosX && ypos == window->cursorPosY)
return; return;
// Set GLFW mouse position // Set GLFW mouse position
window->mousePosX = xpos; window->cursorPosX = xpos;
window->mousePosY = ypos; window->cursorPosY = ypos;
// Do not move physical cursor in locked cursor mode // Do not move physical cursor in locked cursor mode
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
@ -191,8 +304,7 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset)
GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode) GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
{ {
int centerPosX; int centerPosX, centerPosY;
int centerPosY;
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized) if (!_glfwInitialized)
@ -216,25 +328,13 @@ GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
centerPosY = window->height / 2; centerPosY = window->height / 2;
if (mode == GLFW_CURSOR_CAPTURED) if (mode == GLFW_CURSOR_CAPTURED)
{
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY); _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
}
else if (window->cursorMode == GLFW_CURSOR_CAPTURED) else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
if (centerPosX != window->mousePosX || centerPosY != window->mousePosY) _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
{ _glfwInputCursorMotion(window,
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY); centerPosX - window->cursorPosX,
centerPosY - window->cursorPosY);
window->mousePosX = centerPosX;
window->mousePosY = centerPosY;
if (_glfwLibrary.mousePosCallback)
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
}
}
} }
_glfwPlatformSetCursorMode(window, mode); _glfwPlatformSetCursorMode(window, mode);
@ -313,7 +413,7 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
_GLFWwindow* window; _GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; window = window->next) for (window = _glfwLibrary.windowListHead; window; window = window->next)
cbfun(window, window->mousePosX, window->mousePosY); cbfun(window, window->cursorPosX, window->cursorPosY);
} }
} }

View File

@ -104,7 +104,7 @@ struct _GLFWhints
int accumAlphaBits; int accumAlphaBits;
int auxBuffers; int auxBuffers;
GLboolean stereo; GLboolean stereo;
GLboolean windowNoResize; GLboolean resizable;
int samples; int samples;
int glMajor; int glMajor;
int glMinor; int glMinor;
@ -126,7 +126,7 @@ struct _GLFWwndconfig
int mode; int mode;
const char* title; const char* title;
int refreshRate; int refreshRate;
GLboolean windowNoResize; GLboolean resizable;
int glMajor; int glMajor;
int glMinor; int glMinor;
GLboolean glForward; GLboolean glForward;
@ -176,7 +176,7 @@ struct _GLFWwindow
int width, height; int width, height;
int positionX, positionY; int positionX, positionY;
int mode; // GLFW_WINDOW or GLFW_FULLSCREEN int mode; // GLFW_WINDOW or GLFW_FULLSCREEN
GLboolean windowNoResize; // resize- and maximize gadgets disabled flag GLboolean resizable; // GL_TRUE if user may resize this window
int refreshRate; // monitor refresh rate int refreshRate; // monitor refresh rate
void* userPointer; void* userPointer;
@ -185,7 +185,7 @@ struct _GLFWwindow
GLboolean stickyMouseButtons; GLboolean stickyMouseButtons;
GLboolean keyRepeat; GLboolean keyRepeat;
GLboolean sysKeysDisabled; // system keys disabled flag GLboolean sysKeysDisabled; // system keys disabled flag
int mousePosX, mousePosY; int cursorPosX, cursorPosY;
int cursorMode; int cursorMode;
int scrollX, scrollY; int scrollX, scrollY;
char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1]; char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
@ -365,12 +365,19 @@ void _glfwSetError(int error, const char* description);
// Window management (window.c) // Window management (window.c)
void _glfwSetDefaultWindowHints(void); void _glfwSetDefaultWindowHints(void);
// Input handling (window.c) // WIndow event notification
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified);
void _glfwInputWindowDamage(_GLFWwindow* window);
// Input event notification
void _glfwInputKey(_GLFWwindow* window, int key, int action); void _glfwInputKey(_GLFWwindow* window, int key, int action);
void _glfwInputChar(_GLFWwindow* window, int character); void _glfwInputChar(_GLFWwindow* window, int character);
void _glfwInputScroll(_GLFWwindow* window, int x, int y); void _glfwInputScroll(_GLFWwindow* window, int x, int y);
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action); void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated); void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y);
// OpenGL context helpers (opengl.c) // OpenGL context helpers (opengl.c)
int _glfwStringInExtensionString(const char* string, const GLubyte* extensions); int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);

View File

@ -851,15 +851,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
} }
_glfwInputWindowFocus(window, active); _glfwInputWindowFocus(window, active);
_glfwInputWindowIconify(window, iconified);
if (iconified != window->iconified)
{
window->iconified = iconified;
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
}
return 0; return 0;
} }
@ -1005,32 +997,27 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (newMouseX != window->Win32.oldMouseX || if (newMouseX != window->Win32.oldMouseX ||
newMouseY != window->Win32.oldMouseY) newMouseY != window->Win32.oldMouseY)
{ {
int x, y;
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
if (_glfwLibrary.activeWindow != window) if (_glfwLibrary.activeWindow != window)
return 0; return 0;
window->mousePosX += newMouseX - x = newMouseX - window->Win32.oldMouseX;
window->Win32.oldMouseX; y = newMouseY - window->Win32.oldMouseY;
window->mousePosY += newMouseY -
window->Win32.oldMouseY;
} }
else else
{ {
window->mousePosX = newMouseX; x = newMouseX;
window->mousePosY = newMouseY; y = newMouseY;
} }
window->Win32.oldMouseX = newMouseX; window->Win32.oldMouseX = newMouseX;
window->Win32.oldMouseY = newMouseY; window->Win32.oldMouseY = newMouseY;
window->Win32.cursorCentered = GL_FALSE; window->Win32.cursorCentered = GL_FALSE;
if (_glfwLibrary.mousePosCallback) _glfwInputCursorMotion(window, x, y);
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
}
} }
return 0; return 0;
@ -1052,9 +1039,6 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_SIZE: case WM_SIZE:
{ {
window->width = LOWORD(lParam);
window->height = HIWORD(lParam);
// If window is in cursor capture mode, update clipping rect // If window is in cursor capture mode, update clipping rect
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
@ -1063,21 +1047,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
ClipCursor(&ClipWindowRect); ClipCursor(&ClipWindowRect);
} }
if (_glfwLibrary.windowSizeCallback) _glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
{
_glfwLibrary.windowSizeCallback(window,
window->width,
window->height);
}
return 0; return 0;
} }
case WM_MOVE: case WM_MOVE:
{ {
window->positionX = LOWORD(lParam);
window->positionY = HIWORD(lParam);
// If window is in cursor capture mode, update clipping rect // If window is in cursor capture mode, update clipping rect
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
@ -1085,15 +1060,15 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (GetWindowRect(window->Win32.handle, &ClipWindowRect)) if (GetWindowRect(window->Win32.handle, &ClipWindowRect))
ClipCursor(&ClipWindowRect); ClipCursor(&ClipWindowRect);
} }
_glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam));
return 0; return 0;
} }
// Was the window contents damaged? // Was the window contents damaged?
case WM_PAINT: case WM_PAINT:
{ {
if (_glfwLibrary.windowRefreshCallback) _glfwInputWindowDamage(window);
_glfwLibrary.windowRefreshCallback(window);
break; break;
} }
@ -1343,7 +1318,7 @@ static int createWindow(_GLFWwindow* window,
{ {
dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
if (!wndconfig->windowNoResize) if (wndconfig->resizable)
{ {
dwStyle |= (WS_MAXIMIZEBOX | WS_SIZEBOX); dwStyle |= (WS_MAXIMIZEBOX | WS_SIZEBOX);
dwExStyle |= WS_EX_WINDOWEDGE; dwExStyle |= WS_EX_WINDOWEDGE;
@ -1405,8 +1380,8 @@ static int createWindow(_GLFWwindow* window,
// Initialize mouse position data // Initialize mouse position data
GetCursorPos(&pos); GetCursorPos(&pos);
ScreenToClient(window->Win32.handle, &pos); ScreenToClient(window->Win32.handle, &pos);
window->Win32.oldMouseX = window->mousePosX = pos.x; window->Win32.oldMouseX = window->cursorPosX = pos.x;
window->Win32.oldMouseY = window->mousePosY = pos.y; window->Win32.oldMouseY = window->cursorPosY = pos.y;
return GL_TRUE; return GL_TRUE;
} }
@ -1820,8 +1795,8 @@ void _glfwPlatformPollEvents(void)
} }
else else
{ {
//window->Win32.oldMouseX = window->mousePosX; //window->Win32.oldMouseX = window->cursorPosX;
//window->Win32.oldMouseY = window->mousePosY; //window->Win32.oldMouseY = window->cursorPosY;
} }
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))

View File

@ -100,85 +100,9 @@ void _glfwSetDefaultWindowHints(void)
// The default minimum OpenGL version is 1.0 // The default minimum OpenGL version is 1.0
_glfwLibrary.hints.glMajor = 1; _glfwLibrary.hints.glMajor = 1;
_glfwLibrary.hints.glMinor = 0; _glfwLibrary.hints.glMinor = 0;
}
// The default is to allow window resizing
//======================================================================== _glfwLibrary.hints.resizable = GL_TRUE;
// Register keyboard activity
//========================================================================
void _glfwInputKey(_GLFWwindow* window, int key, int action)
{
GLboolean keyrepeat = GL_FALSE;
if (key < 0 || key > GLFW_KEY_LAST)
return;
// Are we trying to release an already released key?
if (action == GLFW_RELEASE && window->key[key] != GLFW_PRESS)
return;
// Register key action
if(action == GLFW_RELEASE && window->stickyKeys)
window->key[key] = GLFW_STICK;
else
{
keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
window->key[key] = (char) action;
}
// Call user callback function
if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat))
_glfwLibrary.keyCallback(window, key, action);
}
//========================================================================
// Register (keyboard) character activity
//========================================================================
void _glfwInputChar(_GLFWwindow* window, int character)
{
// Valid Unicode (ISO 10646) character?
if (!((character >= 32 && character <= 126) || character >= 160))
return;
if (_glfwLibrary.charCallback)
_glfwLibrary.charCallback(window, character);
}
//========================================================================
// Register scroll events
//========================================================================
void _glfwInputScroll(_GLFWwindow* window, int xoffset, int yoffset)
{
window->scrollX += xoffset;
window->scrollY += yoffset;
if (_glfwLibrary.scrollCallback)
_glfwLibrary.scrollCallback(window, xoffset, yoffset);
}
//========================================================================
// Register mouse button clicks
//========================================================================
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
{
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
return;
// Register mouse button action
if (action == GLFW_RELEASE && window->stickyMouseButtons)
window->mouseButton[button] = GLFW_STICK;
else
window->mouseButton[button] = (char) action;
if (_glfwLibrary.mouseButtonCallback)
_glfwLibrary.mouseButtonCallback(window, button, action);
} }
@ -227,6 +151,61 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated)
} }
//========================================================================
// Register window position events
//========================================================================
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
{
window->positionX = x;
window->positionY = y;
}
//========================================================================
// Register window size events
//========================================================================
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
{
if (window->width == width && window->height == height)
return;
window->width = width;
window->height = height;
if (_glfwLibrary.windowSizeCallback)
_glfwLibrary.windowSizeCallback(window, width, height);
}
//========================================================================
// Register window size events
//========================================================================
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
{
if (window->iconified == iconified)
return;
window->iconified = iconified;
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, iconified);
}
//========================================================================
// Register window damage events
//========================================================================
void _glfwInputWindowDamage(_GLFWwindow* window)
{
if (_glfwLibrary.windowRefreshCallback)
_glfwLibrary.windowRefreshCallback(window);
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////// GLFW public API ////// ////// GLFW public API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -271,7 +250,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
wndconfig.mode = mode; wndconfig.mode = mode;
wndconfig.title = title; wndconfig.title = title;
wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0); wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0);
wndconfig.windowNoResize = _glfwLibrary.hints.windowNoResize ? GL_TRUE : GL_FALSE; wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE;
wndconfig.glMajor = _glfwLibrary.hints.glMajor; wndconfig.glMajor = _glfwLibrary.hints.glMajor;
wndconfig.glMinor = _glfwLibrary.hints.glMinor; wndconfig.glMinor = _glfwLibrary.hints.glMinor;
wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE; wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE;
@ -443,8 +422,8 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
case GLFW_STEREO: case GLFW_STEREO:
_glfwLibrary.hints.stereo = hint; _glfwLibrary.hints.stereo = hint;
break; break;
case GLFW_WINDOW_NO_RESIZE: case GLFW_WINDOW_RESIZABLE:
_glfwLibrary.hints.windowNoResize = hint; _glfwLibrary.hints.resizable = hint;
break; break;
case GLFW_FSAA_SAMPLES: case GLFW_FSAA_SAMPLES:
_glfwLibrary.hints.samples = hint; _glfwLibrary.hints.samples = hint;
@ -731,8 +710,8 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
return window->stereo; return window->stereo;
case GLFW_REFRESH_RATE: case GLFW_REFRESH_RATE:
return window->refreshRate; return window->refreshRate;
case GLFW_WINDOW_NO_RESIZE: case GLFW_WINDOW_RESIZABLE:
return window->windowNoResize; return window->resizable;
case GLFW_FSAA_SAMPLES: case GLFW_FSAA_SAMPLES:
return window->samples; return window->samples;
case GLFW_OPENGL_VERSION_MAJOR: case GLFW_OPENGL_VERSION_MAJOR:

View File

@ -794,7 +794,7 @@ static GLboolean createWindow(_GLFWwindow* window,
hints->flags = 0; hints->flags = 0;
if (wndconfig->windowNoResize) if (!wndconfig->resizable)
{ {
hints->flags |= (PMinSize | PMaxSize); hints->flags |= (PMinSize | PMaxSize);
hints->min_width = hints->max_width = window->width; hints->min_width = hints->max_width = window->width;
@ -1194,33 +1194,27 @@ static void processSingleEvent(void)
event.xmotion.y != window->X11.cursorPosY) event.xmotion.y != window->X11.cursorPosY)
{ {
// The mouse cursor was moved and we didn't do it // The mouse cursor was moved and we didn't do it
int x, y;
if (window->cursorMode == GLFW_CURSOR_CAPTURED) if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{ {
if (_glfwLibrary.activeWindow != window) if (_glfwLibrary.activeWindow != window)
break; break;
window->mousePosX += event.xmotion.x - x = event.xmotion.x - window->X11.cursorPosX;
window->X11.cursorPosX; y = event.xmotion.y - window->X11.cursorPosY;
window->mousePosY += event.xmotion.y -
window->X11.cursorPosY;
} }
else else
{ {
window->mousePosX = event.xmotion.x; x = event.xmotion.x;
window->mousePosY = event.xmotion.y; y = event.xmotion.y;
} }
window->X11.cursorPosX = event.xmotion.x; window->X11.cursorPosX = event.xmotion.x;
window->X11.cursorPosY = event.xmotion.y; window->X11.cursorPosY = event.xmotion.y;
window->X11.cursorCentered = GL_FALSE; window->X11.cursorCentered = GL_FALSE;
if (_glfwLibrary.mousePosCallback) _glfwInputCursorMotion(window, x, y);
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
}
} }
break; break;
@ -1236,27 +1230,13 @@ static void processSingleEvent(void)
return; return;
} }
if (event.xconfigure.width != window->width || _glfwInputWindowSize(window,
event.xconfigure.height != window->height) event.xconfigure.width,
{ event.xconfigure.height);
// The window was resized
window->width = event.xconfigure.width; _glfwInputWindowPos(window,
window->height = event.xconfigure.height; event.xconfigure.x,
if (_glfwLibrary.windowSizeCallback) event.xconfigure.y);
{
_glfwLibrary.windowSizeCallback(window,
window->width,
window->height);
}
}
if (event.xconfigure.x != window->positionX ||
event.xconfigure.y != window->positionY)
{
window->positionX = event.xconfigure.x;
window->positionY = event.xconfigure.y;
}
break; break;
} }
@ -1305,11 +1285,7 @@ static void processSingleEvent(void)
return; return;
} }
window->iconified = GL_FALSE; _glfwInputWindowIconify(window, GL_FALSE);
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
break; break;
} }
@ -1323,11 +1299,7 @@ static void processSingleEvent(void)
return; return;
} }
window->iconified = GL_TRUE; _glfwInputWindowIconify(window, GL_TRUE);
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
break; break;
} }
@ -1377,9 +1349,7 @@ static void processSingleEvent(void)
return; return;
} }
if (_glfwLibrary.windowRefreshCallback) _glfwInputWindowDamage(window);
_glfwLibrary.windowRefreshCallback(window);
break; break;
} }
@ -1421,8 +1391,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
{ {
_GLFWfbconfig closest; _GLFWfbconfig closest;
window->refreshRate = wndconfig->refreshRate; window->refreshRate = wndconfig->refreshRate;
window->windowNoResize = wndconfig->windowNoResize; window->resizable = wndconfig->resizable;
initGLXExtensions(window); initGLXExtensions(window);
@ -1487,8 +1457,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
// TODO: Probably check for some corner cases here. // TODO: Probably check for some corner cases here.
window->mousePosX = windowX; window->cursorPosX = windowX;
window->mousePosY = windowY; window->cursorPosY = windowY;
} }
return GL_TRUE; return GL_TRUE;
@ -1563,7 +1533,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
&width, &height, &rate); &width, &height, &rate);
} }
if (window->windowNoResize) if (!window->resizable)
{ {
// Update window size restrictions to match new window size // Update window size restrictions to match new window size
@ -1730,7 +1700,7 @@ void _glfwPlatformRefreshWindowParams(void)
&dotclock, &modeline); &dotclock, &modeline);
pixels_per_second = 1000.0f * (float) dotclock; pixels_per_second = 1000.0f * (float) dotclock;
pixels_per_frame = (float) modeline.htotal * modeline.vtotal; pixels_per_frame = (float) modeline.htotal * modeline.vtotal;
window->refreshRate = (int)(pixels_per_second/pixels_per_frame+0.5); window->refreshRate = (int) (pixels_per_second / pixels_per_frame + 0.5);
#endif /*_GLFW_HAS_XF86VIDMODE*/ #endif /*_GLFW_HAS_XF86VIDMODE*/
} }
else else

View File

@ -1,5 +1,6 @@
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})
if (UNIX AND NOT APPLE AND NOT CYGWIN) if (UNIX AND NOT APPLE AND NOT CYGWIN)
find_library(MATH_LIBRARY m) find_library(MATH_LIBRARY m)
@ -12,30 +13,52 @@ include_directories(${GLFW_SOURCE_DIR}/include
${OPENGL_INCLUDE_DIR}) ${OPENGL_INCLUDE_DIR})
add_executable(defaults defaults.c) add_executable(defaults defaults.c)
add_executable(events events.c) target_link_libraries(defaults ${STATIC_DEPS})
add_executable(fsaa fsaa.c getopt.c)
add_executable(fsfocus fsfocus.c)
add_executable(gamma gamma.c getopt.c)
add_executable(glfwinfo glfwinfo.c getopt.c)
add_executable(iconify iconify.c getopt.c)
add_executable(joysticks joysticks.c)
add_executable(listmodes listmodes.c)
add_executable(peter peter.c)
add_executable(reopen reopen.c)
if(APPLE) add_executable(dynamic dynamic.c)
# Set fancy names for bundles target_link_libraries(dynamic ${SHARED_DEPS})
add_executable(Accuracy MACOSX_BUNDLE accuracy.c)
add_executable(Sharing MACOSX_BUNDLE sharing.c) add_executable(events events.c)
add_executable(Tearing MACOSX_BUNDLE tearing.c) target_link_libraries(events ${STATIC_DEPS})
add_executable(Windows MACOSX_BUNDLE windows.c)
else() add_executable(fsaa fsaa.c getopt.c)
# Set boring names for executables target_link_libraries(fsaa ${STATIC_DEPS})
add_executable(accuracy WIN32 accuracy.c)
add_executable(sharing WIN32 sharing.c) add_executable(fsfocus fsfocus.c)
add_executable(tearing WIN32 tearing.c) target_link_libraries(fsfocus ${STATIC_DEPS})
add_executable(windows WIN32 windows.c)
endif(APPLE) 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})
add_executable(accuracy WIN32 MACOSX_BUNDLE accuracy.c)
target_link_libraries(accuracy ${STATIC_DEPS})
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(windows WIN32 MACOSX_BUNDLE windows.c)
target_link_libraries(windows ${STATIC_DEPS})
set(WINDOWS_BINARIES accuracy sharing tearing windows) set(WINDOWS_BINARIES accuracy sharing tearing windows)
set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify
@ -47,13 +70,3 @@ if(MSVC)
LINK_FLAGS "/ENTRY:mainCRTStartup") LINK_FLAGS "/ENTRY:mainCRTStartup")
endif(MSVC) 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
tests/dynamic.c Normal file
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);
}

View File

@ -32,21 +32,28 @@
#include <GL/glfw3.h> #include <GL/glfw3.h>
#include <GL/glext.h> #include <GL/glext.h>
#ifdef _MSC_VER
#define strcasecmp(x, y) _stricmp(x, y)
#endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "getopt.h" #include "getopt.h"
#ifdef _MSC_VER
#define strcasecmp(x, y) _stricmp(x, y)
#endif
#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) static void usage(void)
{ {
printf("Usage: version [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n"); printf("Usage: version [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n");
printf("available profiles: core compat es2\n"); printf("available profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT " " PROFILE_NAME_ES2 "\n");
printf("available strategies: none lose\n"); printf("available strategies: " STRATEGY_NAME_NONE " " STRATEGY_NAME_LOSE "\n");
} }
static void error_callback(int error, const char* description) static void error_callback(int error, const char* description)
@ -57,11 +64,11 @@ static void error_callback(int error, const char* description)
static const char* get_glfw_profile_name(int profile) static const char* get_glfw_profile_name(int profile)
{ {
if (profile == GLFW_OPENGL_COMPAT_PROFILE) if (profile == GLFW_OPENGL_COMPAT_PROFILE)
return "compatibility"; return PROFILE_NAME_COMPAT;
else if (profile == GLFW_OPENGL_CORE_PROFILE) else if (profile == GLFW_OPENGL_CORE_PROFILE)
return "core"; return PROFILE_NAME_CORE;
else if (profile == GLFW_OPENGL_ES2_PROFILE) else if (profile == GLFW_OPENGL_ES2_PROFILE)
return "es2"; return PROFILE_NAME_ES2;
return "unknown"; return "unknown";
} }
@ -69,9 +76,9 @@ static const char* get_glfw_profile_name(int profile)
static const char* get_profile_name(GLint mask) static const char* get_profile_name(GLint mask)
{ {
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
return "compatibility"; return PROFILE_NAME_COMPAT;
if (mask & GL_CONTEXT_CORE_PROFILE_BIT) if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
return "core"; return PROFILE_NAME_CORE;
return "unknown"; return "unknown";
} }
@ -142,11 +149,11 @@ int main(int argc, char** argv)
minor = atoi(optarg); minor = atoi(optarg);
break; break;
case 'p': case 'p':
if (strcasecmp(optarg, "core") == 0) if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0)
profile = GLFW_OPENGL_CORE_PROFILE; profile = GLFW_OPENGL_CORE_PROFILE;
else if (strcasecmp(optarg, "compat") == 0) else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0)
profile = GLFW_OPENGL_COMPAT_PROFILE; profile = GLFW_OPENGL_COMPAT_PROFILE;
else if (strcasecmp(optarg, "es2") == 0) else if (strcasecmp(optarg, PROFILE_NAME_ES2) == 0)
profile = GLFW_OPENGL_ES2_PROFILE; profile = GLFW_OPENGL_ES2_PROFILE;
else else
{ {
@ -155,9 +162,9 @@ int main(int argc, char** argv)
} }
break; break;
case 'r': case 'r':
if (strcasecmp(optarg, "none") == 0) if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0)
strategy = GLFW_OPENGL_NO_RESET_NOTIFICATION; strategy = GLFW_OPENGL_NO_RESET_NOTIFICATION;
else if (strcasecmp(optarg, "lose") == 0) else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0)
strategy = GLFW_OPENGL_LOSE_CONTEXT_ON_RESET; strategy = GLFW_OPENGL_LOSE_CONTEXT_ON_RESET;
else else
{ {
@ -221,7 +228,9 @@ int main(int argc, char** argv)
if (major != GLFW_VERSION_MAJOR || if (major != GLFW_VERSION_MAJOR ||
minor != GLFW_VERSION_MINOR || minor != GLFW_VERSION_MINOR ||
revision != GLFW_VERSION_REVISION) revision != GLFW_VERSION_REVISION)
{
printf("*** WARNING: GLFW version mismatch! ***\n"); printf("*** WARNING: GLFW version mismatch! ***\n");
}
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString()); printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
@ -266,7 +275,7 @@ int main(int argc, char** argv)
if (major > 1) if (major > 1)
{ {
printf("OpenGL context shading language version: \"%s\"\n", printf("OpenGL context shading language version: \"%s\"\n",
glGetString(GL_SHADING_LANGUAGE_VERSION)); glGetString(GL_SHADING_LANGUAGE_VERSION));
} }
// Report OpenGL extensions // Report OpenGL extensions

View File

@ -37,22 +37,32 @@
static GLboolean cursor_captured = GL_FALSE; static GLboolean cursor_captured = GL_FALSE;
static GLFWwindow window_handle = NULL; static GLFWwindow window_handle = NULL;
static int cursor_x;
static int cursor_y;
static GLboolean open_window(void); static GLboolean open_window(void);
static void toggle_mouse_cursor(GLFWwindow window) static void toggle_mouse_cursor(GLFWwindow window)
{ {
if (cursor_captured) if (cursor_captured)
{
printf("Released cursor\n");
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL); glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
}
else else
{
printf("Captured cursor\n");
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED); glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
}
cursor_captured = !cursor_captured; cursor_captured = !cursor_captured;
} }
static void mouse_position_callback(GLFWwindow window, int x, int y) static void mouse_position_callback(GLFWwindow window, int x, int y)
{ {
printf("Mouse moved to: %i %i\n", x, y); printf("Mouse moved to: %i %i (%i %i)\n", x, y, x - cursor_x, y - cursor_y);
cursor_x = x;
cursor_y = y;
} }
static void key_callback(GLFWwindow window, int key, int action) static void key_callback(GLFWwindow window, int key, int action)
@ -87,14 +97,12 @@ static void window_size_callback(GLFWwindow window, int width, int height)
static GLboolean open_window(void) static GLboolean open_window(void)
{ {
int x, y;
window_handle = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Peter Detector", NULL); window_handle = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Peter Detector", NULL);
if (!window_handle) if (!window_handle)
return GL_FALSE; return GL_FALSE;
glfwGetMousePos(window_handle, &x, &y); glfwGetMousePos(window_handle, &cursor_x, &cursor_y);
printf("Mouse position: %i %i\n", x, y); printf("Mouse position: %i %i\n", cursor_x, cursor_y);
glfwSetWindowSizeCallback(window_size_callback); glfwSetWindowSizeCallback(window_size_callback);
glfwSetMousePosCallback(mouse_position_callback); glfwSetMousePosCallback(mouse_position_callback);