|
@@ -1,5 +1,5 @@
|
|
|
//========================================================================
|
|
|
-// Simple multi-window test
|
|
|
+// Simple multi-window example
|
|
|
// Copyright (c) Camilla Löwy <[email protected]>
|
|
|
//
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
@@ -22,10 +22,6 @@
|
|
|
// distribution.
|
|
|
//
|
|
|
//========================================================================
|
|
|
-//
|
|
|
-// This test creates four windows and clears each in a different color
|
|
|
-//
|
|
|
-//========================================================================
|
|
|
|
|
|
#include <glad/gl.h>
|
|
|
#define GLFW_INCLUDE_NONE
|
|
@@ -34,109 +30,60 @@
|
|
|
#include <stdio.h>
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
-static GLFWwindow* windows[4];
|
|
|
-static const char* titles[] =
|
|
|
-{
|
|
|
- "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)
|
|
|
-{
|
|
|
- fprintf(stderr, "Error: %s\n", description);
|
|
|
-}
|
|
|
-
|
|
|
-static void arrange_windows(void)
|
|
|
-{
|
|
|
- int xbase, ybase;
|
|
|
- glfwGetWindowPos(windows[0], &xbase, &ybase);
|
|
|
-
|
|
|
- for (int i = 0; i < 4; i++)
|
|
|
- {
|
|
|
- int left, top, right, bottom;
|
|
|
- glfwGetWindowFrameSize(windows[i], &left, &top, &right, &bottom);
|
|
|
- glfwSetWindowPos(windows[i],
|
|
|
- xbase + (i & 1) * (200 + left + right),
|
|
|
- ybase + (i >> 1) * (200 + top + bottom));
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
|
|
-{
|
|
|
- if (action != GLFW_PRESS)
|
|
|
- return;
|
|
|
-
|
|
|
- switch (key)
|
|
|
- {
|
|
|
- case GLFW_KEY_SPACE:
|
|
|
- {
|
|
|
- int xpos, ypos;
|
|
|
- glfwGetWindowPos(window, &xpos, &ypos);
|
|
|
- glfwSetWindowPos(window, xpos, ypos);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- case GLFW_KEY_ESCAPE:
|
|
|
- glfwSetWindowShouldClose(window, GLFW_TRUE);
|
|
|
- break;
|
|
|
-
|
|
|
- case GLFW_KEY_D:
|
|
|
- {
|
|
|
- for (int i = 0; i < 4; i++)
|
|
|
- {
|
|
|
- const int decorated = glfwGetWindowAttrib(windows[i], GLFW_DECORATED);
|
|
|
- glfwSetWindowAttrib(windows[i], GLFW_DECORATED, !decorated);
|
|
|
- }
|
|
|
-
|
|
|
- arrange_windows();
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
int main(int argc, char** argv)
|
|
|
{
|
|
|
- glfwSetErrorCallback(error_callback);
|
|
|
+ int xpos, ypos, height;
|
|
|
+ const char* description;
|
|
|
+ GLFWwindow* windows[4];
|
|
|
|
|
|
if (!glfwInit())
|
|
|
+ {
|
|
|
+ glfwGetError(&description);
|
|
|
+ printf("Error: %s\n", description);
|
|
|
exit(EXIT_FAILURE);
|
|
|
+ }
|
|
|
|
|
|
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
|
|
+ glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
|
|
+
|
|
|
+ glfwGetMonitorWorkarea(glfwGetPrimaryMonitor(), &xpos, &ypos, NULL, &height);
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
{
|
|
|
+ const int size = height / 5;
|
|
|
+ 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 }
|
|
|
+ };
|
|
|
+
|
|
|
if (i > 0)
|
|
|
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE);
|
|
|
|
|
|
- windows[i] = glfwCreateWindow(200, 200, titles[i], NULL, NULL);
|
|
|
+ windows[i] = glfwCreateWindow(size, size, "Multi-Window Example", NULL, NULL);
|
|
|
if (!windows[i])
|
|
|
{
|
|
|
+ glfwGetError(&description);
|
|
|
+ printf("Error: %s\n", description);
|
|
|
glfwTerminate();
|
|
|
exit(EXIT_FAILURE);
|
|
|
}
|
|
|
|
|
|
- glfwSetKeyCallback(windows[i], key_callback);
|
|
|
+ glfwSetWindowPos(windows[i],
|
|
|
+ xpos + size * (1 + (i & 1)),
|
|
|
+ ypos + size * (1 + (i >> 1)));
|
|
|
+ glfwSetInputMode(windows[i], GLFW_STICKY_KEYS, GLFW_TRUE);
|
|
|
|
|
|
glfwMakeContextCurrent(windows[i]);
|
|
|
gladLoadGL(glfwGetProcAddress);
|
|
|
glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f);
|
|
|
}
|
|
|
|
|
|
- arrange_windows();
|
|
|
-
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
glfwShowWindow(windows[i]);
|
|
|
|
|
@@ -148,7 +95,8 @@ int main(int argc, char** argv)
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
glfwSwapBuffers(windows[i]);
|
|
|
|
|
|
- if (glfwWindowShouldClose(windows[i]))
|
|
|
+ if (glfwWindowShouldClose(windows[i]) ||
|
|
|
+ glfwGetKey(windows[i], GLFW_KEY_ESCAPE))
|
|
|
{
|
|
|
glfwTerminate();
|
|
|
exit(EXIT_SUCCESS);
|