windows.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //========================================================================
  2. // Simple multi-window example
  3. // Copyright (c) Camilla Löwy <[email protected]>
  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. #define GLAD_GL_IMPLEMENTATION
  26. #include <glad/gl.h>
  27. #define GLFW_INCLUDE_NONE
  28. #include <GLFW/glfw3.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. int main(int argc, char** argv)
  32. {
  33. int xpos, ypos, height;
  34. const char* description;
  35. GLFWwindow* windows[4];
  36. if (!glfwInit())
  37. {
  38. glfwGetError(&description);
  39. printf("Error: %s\n", description);
  40. exit(EXIT_FAILURE);
  41. }
  42. glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
  43. glfwGetMonitorWorkarea(glfwGetPrimaryMonitor(), &xpos, &ypos, NULL, &height);
  44. for (int i = 0; i < 4; i++)
  45. {
  46. const int size = height / 5;
  47. const struct
  48. {
  49. float r, g, b;
  50. } colors[] =
  51. {
  52. { 0.95f, 0.32f, 0.11f },
  53. { 0.50f, 0.80f, 0.16f },
  54. { 0.f, 0.68f, 0.94f },
  55. { 0.98f, 0.74f, 0.04f }
  56. };
  57. if (i > 0)
  58. glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE);
  59. glfwWindowHint(GLFW_POSITION_X, xpos + size * (1 + (i & 1)));
  60. glfwWindowHint(GLFW_POSITION_Y, ypos + size * (1 + (i >> 1)));
  61. windows[i] = glfwCreateWindow(size, size, "Multi-Window Example", NULL, NULL);
  62. if (!windows[i])
  63. {
  64. glfwGetError(&description);
  65. printf("Error: %s\n", description);
  66. glfwTerminate();
  67. exit(EXIT_FAILURE);
  68. }
  69. glfwSetInputMode(windows[i], GLFW_STICKY_KEYS, GLFW_TRUE);
  70. glfwMakeContextCurrent(windows[i]);
  71. gladLoadGL(glfwGetProcAddress);
  72. glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f);
  73. }
  74. for (;;)
  75. {
  76. for (int i = 0; i < 4; i++)
  77. {
  78. glfwMakeContextCurrent(windows[i]);
  79. glClear(GL_COLOR_BUFFER_BIT);
  80. glfwSwapBuffers(windows[i]);
  81. if (glfwWindowShouldClose(windows[i]) ||
  82. glfwGetKey(windows[i], GLFW_KEY_ESCAPE))
  83. {
  84. glfwTerminate();
  85. exit(EXIT_SUCCESS);
  86. }
  87. }
  88. glfwWaitEvents();
  89. }
  90. }