|
|
@ -1,5 +1,5 @@ |
|
|
|
//========================================================================
|
|
|
|
//========================================================================
|
|
|
|
// Simple multi-window test
|
|
|
|
// Simple multi-window example
|
|
|
|
// Copyright (c) Camilla Löwy <elmindreda@glfw.org>
|
|
|
|
// Copyright (c) Camilla Löwy <elmindreda@glfw.org>
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
@ -22,10 +22,6 @@ |
|
|
|
// distribution.
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
//========================================================================
|
|
|
|
//
|
|
|
|
|
|
|
|
// This test creates four windows and clears each in a different color
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <glad/gl.h> |
|
|
|
#include <glad/gl.h> |
|
|
|
#define GLFW_INCLUDE_NONE |
|
|
|
#define GLFW_INCLUDE_NONE |
|
|
@ -34,109 +30,60 @@ |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.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) |
|
|
|
int main(int argc, char** argv) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glfwSetErrorCallback(error_callback); |
|
|
|
int xpos, ypos, height; |
|
|
|
|
|
|
|
const char* description; |
|
|
|
|
|
|
|
GLFWwindow* windows[4]; |
|
|
|
|
|
|
|
|
|
|
|
if (!glfwInit()) |
|
|
|
if (!glfwInit()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
glfwGetError(&description); |
|
|
|
|
|
|
|
printf("Error: %s\n", description); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); |
|
|
|
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); |
|
|
|
|
|
|
|
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glfwGetMonitorWorkarea(glfwGetPrimaryMonitor(), &xpos, &ypos, NULL, &height); |
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) |
|
|
|
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) |
|
|
|
if (i > 0) |
|
|
|
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE); |
|
|
|
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]) |
|
|
|
if (!windows[i]) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
glfwGetError(&description); |
|
|
|
|
|
|
|
printf("Error: %s\n", description); |
|
|
|
glfwTerminate(); |
|
|
|
glfwTerminate(); |
|
|
|
exit(EXIT_FAILURE); |
|
|
|
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]); |
|
|
|
glfwMakeContextCurrent(windows[i]); |
|
|
|
gladLoadGL(glfwGetProcAddress); |
|
|
|
gladLoadGL(glfwGetProcAddress); |
|
|
|
glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f); |
|
|
|
glClearColor(colors[i].r, colors[i].g, colors[i].b, 1.f); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
arrange_windows(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) |
|
|
|
for (int i = 0; i < 4; i++) |
|
|
|
glfwShowWindow(windows[i]); |
|
|
|
glfwShowWindow(windows[i]); |
|
|
|
|
|
|
|
|
|
|
@ -148,7 +95,8 @@ int main(int argc, char** argv) |
|
|
|
glClear(GL_COLOR_BUFFER_BIT); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT); |
|
|
|
glfwSwapBuffers(windows[i]); |
|
|
|
glfwSwapBuffers(windows[i]); |
|
|
|
|
|
|
|
|
|
|
|
if (glfwWindowShouldClose(windows[i])) |
|
|
|
if (glfwWindowShouldClose(windows[i]) || |
|
|
|
|
|
|
|
glfwGetKey(windows[i], GLFW_KEY_ESCAPE)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glfwTerminate(); |
|
|
|
glfwTerminate(); |
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
exit(EXIT_SUCCESS); |