1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

Merge branch 'master' into multi-monitor

This commit is contained in:
Camilla Berglund 2012-09-23 14:44:56 +02:00
commit 6a5ebbc870
8 changed files with 98 additions and 106 deletions

View File

@ -304,37 +304,6 @@ static int translateKey(WPARAM wParam, LPARAM lParam)
} }
//========================================================================
// Translates a Windows key to Unicode
//========================================================================
static void translateChar(_GLFWwindow* window, DWORD wParam, DWORD lParam)
{
BYTE keyboard_state[256];
WCHAR unicode_buf[10];
UINT scan_code;
int i, num_chars;
GetKeyboardState(keyboard_state);
// Derive scan code from lParam and action
scan_code = (lParam & 0x01ff0000) >> 16;
num_chars = ToUnicode(
wParam, // virtual-key code
scan_code, // scan code
keyboard_state, // key-state array
unicode_buf, // buffer for translated key
10, // size of translated key buffer
0 // active-menu flag
);
// Report characters
for (i = 0; i < num_chars; i++)
_glfwInputChar(window, (int) unicode_buf[i]);
}
//======================================================================== //========================================================================
// Window callback function (handles window events) // Window callback function (handles window events)
//======================================================================== //========================================================================
@ -458,13 +427,15 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_SYSKEYDOWN: case WM_SYSKEYDOWN:
{ {
_glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS); _glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS);
if (_glfwLibrary.charCallback)
translateChar(window, (DWORD) wParam, (DWORD) lParam);
break; break;
} }
case WM_CHAR:
{
_glfwInputChar(window, wParam);
return 0;
}
case WM_KEYUP: case WM_KEYUP:
case WM_SYSKEYUP: case WM_SYSKEYUP:
{ {
@ -1139,6 +1110,7 @@ void _glfwPlatformHideWindow(_GLFWwindow* window)
ShowWindow(window->Win32.handle, SW_HIDE); ShowWindow(window->Win32.handle, SW_HIDE);
} }
//======================================================================== //========================================================================
// Write back window parameters into GLFW window structure // Write back window parameters into GLFW window structure
//======================================================================== //========================================================================
@ -1185,9 +1157,7 @@ void _glfwPlatformPollEvents(void)
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{ {
switch (msg.message) if (msg.message == WM_QUIT)
{
case WM_QUIT:
{ {
// Treat WM_QUIT as a close on all windows // Treat WM_QUIT as a close on all windows
@ -1197,15 +1167,11 @@ void _glfwPlatformPollEvents(void)
_glfwInputWindowCloseRequest(window); _glfwInputWindowCloseRequest(window);
window = window->next; window = window->next;
} }
break;
} }
else
default:
{ {
TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
break;
}
} }
} }

View File

@ -336,8 +336,9 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
// Cache the actual (as opposed to requested) window parameters // Cache the actual (as opposed to requested) window parameters
_glfwPlatformRefreshWindowParams(window); _glfwPlatformRefreshWindowParams(window);
// Cache the actual (as opposed to requested) context parameters
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
// Cache the actual (as opposed to requested) context parameters
if (!_glfwRefreshContextParams()) if (!_glfwRefreshContextParams())
{ {
glfwDestroyWindow(window); glfwDestroyWindow(window);
@ -353,6 +354,11 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
return GL_FALSE; return GL_FALSE;
} }
// Clearing the front buffer to black to avoid garbage pixels left over
// from previous uses of our bit of VRAM
glClear(GL_COLOR_BUFFER_BIT);
_glfwPlatformSwapBuffers(window);
// Restore the previously current context (or NULL) // Restore the previously current context (or NULL)
glfwMakeContextCurrent(previous); glfwMakeContextCurrent(previous);
@ -361,12 +367,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
if (mode == GLFW_FULLSCREEN) if (mode == GLFW_FULLSCREEN)
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED); glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
// Clearing the front buffer to black to avoid garbage pixels left over if (mode == GLFW_FULLSCREEN || wndconfig.visible)
// from previous uses of our bit of VRAM
glClear(GL_COLOR_BUFFER_BIT);
_glfwPlatformSwapBuffers(window);
if (wndconfig.visible || mode == GLFW_FULLSCREEN)
glfwShowWindow(window); glfwShowWindow(window);
return window; return window;

View File

@ -34,6 +34,8 @@
#include "getopt.h" #include "getopt.h"
static GLboolean closed = GL_FALSE;
static void usage(void) static void usage(void)
{ {
printf("Usage: clipboard [-h]\n"); printf("Usage: clipboard [-h]\n");
@ -45,6 +47,12 @@ static GLboolean control_is_down(GLFWwindow window)
glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL); glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL);
} }
static int window_close_callback(GLFWwindow window)
{
closed = GL_TRUE;
return GL_FALSE;
}
static void key_callback(GLFWwindow window, int key, int action) static void key_callback(GLFWwindow window, int key, int action)
{ {
if (action != GLFW_PRESS) if (action != GLFW_PRESS)
@ -53,7 +61,7 @@ static void key_callback(GLFWwindow window, int key, int action)
switch (key) switch (key)
{ {
case GLFW_KEY_ESCAPE: case GLFW_KEY_ESCAPE:
glfwDestroyWindow(window); closed = GL_TRUE;
break; break;
case GLFW_KEY_V: case GLFW_KEY_V:
@ -80,7 +88,7 @@ static void key_callback(GLFWwindow window, int key, int action)
} }
} }
static void size_callback(GLFWwindow window, int width, int height) static void window_size_callback(GLFWwindow window, int width, int height)
{ {
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
} }
@ -130,7 +138,8 @@ int main(int argc, char** argv)
glfwSwapInterval(1); glfwSwapInterval(1);
glfwSetKeyCallback(key_callback); glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(size_callback); glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f); glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f);
@ -138,7 +147,7 @@ int main(int argc, char** argv)
glClearColor(0.5f, 0.5f, 0.5f, 0); glClearColor(0.5f, 0.5f, 0.5f, 0);
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED)) while (!closed)
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

View File

@ -37,6 +37,7 @@
#define STEP_SIZE 0.1f #define STEP_SIZE 0.1f
static GLboolean closed = GL_FALSE;
static GLfloat gamma_value = 1.0f; static GLfloat gamma_value = 1.0f;
static void usage(void) static void usage(void)
@ -51,6 +52,12 @@ static void set_gamma(float value)
glfwSetGamma(gamma_value); glfwSetGamma(gamma_value);
} }
static int window_close_callback(GLFWwindow window)
{
closed = GL_TRUE;
return GL_FALSE;
}
static void key_callback(GLFWwindow window, int key, int action) static void key_callback(GLFWwindow window, int key, int action)
{ {
if (action != GLFW_PRESS) if (action != GLFW_PRESS)
@ -60,7 +67,7 @@ static void key_callback(GLFWwindow window, int key, int action)
{ {
case GLFW_KEY_ESCAPE: case GLFW_KEY_ESCAPE:
{ {
glfwDestroyWindow(window); closed = GL_TRUE;
break; break;
} }
@ -145,6 +152,7 @@ int main(int argc, char** argv)
glfwSwapInterval(1); glfwSwapInterval(1);
glfwSetKeyCallback(key_callback); glfwSetKeyCallback(key_callback);
glfwSetWindowCloseCallback(window_close_callback);
glfwSetWindowSizeCallback(size_callback); glfwSetWindowSizeCallback(size_callback);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
@ -153,7 +161,7 @@ int main(int argc, char** argv)
glClearColor(0.5f, 0.5f, 0.5f, 0); glClearColor(0.5f, 0.5f, 0.5f, 0);
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED)) while (!closed)
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

View File

@ -35,11 +35,19 @@
#include "getopt.h" #include "getopt.h"
static GLboolean closed = GL_FALSE;
static void usage(void) static void usage(void)
{ {
printf("Usage: iconify [-h] [-f]\n"); printf("Usage: iconify [-h] [-f]\n");
} }
static int window_close_callback(GLFWwindow window)
{
closed = GL_TRUE;
return GL_FALSE;
}
static void key_callback(GLFWwindow window, int key, int action) static void key_callback(GLFWwindow window, int key, int action)
{ {
printf("%0.2f Key %s\n", printf("%0.2f Key %s\n",
@ -55,12 +63,12 @@ static void key_callback(GLFWwindow window, int key, int action)
glfwIconifyWindow(window); glfwIconifyWindow(window);
break; break;
case GLFW_KEY_ESCAPE: case GLFW_KEY_ESCAPE:
glfwDestroyWindow(window); closed = GL_TRUE;
break; break;
} }
} }
static void size_callback(GLFWwindow window, int width, int height) static void window_size_callback(GLFWwindow window, int width, int height)
{ {
printf("%0.2f Size %ix%i\n", glfwGetTime(), width, height); printf("%0.2f Size %ix%i\n", glfwGetTime(), width, height);
@ -124,11 +132,12 @@ int main(int argc, char** argv)
glfwSwapInterval(1); glfwSwapInterval(1);
glfwSetKeyCallback(key_callback); glfwSetKeyCallback(key_callback);
glfwSetWindowSizeCallback(size_callback); glfwSetWindowSizeCallback(window_size_callback);
glfwSetWindowCloseCallback(window_close_callback);
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED)) while (!closed)
{ {
if (iconified != glfwGetWindowParam(window, GLFW_ICONIFIED) || if (iconified != glfwGetWindowParam(window, GLFW_ICONIFIED) ||
active != glfwGetWindowParam(window, GLFW_ACTIVE)) active != glfwGetWindowParam(window, GLFW_ACTIVE))

View File

@ -35,7 +35,7 @@
#include "getopt.h" #include "getopt.h"
static GLFWwindow window = NULL; static GLFWwindow window_handle = NULL;
enum Mode enum Mode
{ {
@ -68,25 +68,25 @@ static void error_callback(int error, const char* description)
fprintf(stderr, "Error: %s\n", description); fprintf(stderr, "Error: %s\n", description);
} }
static void window_size_callback(GLFWwindow in_window, int width, int height) static void window_size_callback(GLFWwindow window, int width, int height)
{ {
printf("Window resized to %ix%i\n", width, height); printf("Window resized to %ix%i\n", width, height);
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
} }
static int window_close_callback(GLFWwindow dummy) static int window_close_callback(GLFWwindow window)
{ {
window = NULL; window_handle = NULL;
return GL_TRUE; return GL_TRUE;
} }
static void key_callback(GLFWwindow dummy, int key, int action) static void key_callback(GLFWwindow window, int key, int action)
{ {
if (key == GLFW_KEY_ESCAPE) if (key == GLFW_KEY_ESCAPE)
{ {
glfwDestroyWindow(window); glfwDestroyWindow(window);
window = NULL; window_handle = NULL;
} }
} }
@ -143,10 +143,10 @@ static void test_modes(GLFWmonitor monitor)
glfwGetMonitorString(monitor, GLFW_MONITOR_NAME), glfwGetMonitorString(monitor, GLFW_MONITOR_NAME),
format_mode(mode)); format_mode(mode));
window = glfwCreateWindow(mode->width, mode->height, window_handle = glfwCreateWindow(mode->width, mode->height,
GLFW_FULLSCREEN, "Video Mode Test", GLFW_FULLSCREEN, "Video Mode Test",
NULL); NULL);
if (!window) if (!window_handle)
{ {
printf("Failed to enter mode %u: %s\n", printf("Failed to enter mode %u: %s\n",
(unsigned int) i, (unsigned int) i,
@ -154,7 +154,7 @@ static void test_modes(GLFWmonitor monitor)
continue; continue;
} }
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window_handle);
glfwSwapInterval(1); glfwSwapInterval(1);
glfwSetTime(0.0); glfwSetTime(0.0);
@ -162,10 +162,10 @@ static void test_modes(GLFWmonitor monitor)
while (glfwGetTime() < 5.0) while (glfwGetTime() < 5.0)
{ {
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window); glfwSwapBuffers(window_handle);
glfwPollEvents(); glfwPollEvents();
if (!window) if (!window_handle)
{ {
printf("User terminated program\n"); printf("User terminated program\n");
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
@ -176,7 +176,7 @@ static void test_modes(GLFWmonitor monitor)
glGetIntegerv(GL_GREEN_BITS, &current.greenBits); glGetIntegerv(GL_GREEN_BITS, &current.greenBits);
glGetIntegerv(GL_BLUE_BITS, &current.blueBits); glGetIntegerv(GL_BLUE_BITS, &current.blueBits);
glfwGetWindowSize(window, &current.width, &current.height); glfwGetWindowSize(window_handle, &current.width, &current.height);
if (current.redBits != mode->redBits || if (current.redBits != mode->redBits ||
current.greenBits != mode->greenBits || current.greenBits != mode->greenBits ||
@ -196,9 +196,9 @@ static void test_modes(GLFWmonitor monitor)
printf("Closing window\n"); printf("Closing window\n");
glfwDestroyWindow(window); glfwDestroyWindow(window_handle);
window_handle = NULL;
glfwPollEvents(); glfwPollEvents();
window = NULL;
} }
} }

View File

@ -35,6 +35,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
static GLboolean reopen = GL_FALSE;
static GLFWwindow window_handle = NULL; static GLFWwindow window_handle = NULL;
static int cursor_x; static int cursor_x;
static int cursor_y; static int cursor_y;
@ -77,10 +78,7 @@ static void key_callback(GLFWwindow window, int key, int action)
case GLFW_KEY_R: case GLFW_KEY_R:
{ {
if (action == GLFW_PRESS) if (action == GLFW_PRESS)
{ reopen = GL_TRUE;
glfwDestroyWindow(window);
open_window();
}
break; break;
} }
@ -121,8 +119,6 @@ int main(void)
if (!open_window()) if (!open_window())
{ {
glfwTerminate();
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError())); fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -135,6 +131,18 @@ int main(void)
glfwSwapBuffers(window_handle); glfwSwapBuffers(window_handle);
glfwWaitEvents(); glfwWaitEvents();
if (reopen)
{
glfwDestroyWindow(window_handle);
if (!open_window())
{
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
exit(EXIT_FAILURE);
}
reopen = GL_FALSE;
}
} }
glfwTerminate(); glfwTerminate();

View File

@ -37,27 +37,18 @@
#define HEIGHT 400 #define HEIGHT 400
static GLFWwindow windows[2]; static GLFWwindow windows[2];
static GLboolean closed = GL_FALSE;
static void key_callback(GLFWwindow window, int key, int action) static void key_callback(GLFWwindow window, int key, int action)
{ {
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE) if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
glfwDestroyWindow(window); closed = GL_TRUE;
} }
static int window_close_callback(GLFWwindow window) static int window_close_callback(GLFWwindow window)
{ {
int i; closed = GL_TRUE;
return GL_FALSE;
for (i = 0; i < 2; i++)
{
if (windows[i] == window)
{
windows[i] = NULL;
break;
}
}
return GL_TRUE;
} }
static GLFWwindow open_window(const char* title, GLFWwindow share) static GLFWwindow open_window(const char* title, GLFWwindow share)
@ -170,7 +161,7 @@ int main(int argc, char** argv)
glfwGetWindowPos(windows[0], &x, &y); glfwGetWindowPos(windows[0], &x, &y);
glfwSetWindowPos(windows[1], x + WIDTH + 50, y); glfwSetWindowPos(windows[1], x + WIDTH + 50, y);
while (windows[0] && windows[1]) while (!closed)
{ {
glfwMakeContextCurrent(windows[0]); glfwMakeContextCurrent(windows[0]);
draw_quad(texture); draw_quad(texture);