mirror of
https://github.com/glfw/glfw.git
synced 2026-09-21 16:44:11 +00:00
Merge branch 'master' into multi-monitor
Conflicts: CMakeLists.txt readme.html src/CMakeLists.txt src/cocoa_platform.h src/win32_platform.h src/x11_platform.h tests/events.c
This commit is contained in:
@@ -218,6 +218,15 @@ static const char* get_character_string(int character)
|
||||
return result;
|
||||
}
|
||||
|
||||
static void window_pos_callback(GLFWwindow window, int x, int y)
|
||||
{
|
||||
printf("%08x at %0.3f: Window position: %i %i\n",
|
||||
counter++,
|
||||
glfwGetTime(),
|
||||
x,
|
||||
y);
|
||||
}
|
||||
|
||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
||||
{
|
||||
printf("%08x at %0.3f: Window size: %i %i\n",
|
||||
@@ -382,6 +391,7 @@ int main(void)
|
||||
|
||||
glfwSetMonitorCallback(monitor_callback);
|
||||
|
||||
glfwSetWindowPosCallback(window, window_pos_callback);
|
||||
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||
glfwSetWindowCloseCallback(window, window_close_callback);
|
||||
glfwSetWindowRefreshCallback(window, window_refresh_callback);
|
||||
|
||||
+12
-7
@@ -37,6 +37,7 @@
|
||||
typedef struct Joystick
|
||||
{
|
||||
GLboolean present;
|
||||
char* name;
|
||||
float* axes;
|
||||
unsigned char* buttons;
|
||||
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;
|
||||
|
||||
glfwGetWindowSize(glfwGetCurrentContext(), &width, &height);
|
||||
glfwGetWindowSize(window, &width, &height);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
@@ -130,6 +131,9 @@ static void refresh_joysticks(void)
|
||||
{
|
||||
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);
|
||||
if (axis_count != j->axis_count)
|
||||
{
|
||||
@@ -150,8 +154,8 @@ static void refresh_joysticks(void)
|
||||
|
||||
if (!j->present)
|
||||
{
|
||||
printf("Found joystick %i with %i axes, %i buttons\n",
|
||||
i + 1, j->axis_count, j->button_count);
|
||||
printf("Found joystick %i named \'%s\' with %i axes, %i buttons\n",
|
||||
i + 1, j->name, j->axis_count, j->button_count);
|
||||
|
||||
joystick_count++;
|
||||
}
|
||||
@@ -162,12 +166,13 @@ static void refresh_joysticks(void)
|
||||
{
|
||||
if (j->present)
|
||||
{
|
||||
printf("Lost joystick %i named \'%s\'\n", i + 1, j->name);
|
||||
|
||||
free(j->name);
|
||||
free(j->axes);
|
||||
free(j->buttons);
|
||||
memset(j, 0, sizeof(Joystick));
|
||||
|
||||
printf("Lost joystick %i\n", i + 1);
|
||||
|
||||
joystick_count--;
|
||||
}
|
||||
}
|
||||
@@ -205,7 +210,7 @@ int main(void)
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
refresh_joysticks();
|
||||
draw_joysticks();
|
||||
draw_joysticks(window);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
|
||||
Reference in New Issue
Block a user