1 //========================================================================
2 // Simple multi-window example
3 // Copyright (c) Camilla Löwy <elmindreda@glfw.org>
4 //
5 // This software is provided 'as-is', without any express or implied
6 // warranty. In no event will the authors be held liable for any damages
7 // arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it
11 // freely, subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented; you must not
14 // claim that you wrote the original software. If you use this software
15 // in a product, an acknowledgment in the product documentation would
16 // be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such, and must not
19 // be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source
22 // distribution.
23 //
24 //========================================================================
25
26 #define GLAD_GL_IMPLEMENTATION
27 #include <glad/gl.h>
28 #define GLFW_INCLUDE_NONE
29 #include <GLFW/glfw3.h>
30
31 #include <stdio.h>
32 #include <stdlib.h>
33
main(int argc,char ** argv)34 int main(int argc, char** argv)
35 {
36 int xpos, ypos, height;
37 const char* description;
38 GLFWwindow* windows[4];
39
40 if (!glfwInit())
41 {
42 glfwGetError(&description);
43 printf("Error: %s\n", description);
44 exit(EXIT_FAILURE);
45 }
46
47 glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
48
49 glfwGetMonitorWorkarea(glfwGetPrimaryMonitor(), &xpos, &ypos, NULL, &height);
50
51 for (int i = 0; i < 4; i++)
52 {
53 const int size = height / 5;
54 const struct
55 {
56 float r, g, b;
57 } colors[] =
58 {
59 { 0.95f, 0.32f, 0.11f },
60 { 0.50f, 0.80f, 0.16f },
61 { 0.f, 0.68f, 0.94f },
62 { 0.98f, 0.74f, 0.04f }
63 };
64
65 if (i > 0)
66 glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE);
67
68 glfwWindowHint(GLFW_POSITION_X, xpos + size * (1 + (i & 1)));
69 glfwWindowHint(GLFW_POSITION_Y, ypos + size * (1 + (i >> 1)));
70
71 windows[i] = glfwCreateWindow(size, size, "Multi-Window Example", NULL, NULL);
72 if (!windows[i])
73 {
74 glfwGetError(&description);
75 printf("Error: %s\n", description);
76 glfwTerminate();
77 exit(EXIT_FAILURE);
78 }
79
80 glfwSetInputMode(windows[i], GLFW_STICKY_KEYS, GLFW_TRUE);
81
82 glfwMakeContextCurrent(windows[i]);
83 gladLoadGL(glfwGetProcAddress);
84 glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f);
85 }
86
87 for (;;)
88 {
89 for (int i = 0; i < 4; i++)
90 {
91 glfwMakeContextCurrent(windows[i]);
92 glClear(GL_COLOR_BUFFER_BIT);
93 glfwSwapBuffers(windows[i]);
94
95 if (glfwWindowShouldClose(windows[i]) ||
96 glfwGetKey(windows[i], GLFW_KEY_ESCAPE))
97 {
98 glfwTerminate();
99 exit(EXIT_SUCCESS);
100 }
101 }
102
103 glfwWaitEvents();
104 }
105 }
106
107