Merge branch 'master' of ssh://glfw.git.sourceforge.net/gitroot/glfw/glfw

This commit is contained in:
Camilla Berglund 2010-10-04 21:15:54 +02:00
Родитель 25de1dd957 9e1031a35a
Коммит ba9f028eba
5 изменённых файлов: 161 добавлений и 10 удалений

Просмотреть файл

@ -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)

0
src/win32/win32_window.c Executable file → Normal file
Просмотреть файл

Просмотреть файл

@ -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

Просмотреть файл

153
tests/sharing.c Normal file
Просмотреть файл

@ -0,0 +1,153 @@
//========================================================================
// Context sharing test program
// 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 program is used to test sharing of objects between contexts
//
//========================================================================
#include <GL/glfw3.h>
#include <stdio.h>
#include <stdlib.h>
#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);
}