Improved multi-window test.

Fixed proper Windows colors.  Added support for Escape key.  Made
windows undecorated.  Added command-line option for decorated windows.
This commit is contained in:
Camilla Berglund 2015-01-25 23:38:28 +01:00
parent 5abf7841f8
commit 8d4ba0aa83

View File

@ -32,12 +32,23 @@
#include <stdio.h>
#include <stdlib.h>
static const char* titles[4] =
static const char* titles[] =
{
"Foo",
"Bar",
"Baz",
"Quux"
"Red",
"Green",
"Blue",
"Yellow"
};
static const struct
{
float r, g, b;
} colors[] =
{
{ 0.95f, 0.32f, 0.11f },
{ 0.50f, 0.80f, 0.16f },
{ 0.f, 0.68f, 0.94f },
{ 0.98f, 0.74f, 0.04f }
};
static void error_callback(int error, const char* description)
@ -47,15 +58,26 @@ static void error_callback(int error, const char* description)
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
if (action != GLFW_PRESS)
return;
switch (key)
{
int xpos, ypos;
glfwGetWindowPos(window, &xpos, &ypos);
glfwSetWindowPos(window, xpos, ypos);
case GLFW_KEY_SPACE:
{
int xpos, ypos;
glfwGetWindowPos(window, &xpos, &ypos);
glfwSetWindowPos(window, xpos, ypos);
break;
}
case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(window, GL_TRUE);
break;
}
}
int main(void)
int main(int argc, char** argv)
{
int i;
GLboolean running = GL_TRUE;
@ -66,6 +88,7 @@ int main(void)
if (!glfwInit())
exit(EXIT_FAILURE);
glfwWindowHint(GLFW_DECORATED, GL_FALSE);
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
for (i = 0; i < 4; i++)
@ -82,10 +105,7 @@ int main(void)
glfwSetKeyCallback(windows[i], key_callback);
glfwMakeContextCurrent(windows[i]);
glClearColor((GLclampf) (i & 1),
(GLclampf) (i >> 1),
i ? 0.f : 1.f,
0.f);
glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f);
glfwGetWindowFrameSize(windows[i], &left, &top, &right, &bottom);
glfwSetWindowPos(windows[i],