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