mirror of
https://github.com/glfw/glfw.git
synced 2025-10-05 06:06:36 +00:00
Merge 1557990fa1
into 5b8051581e
This commit is contained in:
commit
3e17bbc890
1
.gitignore
vendored
1
.gitignore
vendored
@ -81,4 +81,3 @@ tests/title
|
||||
tests/version
|
||||
tests/vulkan
|
||||
tests/windows
|
||||
|
||||
|
@ -39,11 +39,14 @@ add_executable(offscreen offscreen.c ${ICON} ${GLAD})
|
||||
add_executable(particles WIN32 MACOSX_BUNDLE particles.c ${ICON} ${TINYCTHREAD} ${GETOPT} ${GLAD})
|
||||
add_executable(simple WIN32 MACOSX_BUNDLE simple.c ${ICON} ${GLAD})
|
||||
add_executable(splitview WIN32 MACOSX_BUNDLE splitview.c ${ICON} ${GLAD})
|
||||
add_executable(transparent WIN32 MACOSX_BUNDLE transparent.c ${ICON} ${GLAD})
|
||||
add_executable(wave WIN32 MACOSX_BUNDLE wave.c ${ICON} ${GLAD})
|
||||
add_executable(filters WIN32 MACOSX_BUNDLE filters.c ${ICON} ${TINYCTHREAD} ${GETOPT} ${GLAD})
|
||||
|
||||
target_link_libraries(particles "${CMAKE_THREAD_LIBS_INIT}" "${RT_LIBRARY}")
|
||||
target_link_libraries(filters "${CMAKE_THREAD_LIBS_INIT}" "${RT_LIBRARY}")
|
||||
|
||||
set(WINDOWS_BINARIES boing gears heightmap particles simple splitview wave)
|
||||
set(WINDOWS_BINARIES boing gears heightmap particles simple transparent splitview wave filters)
|
||||
|
||||
set_target_properties(${WINDOWS_BINARIES} PROPERTIES FOLDER "GLFW3/Examples")
|
||||
|
||||
@ -58,8 +61,10 @@ if (APPLE)
|
||||
set_target_properties(gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears")
|
||||
set_target_properties(heightmap PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Heightmap")
|
||||
set_target_properties(particles PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Particles")
|
||||
set_target_properties(filters PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Filters")
|
||||
set_target_properties(simple PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Simple")
|
||||
set_target_properties(splitview PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "SplitView")
|
||||
set_target_properties(transparent PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Transparent")
|
||||
set_target_properties(wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave")
|
||||
|
||||
set_target_properties(${WINDOWS_BINARIES} PROPERTIES
|
||||
|
279
examples/filters.c
Normal file
279
examples/filters.c
Normal file
@ -0,0 +1,279 @@
|
||||
/**
|
||||
* This code was originally derived from the threads test code that came with
|
||||
* the license below. However, its purpose has changed; while it does show
|
||||
* how to use threads, its real purpose is to show how to draw images on a
|
||||
* window based on the location of a different window.
|
||||
*/
|
||||
|
||||
//========================================================================
|
||||
// Multi-threading test
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This test is intended to verify whether the OpenGL context part of
|
||||
// the GLFW API is able to be used from multiple threads
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "tinycthread.h"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "linmath.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
static const struct
|
||||
{
|
||||
float x, y;
|
||||
float r, g, b;
|
||||
} vertices[3] =
|
||||
{
|
||||
{ -0.6f, -0.4f, 1.f, 0.f, 0.f },
|
||||
{ 0.6f, -0.4f, 0.f, 1.f, 0.f },
|
||||
{ 0.f, 0.72f, 0.f, 0.f, 1.f }
|
||||
};
|
||||
|
||||
static const char* vertex_shader_text =
|
||||
"uniform mat4 MVP;\n"
|
||||
"attribute vec3 vCol;\n"
|
||||
"attribute vec2 vPos;\n"
|
||||
"varying vec3 color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = MVP * vec4(vPos, 0.0, 1.0);\n"
|
||||
" color = vCol;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* fragment_shader_text =
|
||||
"varying vec3 color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = vec4(color, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GLFWwindow* primary_window;
|
||||
GLFWwindow* window;
|
||||
const char* title;
|
||||
float r, g, b, a;
|
||||
thrd_t id;
|
||||
} Thread;
|
||||
|
||||
static volatile int running = GLFW_TRUE;
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static int thread_main(void* data)
|
||||
{
|
||||
const Thread* thread = data;
|
||||
|
||||
glfwMakeContextCurrent(thread->window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
while (running)
|
||||
{
|
||||
const float v = (float) fabs(sin(glfwGetTime() * 2.f));
|
||||
glClearColor(thread->r * v, thread->g * v, thread->b * v, thread->a * v);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glfwSwapBuffers(thread->window);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int other_thread_main(void* data)
|
||||
{
|
||||
const Thread* thread = data;
|
||||
|
||||
GLuint vertex_buffer, vertex_shader, fragment_shader, program;
|
||||
GLint mvp_location, vpos_location, vcol_location;
|
||||
|
||||
glfwMakeContextCurrent(thread->window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
// NOTE: OpenGL error checks have been omitted for brevity
|
||||
|
||||
glGenBuffers(1, &vertex_buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
|
||||
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
mvp_location = glGetUniformLocation(program, "MVP");
|
||||
vpos_location = glGetAttribLocation(program, "vPos");
|
||||
vcol_location = glGetAttribLocation(program, "vCol");
|
||||
|
||||
glEnableVertexAttribArray(vpos_location);
|
||||
glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE,
|
||||
sizeof(float) * 5, (void*) 0);
|
||||
glEnableVertexAttribArray(vcol_location);
|
||||
glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE,
|
||||
sizeof(float) * 5, (void*) (sizeof(float) * 2));
|
||||
|
||||
while (running)
|
||||
{
|
||||
int primary_x_pos, primary_y_pos;
|
||||
int primary_width, primary_height;
|
||||
int my_x_pos, my_y_pos;
|
||||
int my_width, my_height;
|
||||
float delta_x, delta_y;
|
||||
float ratio, x_ratio, y_ratio;
|
||||
float x_offset, y_offset;
|
||||
mat4x4 m, p, mvp;
|
||||
|
||||
glfwGetWindowPos(thread->primary_window, &primary_x_pos, &primary_y_pos);
|
||||
glfwGetFramebufferSize(thread->primary_window, &primary_width, &primary_height);
|
||||
glfwGetWindowPos(thread->window, &my_x_pos, &my_y_pos);
|
||||
glfwGetFramebufferSize(thread->window, &my_width, &my_height);
|
||||
|
||||
const float v = (float) fabs(sin(glfwGetTime() * 2.f));
|
||||
ratio = my_width / (float) my_height;
|
||||
x_ratio = (my_width / (float) primary_width);
|
||||
y_ratio = (my_height / (float) primary_height);
|
||||
|
||||
delta_x = (((float)(primary_x_pos - my_x_pos)) / ((float) my_width)) * x_ratio * 2 - x_ratio + 1;
|
||||
delta_y = (-((float)(primary_y_pos - my_y_pos)) / ((float) my_height)) * y_ratio * 2 + y_ratio - 1;
|
||||
|
||||
glViewport(0, 0, my_width, my_height);
|
||||
|
||||
glClearColor(thread->r * v, thread->g * v, thread->b * v, thread->a * v);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
mat4x4_identity(m);
|
||||
mat4x4_rotate_Z(m, m, (float) glfwGetTime());
|
||||
mat4x4_ortho(p, -x_ratio, x_ratio, -y_ratio, y_ratio, 1.f, -1.f);
|
||||
mat4x4_translate_in_place(p, delta_x, delta_y, 0.0f);
|
||||
mat4x4_mul(mvp, p, m);
|
||||
|
||||
glUseProgram(program);
|
||||
glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*) mvp);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
glfwSwapBuffers(thread->window);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, result;
|
||||
Thread threads[] =
|
||||
{
|
||||
{ NULL, NULL, "Red", 1.0f, 0.0f, 0.0f, 0.5f, 0 },
|
||||
{ NULL, NULL, "Green", 0.0f, 1.0f, 0.0f, 0.5f, 0 },
|
||||
{ NULL, NULL, "Blue", 0.0f, 0.0f, 1.0f, 0.5f, 0 }
|
||||
};
|
||||
const int count = sizeof(threads) / sizeof(Thread);
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
||||
|
||||
glfwWindowHint(GLFW_ALPHA_BITS, 8);
|
||||
glfwWindowHint(GLFW_TRANSPARENT, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_DECORATED, GLFW_TRUE);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
threads[i].window = glfwCreateWindow(200, 200,
|
||||
threads[i].title,
|
||||
NULL, NULL);
|
||||
if (!threads[i].window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200);
|
||||
glfwShowWindow(threads[i].window);
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
threads[i].primary_window = threads[0].window;
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(threads[0].window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
glfwMakeContextCurrent(NULL);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
result = thrd_create(&threads[i].id, other_thread_main, threads + i);
|
||||
|
||||
if (result != thrd_success)
|
||||
{
|
||||
fprintf(stderr, "Failed to create secondary thread\n");
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
while (running)
|
||||
{
|
||||
glfwWaitEvents();
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (glfwWindowShouldClose(threads[i].window))
|
||||
running = GLFW_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
glfwHideWindow(threads[i].window);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
thrd_join(threads[i].id, &result);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
170
examples/transparent.c
Normal file
170
examples/transparent.c
Normal file
@ -0,0 +1,170 @@
|
||||
//========================================================================
|
||||
// Simple GLFW example
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//! [code]
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "linmath.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static const struct
|
||||
{
|
||||
float x, y;
|
||||
float r, g, b;
|
||||
} vertices[3] =
|
||||
{
|
||||
{ -0.6f, -0.4f, 1.f, 0.f, 0.f },
|
||||
{ 0.6f, -0.4f, 0.f, 1.f, 0.f },
|
||||
{ 0.f, 0.6f, 0.f, 0.f, 1.f }
|
||||
};
|
||||
|
||||
static const char* vertex_shader_text =
|
||||
"uniform mat4 MVP;\n"
|
||||
"attribute vec3 vCol;\n"
|
||||
"attribute vec2 vPos;\n"
|
||||
"varying vec3 color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = MVP * vec4(vPos, 0.0, 1.0);\n"
|
||||
" color = vCol;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* fragment_shader_text =
|
||||
"varying vec3 color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_FragColor = vec4(color, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
GLFWwindow* window;
|
||||
GLuint vertex_buffer, vertex_shader, fragment_shader, program;
|
||||
GLint mvp_location, vpos_location, vcol_location;
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
||||
|
||||
glfwWindowHint(GLFW_ALPHA_BITS, 8);
|
||||
glfwWindowHint(GLFW_TRANSPARENT, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_DECORATED, GLFW_TRUE);
|
||||
|
||||
window = glfwCreateWindow(256, 256, "Transparent window example", NULL, NULL);
|
||||
if (!window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwSetWindowPos(window, 300, 300);
|
||||
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
// NOTE: OpenGL error checks have been omitted for brevity
|
||||
|
||||
glGenBuffers(1, &vertex_buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
vertex_shader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL);
|
||||
glCompileShader(vertex_shader);
|
||||
|
||||
fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragment_shader, 1, &fragment_shader_text, NULL);
|
||||
glCompileShader(fragment_shader);
|
||||
|
||||
program = glCreateProgram();
|
||||
glAttachShader(program, vertex_shader);
|
||||
glAttachShader(program, fragment_shader);
|
||||
glLinkProgram(program);
|
||||
|
||||
mvp_location = glGetUniformLocation(program, "MVP");
|
||||
vpos_location = glGetAttribLocation(program, "vPos");
|
||||
vcol_location = glGetAttribLocation(program, "vCol");
|
||||
|
||||
glEnableVertexAttribArray(vpos_location);
|
||||
glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE,
|
||||
sizeof(float) * 5, (void*) 0);
|
||||
glEnableVertexAttribArray(vcol_location);
|
||||
glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE,
|
||||
sizeof(float) * 5, (void*) (sizeof(float) * 2));
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
float ratio;
|
||||
int width, height;
|
||||
mat4x4 m, p, mvp;
|
||||
|
||||
glfwGetFramebufferSize(window, &width, &height);
|
||||
ratio = width / (float) height;
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
glClearColor(0,0,0,0.5);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
mat4x4_identity(m);
|
||||
mat4x4_rotate_Z(m, m, (float) glfwGetTime());
|
||||
mat4x4_ortho(p, -ratio, ratio, -1.f, 1.f, 1.f, -1.f);
|
||||
mat4x4_mul(mvp, p, m);
|
||||
|
||||
glUseProgram(program);
|
||||
glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*) mvp);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
//! [code]
|
@ -658,6 +658,7 @@ extern "C" {
|
||||
#define GLFW_SRGB_CAPABLE 0x0002100E
|
||||
#define GLFW_REFRESH_RATE 0x0002100F
|
||||
#define GLFW_DOUBLEBUFFER 0x00021010
|
||||
#define GLFW_TRANSPARENT 0x00021011
|
||||
|
||||
#define GLFW_CLIENT_API 0x00022001
|
||||
#define GLFW_CONTEXT_VERSION_MAJOR 0x00022002
|
||||
|
@ -418,7 +418,11 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
|
||||
|
||||
- (BOOL)isOpaque
|
||||
{
|
||||
return YES;
|
||||
// Set to NO even if transparent is not used;
|
||||
// The NSView/GLFWContentView does not need to be opaque anyway,
|
||||
// and to avoid keeping track of transparent inside the NSView we
|
||||
// just return NO here instead.
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)canBecomeKeyView
|
||||
@ -1137,13 +1141,32 @@ void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
|
||||
|
||||
void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos)
|
||||
{
|
||||
const NSRect contentRect =
|
||||
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
|
||||
// Code from Matt Reagan on the Cocoa-dev mailing list.
|
||||
CGRect rect;
|
||||
CGWindowID windowID = (CGWindowID)[window->ns.object windowNumber];
|
||||
CFArrayRef windowArray = CGWindowListCopyWindowInfo(kCGWindowListOptionIncludingWindow, windowID);
|
||||
|
||||
if (CFArrayGetCount(windowArray))
|
||||
{
|
||||
CFDictionaryRef windowInfoDictionary = (CFDictionaryRef)CFArrayGetValueAtIndex ((CFArrayRef)windowArray, 0);
|
||||
|
||||
if (CFDictionaryContainsKey(windowInfoDictionary, kCGWindowBounds))
|
||||
{
|
||||
CFDictionaryRef bounds = (CFDictionaryRef)CFDictionaryGetValue(windowInfoDictionary, kCGWindowBounds);
|
||||
|
||||
if (bounds)
|
||||
{
|
||||
CGRectMakeWithDictionaryRepresentation(bounds, &rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(windowArray);
|
||||
|
||||
if (xpos)
|
||||
*xpos = contentRect.origin.x;
|
||||
*xpos = rect.origin.x;
|
||||
if (ypos)
|
||||
*ypos = transformY(contentRect.origin.y + contentRect.size.height);
|
||||
*ypos = rect.origin.y;
|
||||
}
|
||||
|
||||
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y)
|
||||
|
@ -355,6 +355,7 @@ struct _GLFWwindow
|
||||
GLFWbool decorated;
|
||||
GLFWbool autoIconify;
|
||||
GLFWbool floating;
|
||||
GLFWbool transparent;
|
||||
GLFWbool closed;
|
||||
void* userPointer;
|
||||
GLFWvidmode videoMode;
|
||||
|
@ -283,6 +283,12 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window,
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
||||
if (fbconfig->transparent)
|
||||
{
|
||||
GLint opaque = 0;
|
||||
[window->context.nsgl.object setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
|
||||
}
|
||||
|
||||
[window->context.nsgl.object setView:window->ns.view];
|
||||
|
||||
window->context.makeCurrent = makeContextCurrentNSGL;
|
||||
|
147
tests/transparent_threads.c
Normal file
147
tests/transparent_threads.c
Normal file
@ -0,0 +1,147 @@
|
||||
//========================================================================
|
||||
// Multi-threading test
|
||||
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
//
|
||||
// This test is intended to verify whether the OpenGL context part of
|
||||
// the GLFW API is able to be used from multiple threads
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include "tinycthread.h"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GLFWwindow* window;
|
||||
const char* title;
|
||||
float r, g, b, a;
|
||||
thrd_t id;
|
||||
} Thread;
|
||||
|
||||
static volatile int running = GLFW_TRUE;
|
||||
|
||||
static void error_callback(int error, const char* description)
|
||||
{
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
static int thread_main(void* data)
|
||||
{
|
||||
const Thread* thread = data;
|
||||
|
||||
glfwMakeContextCurrent(thread->window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
while (running)
|
||||
{
|
||||
const float v = (float) fabs(sin(glfwGetTime() * 2.f));
|
||||
glClearColor(thread->r * v, thread->g * v, thread->b * v, thread->a * v);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glfwSwapBuffers(thread->window);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i, result;
|
||||
Thread threads[] =
|
||||
{
|
||||
{ NULL, "Red", 1.0f, 0.0f, 0.0f, 0.5f, 0 },
|
||||
{ NULL, "Green", 0.0f, 1.0f, 0.0f, 0.5f, 0 },
|
||||
{ NULL, "Blue", 0.0f, 0.0f, 1.0f, 0.5f, 0 }
|
||||
};
|
||||
const int count = sizeof(threads) / sizeof(Thread);
|
||||
|
||||
glfwSetErrorCallback(error_callback);
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
||||
|
||||
glfwWindowHint(GLFW_ALPHA_BITS, 8);
|
||||
glfwWindowHint(GLFW_TRANSPARENT, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_DECORATED, GLFW_TRUE);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
threads[i].window = glfwCreateWindow(200, 200,
|
||||
threads[i].title,
|
||||
NULL, NULL);
|
||||
if (!threads[i].window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200);
|
||||
glfwShowWindow(threads[i].window);
|
||||
}
|
||||
|
||||
glfwMakeContextCurrent(threads[0].window);
|
||||
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
|
||||
glfwMakeContextCurrent(NULL);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (thrd_create(&threads[i].id, thread_main, threads + i) !=
|
||||
thrd_success)
|
||||
{
|
||||
fprintf(stderr, "Failed to create secondary thread\n");
|
||||
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
while (running)
|
||||
{
|
||||
glfwWaitEvents();
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (glfwWindowShouldClose(threads[i].window))
|
||||
running = GLFW_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
glfwHideWindow(threads[i].window);
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
thrd_join(threads[i].id, &result);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user