Merge branch 'master' into EGL

This commit is contained in:
Camilla Berglund 2012-12-02 17:11:17 +01:00
commit 14e71833bd
10 changed files with 114 additions and 15 deletions

View File

@ -1539,6 +1539,14 @@ GLFWAPI int glfwGetJoystickAxes(int joy, float* axes, int numaxes);
*/ */
GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
/*! @brief Returns the name of the specified joystick.
* @param[in] joy The joystick to query.
* @return The UTF-8 encoded name of the joystick, or @c NULL if the joystick
* is not present.
* @ingroup input
*/
GLFWAPI const char* glfwGetJoystickName(int joy);
/*! @brief Sets the clipboard to the specified string. /*! @brief Sets the clipboard to the specified string.
* @param[in] window The window that will own the clipboard contents. * @param[in] window The window that will own the clipboard contents.
* @param[in] string A UTF-8 encoded string. * @param[in] string A UTF-8 encoded string.

View File

@ -278,6 +278,7 @@ version of GLFW.</p>
<li>Added <code>glfwSetWindowFocusCallback</code> function and <code>GLFWwindowfocusfun</code> type for receiving window focus events</li> <li>Added <code>glfwSetWindowFocusCallback</code> function and <code>GLFWwindowfocusfun</code> type for receiving window focus events</li>
<li>Added <code>glfwSetWindowIconifyCallback</code> function and <code>GLFWwindowiconifyfun</code> type for receiving window iconification events</li> <li>Added <code>glfwSetWindowIconifyCallback</code> function and <code>GLFWwindowiconifyfun</code> type for receiving window iconification events</li>
<li>Added <code>glfwGetClipboardString</code> and <code>glfwSetClipboardString</code> functions for interacting with the system clipboard</li> <li>Added <code>glfwGetClipboardString</code> and <code>glfwSetClipboardString</code> functions for interacting with the system clipboard</li>
<li>Added <code>glfwGetJoystickName</code> for retrieving the name of a joystick</li>
<li>Added <code>glfwGetCurrentContext</code> function for retrieving the window whose OpenGL context is current</li> <li>Added <code>glfwGetCurrentContext</code> function for retrieving the window whose OpenGL context is current</li>
<li>Added <code>GLFW_SRGB_CAPABLE</code> for requesting sRGB capable framebuffers</li> <li>Added <code>GLFW_SRGB_CAPABLE</code> for requesting sRGB capable framebuffers</li>
<li>Added <code>GLFW_CLIENT_API</code>, <code>GLFW_OPENGL_API</code> and <code>GLFW_OPENGL_ES_API</code> for selecting client API</li> <li>Added <code>GLFW_CLIENT_API</code>, <code>GLFW_OPENGL_API</code> and <code>GLFW_OPENGL_ES_API</code> for selecting client API</li>

View File

@ -68,7 +68,7 @@ typedef struct
typedef struct typedef struct
{ {
int present; int present;
char product[256]; char name[256];
IOHIDDeviceInterface** interface; IOHIDDeviceInterface** interface;
@ -443,9 +443,9 @@ void _glfwInitJoysticks(void)
if (refCF) if (refCF)
{ {
CFStringGetCString(refCF, CFStringGetCString(refCF,
(char*) &(joystick->product), joystick->name,
256, sizeof(joystick->name),
CFStringGetSystemEncoding()); kCFStringEncodingUTF8);
} }
joystick->numAxes = 0; joystick->numAxes = 0;
@ -625,3 +625,13 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
return button; return button;
} }
//========================================================================
// Get joystick name
//========================================================================
const char* _glfwPlatformGetJoystickName(int joy)
{
return _glfwJoysticks[joy].name;
}

View File

@ -285,6 +285,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window);
int _glfwPlatformGetJoystickParam(int joy, int param); int _glfwPlatformGetJoystickParam(int joy, int param);
int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes); int _glfwPlatformGetJoystickAxes(int joy, float* axes, int numaxes);
int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
const char* _glfwPlatformGetJoystickName(int joy);
// Time input // Time input
double _glfwPlatformGetTime(void); double _glfwPlatformGetTime(void);

View File

@ -126,3 +126,25 @@ GLFWAPI int glfwGetJoystickButtons(int joy,
return _glfwPlatformGetJoystickButtons(joy, buttons, numbuttons); return _glfwPlatformGetJoystickButtons(joy, buttons, numbuttons);
} }
//========================================================================
// Get joystick name
//========================================================================
GLFWAPI const char* glfwGetJoystickName(int joy)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
return NULL;
}
if (joy < 0 || joy > GLFW_JOYSTICK_LAST)
{
_glfwSetError(GLFW_INVALID_ENUM, NULL);
return NULL;
}
return _glfwPlatformGetJoystickName(joy);
}

View File

@ -199,15 +199,43 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
if (hats > 0) if (hats > 0)
{ {
int j; int j, value = ji.dwPOV / 100 / 45;
int value = ji.dwPOV / 100 / 45;
if (value < 0 || value > 8) value = 8; if (value < 0 || value > 8)
value = 8;
for (j = 0; j < 4 && button < numbuttons; j++) for (j = 0; j < 4 && button < numbuttons; j++)
{ {
buttons[button++] = directions[value] & (1 << j) ? GLFW_PRESS : GLFW_RELEASE; if (directions[value] & (1 << j))
buttons[button] = GLFW_PRESS;
else
buttons[button] = GLFW_RELEASE;
button++;
} }
} }
return button; return button;
} }
//========================================================================
// Get joystick name
//========================================================================
const char* _glfwPlatformGetJoystickName(int joy)
{
JOYCAPS jc;
const int i = joy - GLFW_JOYSTICK_1;
if (!isJoystickPresent(joy))
return NULL;
_glfw_joyGetDevCaps(i, &jc, sizeof(JOYCAPS));
free(_glfwLibrary.Win32.joyNames[i]);
_glfwLibrary.Win32.joyNames[i] = _glfwCreateUTF8FromWideString(jc.szPname);
return _glfwLibrary.Win32.joyNames[i];
}

View File

@ -183,6 +183,8 @@ typedef struct _GLFWlibraryWin32
} winmm; } winmm;
#endif // _GLFW_NO_DLOAD_WINMM #endif // _GLFW_NO_DLOAD_WINMM
char* joyNames[GLFW_JOYSTICK_LAST + 1];
} _GLFWlibraryWin32; } _GLFWlibraryWin32;

View File

@ -41,6 +41,7 @@
#include <dirent.h> #include <dirent.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#endif // __linux__ #endif // __linux__
@ -52,6 +53,7 @@ static int openJoystickDevice(int joy, const char* path)
{ {
#ifdef __linux__ #ifdef __linux__
char numAxes, numButtons; char numAxes, numButtons;
char name[256];
int fd, version; int fd, version;
fd = open(path, O_RDONLY | O_NONBLOCK); fd = open(path, O_RDONLY | O_NONBLOCK);
@ -69,6 +71,11 @@ static int openJoystickDevice(int joy, const char* path)
return GL_FALSE; return GL_FALSE;
} }
if (ioctl(fd, JSIOCGNAME(sizeof(name)), name) < 0)
strncpy(name, "Unknown", sizeof(name));
_glfwLibrary.X11.joystick[joy].name = strdup(name);
ioctl(fd, JSIOCGAXES, &numAxes); ioctl(fd, JSIOCGAXES, &numAxes);
_glfwLibrary.X11.joystick[joy].numAxes = (int) numAxes; _glfwLibrary.X11.joystick[joy].numAxes = (int) numAxes;
@ -237,6 +244,7 @@ void _glfwTerminateJoysticks(void)
close(_glfwLibrary.X11.joystick[i].fd); close(_glfwLibrary.X11.joystick[i].fd);
free(_glfwLibrary.X11.joystick[i].axis); free(_glfwLibrary.X11.joystick[i].axis);
free(_glfwLibrary.X11.joystick[i].button); free(_glfwLibrary.X11.joystick[i].button);
free(_glfwLibrary.X11.joystick[i].name);
_glfwLibrary.X11.joystick[i].present = GL_FALSE; _glfwLibrary.X11.joystick[i].present = GL_FALSE;
} }
@ -325,3 +333,16 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons,
return numButtons; return numButtons;
} }
//========================================================================
// Get joystick name
//========================================================================
const char* _glfwPlatformGetJoystickName(int joy)
{
if (!_glfwLibrary.X11.joystick[joy].present)
return NULL;
return _glfwLibrary.X11.joystick[joy].name;
}

View File

@ -209,6 +209,7 @@ typedef struct _GLFWlibraryX11
int numButtons; int numButtons;
float* axis; float* axis;
unsigned char* button; unsigned char* button;
char* name;
} joystick[GLFW_JOYSTICK_LAST + 1]; } joystick[GLFW_JOYSTICK_LAST + 1];
} _GLFWlibraryX11; } _GLFWlibraryX11;

View File

@ -37,6 +37,7 @@
typedef struct Joystick typedef struct Joystick
{ {
GLboolean present; GLboolean present;
char* name;
float* axes; float* axes;
unsigned char* buttons; unsigned char* buttons;
int axis_count; int axis_count;
@ -94,11 +95,11 @@ static void draw_joystick(Joystick* j, int x, int y, int width, int height)
} }
} }
static void draw_joysticks(void) static void draw_joysticks(GLFWwindow window)
{ {
int i, width, height; int i, width, height;
glfwGetWindowSize(glfwGetCurrentContext(), &width, &height); glfwGetWindowSize(window, &width, &height);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
@ -130,6 +131,9 @@ static void refresh_joysticks(void)
{ {
int axis_count, button_count; int axis_count, button_count;
free(j->name);
j->name = strdup(glfwGetJoystickName(GLFW_JOYSTICK_1 + i));
axis_count = glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_AXES); axis_count = glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_AXES);
if (axis_count != j->axis_count) if (axis_count != j->axis_count)
{ {
@ -150,8 +154,8 @@ static void refresh_joysticks(void)
if (!j->present) if (!j->present)
{ {
printf("Found joystick %i with %i axes, %i buttons\n", printf("Found joystick %i named \'%s\' with %i axes, %i buttons\n",
i + 1, j->axis_count, j->button_count); i + 1, j->name, j->axis_count, j->button_count);
joystick_count++; joystick_count++;
} }
@ -162,12 +166,13 @@ static void refresh_joysticks(void)
{ {
if (j->present) if (j->present)
{ {
printf("Lost joystick %i named \'%s\'\n", i + 1, j->name);
free(j->name);
free(j->axes); free(j->axes);
free(j->buttons); free(j->buttons);
memset(j, 0, sizeof(Joystick)); memset(j, 0, sizeof(Joystick));
printf("Lost joystick %i\n", i + 1);
joystick_count--; joystick_count--;
} }
} }
@ -205,7 +210,7 @@ int main(void)
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
refresh_joysticks(); refresh_joysticks();
draw_joysticks(); draw_joysticks(window);
glfwSwapBuffers(window); glfwSwapBuffers(window);
glfwPollEvents(); glfwPollEvents();