diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1390ab13..3f5a7c4f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -5,8 +5,6 @@ link_libraries(libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include ${OPENGL_INCLUDE_DIR}) -add_executable(listmodes listmodes.c) - if(APPLE) # Set fancy names for bundles add_executable(Boing MACOSX_BUNDLE boing.c) @@ -25,21 +23,17 @@ else(APPLE) endif(APPLE) set(WINDOWS_BINARIES boing gears heightmap splitview triangle wave) -set(CONSOLE_BINARIES listmodes) if(MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables - set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} + set_target_properties(${WINDOWS_BINARIES} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") endif(MSVC) if(CYGWIN) # Set cross-compile and subsystem compile and link flags - set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} - PROPERTIES COMPILE_FLAGS "-mno-cygwin") set_target_properties(${WINDOWS_BINARIES} + PROPERTIES COMPILE_FLAGS "-mno-cygwin" PROPERTIES LINK_FLAGS "-mno-cygwin -mwindows") - set_target_properties(${CONSOLE_BINARIES} - PROPERTIES LINK_FLAGS "-mno-cygwin -mconsole") endif(CYGWIN) diff --git a/src/win32/win32_window.c b/src/win32/win32_window.c old mode 100755 new mode 100644 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fcd76746..085b6b67 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,6 +8,7 @@ add_executable(events events.c) add_executable(fsfocus fsfocus.c) add_executable(iconify iconify.c getopt.c) add_executable(joysticks joysticks.c) +add_executable(listmodes listmodes.c) add_executable(peter peter.c) add_executable(reopen reopen.c) add_executable(version version.c getopt.c) @@ -16,18 +17,21 @@ if(APPLE) # Set fancy names for bundles add_executable(Accuracy MACOSX_BUNDLE accuracy.c) add_executable(FSAA MACOSX_BUNDLE fsaa.c) + add_executable(Sharing MACOSX_BUNDLE sharing.c) add_executable(Tearing MACOSX_BUNDLE tearing.c) add_executable(Windows MACOSX_BUNDLE windows.c) else() # Set boring names for executables add_executable(accuracy WIN32 accuracy.c) + add_executable(sharing WIN32 sharing.c) add_executable(tearing WIN32 tearing.c) add_executable(fsaa WIN32 fsaa.c) add_executable(windows WIN32 windows.c) endif(APPLE) -set(WINDOWS_BINARIES accuracy tearing windows) -set(CONSOLE_BINARIES defaults events fsaa fsfocus iconify joysticks peter reopen version) +set(WINDOWS_BINARIES accuracy sharing tearing windows) +set(CONSOLE_BINARIES defaults events fsaa fsfocus iconify joysticks listmodes + peter reopen version) if(MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables diff --git a/examples/listmodes.c b/tests/listmodes.c similarity index 100% rename from examples/listmodes.c rename to tests/listmodes.c diff --git a/tests/sharing.c b/tests/sharing.c new file mode 100644 index 00000000..0c6f5988 --- /dev/null +++ b/tests/sharing.c @@ -0,0 +1,153 @@ +//======================================================================== +// Context sharing test program +// Copyright (c) Camilla Berglund +// +// 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 program is used to test sharing of objects between contexts +// +//======================================================================== + +#include + +#include +#include + +#define WIDTH 400 +#define HEIGHT 400 + +static GLFWwindow open_window(const char* title, GLFWwindow share) +{ + GLFWwindow window; + + window = glfwOpenWindow(WIDTH, HEIGHT, GLFW_WINDOWED, title, share); + if (!window) + return NULL; + + glfwSwapInterval(1); + + return window; +} + +static GLuint create_texture(void) +{ + int x, y; + char pixels[256 * 256]; + GLuint texture; + + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + + for (y = 0; y < 256; y++) + { + for (x = 0; x < 256; x++) + pixels[y * 256 + x] = rand() % 256; + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 256, 256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + return texture; +} + +static void draw_quad(GLuint texture) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0.f, 1.f, 0.f, 1.f); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texture); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + glColor3f(0.6f, 0.f, 0.6f); + + glBegin(GL_QUADS); + + glTexCoord2f(0.f, 0.f); + glVertex2f(0.f, 0.f); + + glTexCoord2f(1.f, 0.f); + glVertex2f(1.f, 0.f); + + glTexCoord2f(1.f, 1.f); + glVertex2f(1.f, 1.f); + + glTexCoord2f(0.f, 1.f); + glVertex2f(0.f, 1.f); + + glEnd(); +} + +int main(int argc, char** argv) +{ + GLFWwindow windows[2]; + GLuint texture; + int x, y; + + if (!glfwInit()) + { + fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); + exit(EXIT_FAILURE); + } + + windows[0] = open_window("First", NULL); + if (!windows[0]) + { + fprintf(stderr, "Failed to open first GLFW window: %s\n", glfwErrorString(glfwGetError())); + exit(EXIT_FAILURE); + } + + glfwGetWindowPos(windows[0], &x, &y); + + // This is the one and only time we create a texture + // It is created inside the first context created above + // It will then be shared with the second context created below + texture = create_texture(); + + windows[1] = open_window("Second", windows[0]); + if (!windows[1]) + { + fprintf(stderr, "Failed to open second GLFW window: %s\n", glfwErrorString(glfwGetError())); + exit(EXIT_FAILURE); + } + + glfwSetWindowPos(windows[1], x + WIDTH + 50, y); + + while (glfwIsWindow(windows[0]) && glfwIsWindow(windows[1])) + { + glfwMakeWindowCurrent(windows[0]); + draw_quad(texture); + glfwSwapBuffers(); + + glfwMakeWindowCurrent(windows[1]); + draw_quad(texture); + glfwSwapBuffers(); + + glfwWaitEvents(); + } + + glfwTerminate(); + exit(EXIT_SUCCESS); +} +