Merge branch 'master' of github.com:elmindreda/glfw

This commit is contained in:
Camilla Berglund 2012-09-13 21:58:16 +02:00
commit 1027935cdf
6 changed files with 71 additions and 46 deletions

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;
} }
} }
@ -132,10 +132,10 @@ static void test_modes(void)
printf("Testing mode %u: %s", (unsigned int) i, format_mode(mode)); printf("Testing mode %u: %s", (unsigned int) i, 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,
@ -143,7 +143,7 @@ static void test_modes(void)
continue; continue;
} }
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window_handle);
glfwSwapInterval(1); glfwSwapInterval(1);
glfwSetTime(0.0); glfwSetTime(0.0);
@ -151,10 +151,10 @@ static void test_modes(void)
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);
@ -165,7 +165,7 @@ static void test_modes(void)
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 ||
@ -185,9 +185,9 @@ static void test_modes(void)
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);