Begun integrating monitor and window.

This commit is contained in:
Camilla Berglund 2012-09-27 21:37:36 +02:00
parent 7aaeb6955b
commit 1be1636326
32 changed files with 106 additions and 112 deletions

View File

@ -581,7 +581,7 @@ int main( void )
glfwWindowHint(GLFW_DEPTH_BITS, 16);
window = glfwCreateWindow( 400, 400, GLFW_WINDOWED, "Boing (classic Amiga demo)", NULL );
window = glfwCreateWindow( 400, 400, "Boing (classic Amiga demo)", NULL, NULL );
if (!window)
{
fprintf( stderr, "Failed to open GLFW window\n" );

View File

@ -345,7 +345,7 @@ int main(int argc, char *argv[])
glfwWindowHint(GLFW_DEPTH_BITS, 16);
window = glfwCreateWindow( 300, 300, GLFW_WINDOWED, "Gears", NULL );
window = glfwCreateWindow( 300, 300, "Gears", NULL, NULL );
if (!window)
{
fprintf( stderr, "Failed to open GLFW window\n" );

View File

@ -587,7 +587,7 @@ int main(int argc, char** argv)
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE);
window = glfwCreateWindow(800, 600, GLFW_WINDOWED, "GLFW OpenGL3 Heightmap demo", NULL);
window = glfwCreateWindow(800, 600, "GLFW OpenGL3 Heightmap demo", NULL, NULL);
if (! window )
{
fprintf(stderr, "ERROR: Unable to create the OpenGL context and associated window\n");

View File

@ -459,7 +459,7 @@ int main(void)
glfwWindowHint(GLFW_DEPTH_BITS, 16);
// Open OpenGL window
window = glfwCreateWindow(500, 500, GLFW_WINDOWED, "Split view demo", NULL);
window = glfwCreateWindow(500, 500, "Split view demo", NULL, NULL);
if (!window)
{
fprintf(stderr, "Failed to open GLFW window\n");

View File

@ -23,7 +23,7 @@ int main(void)
}
// Open a window and create its OpenGL context
window = glfwCreateWindow(640, 480, GLFW_WINDOWED, "Spinning Triangle", NULL);
window = glfwCreateWindow(640, 480, "Spinning Triangle", NULL, NULL);
if (!window)
{
fprintf(stderr, "Failed to open GLFW window\n");

View File

@ -406,7 +406,7 @@ int main(int argc, char* argv[])
glfwSetCursorPosCallback(cursor_position_callback);
glfwSetScrollCallback(scroll_callback);
window = glfwCreateWindow(640, 480, GLFW_WINDOWED, "Wave Simulation", NULL);
window = glfwCreateWindow(640, 480, "Wave Simulation", NULL, NULL);
if (!window)
{
fprintf(stderr, "Could not open window\n");

View File

@ -375,10 +375,6 @@ extern "C" {
* Other definitions
*************************************************************************/
/* glfwCreateWindow modes */
#define GLFW_WINDOWED 0x00010001
#define GLFW_FULLSCREEN 0x00010002
/* glfwGetWindowParam tokens */
#define GLFW_ACTIVE 0x00020001
#define GLFW_ICONIFIED 0x00020002
@ -548,7 +544,7 @@ GLFWAPI void glfwSetGammaRamp(const GLFWgammaramp* ramp);
/* Window handling */
GLFWAPI void glfwWindowHint(int target, int hint);
GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, int mode, const char* title, GLFWwindow share);
GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, const char* title, GLFWmonitor monitor, GLFWwindow share);
GLFWAPI void glfwDestroyWindow(GLFWwindow window);
GLFWAPI void glfwSetWindowTitle(GLFWwindow window, const char* title);
GLFWAPI void glfwGetWindowSize(GLFWwindow window, int* width, int* height);

View File

@ -297,7 +297,6 @@ version of GLFW.</p>
<li>Changed <code>glfwGetVideoModes</code> to return a dynamic, unlimited number of video modes</li>
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li>
<li>Renamed <code>glfwOpenWindowHint</code> to <code>glfwWindowHint</code></li>
<li>Renamed <code>GLFW_WINDOW</code> token to <code>GLFW_WINDOWED</code></li>
<li>Renamed <code>GLFW_WINDOW_NO_RESIZE</code> to <code>GLFW_RESIZABLE</code></li>
<li>Renamed <code>GLFW_BUILD_DLL</code> to <code>_GLFW_BUILD_DLL</code></li>
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li>
@ -322,6 +321,7 @@ version of GLFW.</p>
<li>Removed <code>glfwGetNumberOfProcessors</code> function</li>
<li>Removed <code>glfwGetGLVersion</code> function</li>
<li>Removed <code>GLFW_OPENED</code> window parameter</li>
<li>Removed <code>GLFW_WINDOW</code> and <code>GLFW_FULLSCREEN</code></li>
<li>Removed nonsensical key actions for Unicode character input</li>
<li>Removed <code>GLFWCALL</code> and <code>GLFWAPIENTRY</code> macros for stdcall calling convention</li>
<li>Removed <code>GLFW_ACCELERATED</code> window parameter</li>

View File

@ -674,7 +674,9 @@ static GLboolean createWindow(_GLFWwindow* window,
{
unsigned int styleMask = 0;
if (wndconfig->mode == GLFW_WINDOWED)
if (wndconfig->monitor)
styleMask = NSBorderlessWindowMask;
else
{
styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask;
@ -682,8 +684,6 @@ static GLboolean createWindow(_GLFWwindow* window,
if (wndconfig->resizable)
styleMask |= NSResizableWindowMask;
}
else
styleMask = NSBorderlessWindowMask;
window->NS.object = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, window->width, window->height)
@ -788,7 +788,7 @@ static GLboolean createContext(_GLFWwindow* window,
ADD_ATTR(NSOpenGLPFADoubleBuffer);
if (wndconfig->mode == GLFW_FULLSCREEN)
if (wndconfig->monitor)
{
ADD_ATTR(NSOpenGLPFANoRecovery);
ADD_ATTR2(NSOpenGLPFAScreenMask,
@ -919,7 +919,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
[window->NSGL.context setView:[window->NS.object contentView]];
if (wndconfig->mode == GLFW_FULLSCREEN)
if (wndconfig->monitor)
{
int bpp = colorBits + fbconfig->alphaBits;
@ -952,7 +952,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
{
[window->NS.object orderOut:nil];
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
[[window->NS.object contentView] exitFullScreenModeWithOptions:nil];
@ -1121,7 +1121,7 @@ void _glfwPlatformWaitEvents( void )
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
{
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
CGPoint globalPoint = CGPointMake(x, y);
CGDisplayMoveCursorToPoint(CGMainDisplayID(), globalPoint);

View File

@ -129,6 +129,7 @@ struct _GLFWwndconfig
GLboolean glDebug;
int glProfile;
int glRobustness;
_GLFWmonitor* monitor;
_GLFWwindow* share;
};
@ -176,6 +177,7 @@ struct _GLFWwindow
GLboolean visible; // GL_TRUE if this window is visible
int refreshRate; // monitor refresh rate
void* userPointer;
_GLFWmonitor* monitor;
// Window input state
GLboolean stickyKeys;

View File

@ -156,12 +156,20 @@ void _glfwInputMonitorChange(void)
for (i = 0; i < _glfwLibrary.monitorCount; i++)
{
_GLFWwindow* window;
if (_glfwLibrary.monitors[i] == NULL)
continue;
// This monitor is no longer connected
_glfwLibrary.monitorCallback(_glfwLibrary.monitors[i],
GLFW_MONITOR_DISCONNECTED);
for (window = _glfwLibrary.windowListHead; window; window = window->next)
{
if (window->monitor == _glfwLibrary.monitors[i])
window->monitor = NULL;
}
}
_glfwDestroyMonitors();

View File

@ -344,7 +344,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
showCursor(window);
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
if (!iconified)
{
@ -367,7 +367,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
captureCursor(window);
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
if (!_glfwLibrary.Win32.monitor.modeChanged)
{
@ -400,7 +400,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case SC_SCREENSAVE:
case SC_MONITORPOWER:
{
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
// We are running in fullscreen mode, so disallow
// screen saver and screen blanking
@ -738,7 +738,7 @@ static int createWindow(_GLFWwindow* window,
dwExStyle = WS_EX_APPWINDOW;
// Set window style, depending on fullscreen mode
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
dwStyle |= WS_POPUP;
@ -775,7 +775,7 @@ static int createWindow(_GLFWwindow* window,
// Adjust window position to working area (e.g. if the task bar is at
// the top of the display). Fullscreen windows are always opened in
// the upper left corner regardless of the desktop working area.
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
wa.left = wa.top = 0;
else
SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0);
@ -866,7 +866,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
return GL_FALSE;
}
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
int bpp = fbconfig->redBits + fbconfig->greenBits + fbconfig->blueBits;
if (bpp < 15 || bpp >= 24)
@ -962,7 +962,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
return GL_FALSE;
}
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
// Place the window above all topmost windows
_glfwPlatformShowWindow(window);
@ -982,7 +982,7 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window)
{
destroyWindow(window);
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
if (_glfwLibrary.Win32.monitor.modeChanged)
{
@ -1021,7 +1021,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
{
GLboolean sizeChanged = GL_FALSE;
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
if (width > window->width || height > window->height)
{

View File

@ -224,7 +224,8 @@ void _glfwInputWindowCloseRequest(_GLFWwindow* window)
//========================================================================
GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
int mode, const char* title,
const char* title,
GLFWmonitor monitor,
GLFWwindow share)
{
_GLFWfbconfig fbconfig;
@ -257,7 +258,6 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
fbconfig.samples = Max(_glfwLibrary.hints.samples, 0);
// Set up desired window config
wndconfig.mode = mode;
wndconfig.title = title;
wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0);
wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE;
@ -268,6 +268,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
wndconfig.glDebug = _glfwLibrary.hints.glDebug ? GL_TRUE : GL_FALSE;
wndconfig.glProfile = _glfwLibrary.hints.glProfile;
wndconfig.glRobustness = _glfwLibrary.hints.glRobustness ? GL_TRUE : GL_FALSE;
wndconfig.monitor = (_GLFWmonitor*) monitor;
wndconfig.share = share;
// Reset to default values for the next call
@ -280,13 +281,6 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
// Save the currently current context so it can be restored later
previous = glfwGetCurrentContext();
if (mode != GLFW_WINDOWED && mode != GLFW_FULLSCREEN)
{
_glfwSetError(GLFW_INVALID_ENUM,
"glfwCreateWindow: Invalid window mode");
return GL_FALSE;
}
// Check width & height
if (width > 0 && height <= 0)
{
@ -320,10 +314,10 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
// Remember window settings
window->width = width;
window->height = height;
window->mode = mode;
window->resizable = wndconfig.resizable;
window->cursorMode = GLFW_CURSOR_NORMAL;
window->systemKeys = GL_TRUE;
window->monitor = (_GLFWmonitor*) monitor;
// Open the actual window and create its context
if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig))
@ -364,10 +358,10 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
// The GLFW specification states that fullscreen windows have the cursor
// captured by default
if (mode == GLFW_FULLSCREEN)
if (wndconfig.monitor)
glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
if (mode == GLFW_WINDOWED && wndconfig.visible)
if (wndconfig.monitor == NULL && wndconfig.visible)
glfwShowWindow(window);
return window;
@ -570,7 +564,7 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow handle, int width, int height)
_glfwPlatformSetWindowSize(window, width, height);
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
// Refresh window parameters (may have changed due to changed video
// modes)
@ -615,7 +609,7 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow handle, int xpos, int ypos)
return;
}
if (window->mode == GLFW_FULLSCREEN || window->iconified)
if (window->monitor || window->iconified)
{
// TODO: Figure out if this is an error
return;
@ -665,7 +659,7 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow handle)
_glfwPlatformRestoreWindow(window);
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
_glfwPlatformRefreshWindowParams(window);
}
@ -684,7 +678,7 @@ GLFWAPI void glfwShowWindow(GLFWwindow handle)
return;
}
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
return;
_glfwPlatformShowWindow(window);
@ -705,7 +699,7 @@ GLFWAPI void glfwHideWindow(GLFWwindow handle)
return;
}
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
return;
_glfwPlatformHideWindow(window);

View File

@ -107,7 +107,7 @@ static GLboolean createWindow(_GLFWwindow* window,
ExposureMask | FocusChangeMask | VisibilityChangeMask |
EnterWindowMask | LeaveWindowMask;
if (wndconfig->mode == GLFW_WINDOWED)
if (!wndconfig->monitor)
{
// The /only/ reason for setting the background pixel here is that
// otherwise our window won't get any decorations on systems using
@ -138,7 +138,7 @@ static GLboolean createWindow(_GLFWwindow* window,
}
}
if (window->mode == GLFW_FULLSCREEN && !_glfwLibrary.X11.hasEWMH)
if (window->monitor && !_glfwLibrary.X11.hasEWMH)
{
// This is the butcher's way of removing window decorations
// Setting the override-redirect attribute on a window makes the window
@ -851,7 +851,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
}
#endif /*_GLFW_HAS_XRANDR*/
if (wndconfig->mode == GLFW_FULLSCREEN)
if (wndconfig->monitor)
{
_glfwPlatformShowWindow(window);
enterFullscreenMode(window);
@ -887,7 +887,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
void _glfwPlatformDestroyWindow(_GLFWwindow* window)
{
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
leaveFullscreenMode(window);
_glfwDestroyContext(window);
@ -959,7 +959,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
rate = window->refreshRate;
if (window->mode == GLFW_FULLSCREEN)
if (window->monitor)
{
// Get the closest matching video mode for the specified window size
mode = _glfwGetClosestVideoMode(&width, &height, &rate);
@ -979,15 +979,17 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
XFree(hints);
}
// Change window size before changing fullscreen mode?
if (window->mode == GLFW_FULLSCREEN && (width > window->width))
if (window->monitor)
{
XResizeWindow(_glfwLibrary.X11.display, window->X11.handle, width, height);
sizeChanged = GL_TRUE;
}
// Change window size before changing fullscreen mode?
if (width > window->width)
{
XResizeWindow(_glfwLibrary.X11.display,
window->X11.handle,
width, height);
sizeChanged = GL_TRUE;
}
if (window->mode == GLFW_FULLSCREEN)
{
// Change video mode, keeping current refresh rate
_glfwSetVideoModeMODE(mode, window->refreshRate);
}

View File

@ -90,7 +90,7 @@ int main(void)
glfwSetWindowSizeCallback(window_size_callback);
glfwSetKeyCallback(key_callback);
window = glfwCreateWindow(window_width, window_height, GLFW_WINDOWED, "", NULL);
window = glfwCreateWindow(window_width, window_height, "", NULL, NULL);
if (!window)
{
glfwTerminate();

View File

@ -125,7 +125,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Clipboard Test", NULL);
window = glfwCreateWindow(0, 0, "Clipboard Test", NULL, NULL);
if (!window)
{
glfwTerminate();

View File

@ -85,7 +85,7 @@ int main(void)
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Defaults", NULL);
window = glfwCreateWindow(0, 0, "Defaults", NULL, NULL);
if (!window)
{
glfwTerminate();

View File

@ -399,7 +399,7 @@ int main(void)
glfwSetCharCallback(char_callback);
glfwSetMonitorCallback(monitor_callback);
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Event Linter", NULL);
window = glfwCreateWindow(0, 0, "Event Linter", NULL, NULL);
if (!window)
{
glfwTerminate();

View File

@ -98,7 +98,7 @@ int main(int argc, char** argv)
glfwWindowHint(GLFW_FSAA_SAMPLES, samples);
window = glfwCreateWindow(800, 400, GLFW_WINDOWED, "Aliasing Detector", NULL);
window = glfwCreateWindow(800, 400, "Aliasing Detector", NULL, NULL);
if (!window)
{
glfwTerminate();

View File

@ -82,7 +82,7 @@ int main(void)
exit(EXIT_FAILURE);
}
window = glfwCreateWindow(640, 480, GLFW_FULLSCREEN, "Fullscreen focus", NULL);
window = glfwCreateWindow(640, 480, "Fullscreen focus", glfwGetPrimaryMonitor(), NULL);
if (!window)
{
glfwTerminate();

View File

@ -97,7 +97,7 @@ static void size_callback(GLFWwindow window, int width, int height)
int main(int argc, char** argv)
{
int width, height, ch;
int mode = GLFW_WINDOWED;
GLFWmonitor monitor = NULL;
GLFWwindow window;
while ((ch = getopt(argc, argv, "fh")) != -1)
@ -109,7 +109,7 @@ int main(int argc, char** argv)
exit(EXIT_SUCCESS);
case 'f':
mode = GLFW_FULLSCREEN;
monitor = glfwGetPrimaryMonitor();
break;
default:
@ -124,10 +124,10 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
if (mode == GLFW_FULLSCREEN)
if (monitor)
{
GLFWvidmode mode;
glfwGetVideoMode(glfwGetPrimaryMonitor(), &mode);
glfwGetVideoMode(monitor, &mode);
width = mode.width;
height = mode.height;
}
@ -137,7 +137,7 @@ int main(int argc, char** argv)
height = 0;
}
window = glfwCreateWindow(width, height, mode, "Gamma Test", NULL);
window = glfwCreateWindow(width, height, "Gamma Test", monitor, NULL);
if (!window)
{
glfwTerminate();

View File

@ -243,7 +243,7 @@ int main(int argc, char** argv)
// We assume here that we stand a better chance of success by leaving all
// possible details of pixel format selection to GLFW
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
window = glfwCreateWindow(0, 0, "Version", NULL, NULL);
if (!window)
exit(EXIT_FAILURE);

View File

@ -78,8 +78,8 @@ static void window_size_callback(GLFWwindow window, int width, int height)
int main(int argc, char** argv)
{
int width, height, ch;
int mode = GLFW_WINDOWED;
GLboolean active = -1, iconified = -1;
GLFWmonitor monitor = NULL;
GLFWwindow window;
while ((ch = getopt(argc, argv, "fh")) != -1)
@ -91,7 +91,7 @@ int main(int argc, char** argv)
exit(EXIT_SUCCESS);
case 'f':
mode = GLFW_FULLSCREEN;
monitor = glfwGetPrimaryMonitor();
break;
default:
@ -106,12 +106,12 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
if (mode == GLFW_FULLSCREEN)
if (monitor)
{
GLFWvidmode current_mode;
glfwGetVideoMode(glfwGetPrimaryMonitor(), &current_mode);
width = current_mode.width;
height = current_mode.height;
GLFWvidmode mode;
glfwGetVideoMode(monitor, &mode);
width = mode.width;
height = mode.height;
}
else
{
@ -119,7 +119,7 @@ int main(int argc, char** argv)
height = 0;
}
window = glfwCreateWindow(width, height, mode, "Iconify", NULL);
window = glfwCreateWindow(width, height, "Iconify", monitor, NULL);
if (!window)
{
glfwTerminate();

View File

@ -186,7 +186,7 @@ int main(void)
exit(EXIT_FAILURE);
}
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Joystick Test", NULL);
window = glfwCreateWindow(0, 0, "Joystick Test", NULL, NULL);
if (!window)
{
glfwTerminate();

View File

@ -144,7 +144,8 @@ static void test_modes(GLFWmonitor monitor)
format_mode(mode));
window_handle = glfwCreateWindow(mode->width, mode->height,
GLFW_FULLSCREEN, "Video Mode Test",
"Video Mode Test",
glfwGetPrimaryMonitor(),
NULL);
if (!window_handle)
{

View File

@ -92,7 +92,7 @@ static void window_size_callback(GLFWwindow window, int width, int height)
static GLboolean open_window(void)
{
window_handle = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Peter Detector", NULL);
window_handle = glfwCreateWindow(0, 0, "Peter Detector", NULL, NULL);
if (!window_handle)
return GL_FALSE;

View File

@ -41,19 +41,6 @@
static GLFWwindow window_handle = NULL;
static GLboolean closed = GL_FALSE;
static const char* get_mode_name(int mode)
{
switch (mode)
{
case GLFW_WINDOWED:
return "windowed";
case GLFW_FULLSCREEN:
return "fullscreen";
default:
return "unknown";
}
}
static void window_size_callback(GLFWwindow window, int width, int height)
{
glViewport(0, 0, width, height);
@ -80,22 +67,18 @@ static void key_callback(GLFWwindow window, int key, int action)
}
}
static GLboolean open_window(int width, int height, int mode)
static GLboolean open_window(int width, int height, GLFWmonitor monitor)
{
double base;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
return GL_FALSE;
}
base = glfwGetTime();
window_handle = glfwCreateWindow(width, height, mode, "Window Re-opener", NULL);
window_handle = glfwCreateWindow(width, height, "Window Re-opener", monitor, NULL);
if (!window_handle)
{
fprintf(stderr, "Failed to open %s mode GLFW window: %s\n", get_mode_name(mode), glfwErrorString(glfwGetError()));
fprintf(stderr, "Failed to open %s mode GLFW window: %s\n",
monitor ? "fullscreen" : "windowed",
glfwErrorString(glfwGetError()));
return GL_FALSE;
}
@ -107,7 +90,7 @@ static GLboolean open_window(int width, int height, int mode)
glfwSetKeyCallback(key_callback);
printf("Opening %s mode window took %0.3f seconds\n",
get_mode_name(mode),
monitor ? "fullscreen" : "windowed",
glfwGetTime() - base);
return GL_TRUE;
@ -121,17 +104,26 @@ static void close_window(void)
window_handle = NULL;
printf("Closing window took %0.3f seconds\n", glfwGetTime() - base);
glfwTerminate();
}
int main(int argc, char** argv)
{
int count = 0;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
return GL_FALSE;
}
for (;;)
{
if (!open_window(640, 480, (count & 1) ? GLFW_FULLSCREEN : GLFW_WINDOWED))
GLFWmonitor monitor = NULL;
if (count & 1)
monitor = glfwGetPrimaryMonitor();
if (!open_window(640, 480, monitor))
exit(EXIT_FAILURE);
glMatrixMode(GL_PROJECTION);

View File

@ -55,7 +55,7 @@ static GLFWwindow open_window(const char* title, GLFWwindow share)
{
GLFWwindow window;
window = glfwCreateWindow(WIDTH, HEIGHT, GLFW_WINDOWED, title, share);
window = glfwCreateWindow(WIDTH, HEIGHT, title, NULL, share);
if (!window)
return NULL;

View File

@ -70,7 +70,7 @@ int main(void)
exit(EXIT_FAILURE);
}
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "", NULL);
window = glfwCreateWindow(0, 0, "", NULL, NULL);
if (!window)
{
glfwTerminate();

View File

@ -90,9 +90,8 @@ int main(void)
for (i = 0; i < count; i++)
{
threads[i].window = glfwCreateWindow(200, 200,
GLFW_WINDOWED,
threads[i].title,
NULL);
NULL, NULL);
if (!threads[i].window)
{
fprintf(stderr, "Failed to open GLFW window: %s\n",

View File

@ -47,7 +47,7 @@ int main(void)
exit(EXIT_FAILURE);
}
window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "English 日本語 русский язык 官話", NULL);
window = glfwCreateWindow(0, 0, "English 日本語 русский язык 官話", NULL, NULL);
if (!window)
{
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));

View File

@ -55,7 +55,7 @@ int main(void)
for (i = 0; i < 4; i++)
{
windows[i] = glfwCreateWindow(200, 200, GLFW_WINDOWED, titles[i], NULL);
windows[i] = glfwCreateWindow(200, 200, titles[i], NULL, NULL);
if (!windows[i])
{
fprintf(stderr, "Failed to open GLFW window: %s\n",