GLFWAPI int GLFWAPIENTRY glfwOpenWindow( int width, int height, int redbits, int greenbits, int bluebits, int alphabits, int depthbits, int stencilbits, int mode ) { int AccumRedBits, AccumGreenBits, AccumBlueBits, AccumAlphaBits; int AuxBuffers, Stereo, RefreshRate, x, Samples; // Is GLFW initialized? if( !_glfwInitialized || _glfwWin.Opened ) { return GL_FALSE; } // Check input arguments if( mode != GLFW_WINDOW && mode != GLFW_FULLSCREEN ) { return GL_FALSE; } // Clear GLFW window state _glfwWin.Active = GL_TRUE; _glfwWin.Iconified = GL_FALSE; _glfwWin.MouseLock = GL_FALSE; _glfwWin.AutoPollEvents = GL_TRUE; _glfwClearInput(); // Unregister all callback functions _glfwWin.WindowSizeCallback = NULL; _glfwWin.WindowCloseCallback = NULL; _glfwWin.WindowRefreshCallback = NULL; _glfwWin.KeyCallback = NULL; _glfwWin.CharCallback = NULL; _glfwWin.MousePosCallback = NULL; _glfwWin.MouseButtonCallback = NULL; _glfwWin.MouseWheelCallback = NULL; // Get window hints AccumRedBits = _glfwWinHints.AccumRedBits; AccumGreenBits = _glfwWinHints.AccumGreenBits; AccumBlueBits = _glfwWinHints.AccumBlueBits; AccumAlphaBits = _glfwWinHints.AccumAlphaBits; AuxBuffers = _glfwWinHints.AuxBuffers; Stereo = _glfwWinHints.Stereo; RefreshRate = _glfwWinHints.RefreshRate; Samples = _glfwWinHints.Samples; // Check width & height if( width > 0 && height <= 0 ) { // Set the window aspect ratio to 4:3 height = (width * 3) / 4; } else if( width <= 0 && height > 0 ) { // Set the window aspect ratio to 4:3 width = (height * 4) / 3; } else if( width <= 0 && height <= 0 ) { // Default window size width = 640; height = 480; } // Remember window settings _glfwWin.Width = width; _glfwWin.Height = height; _glfwWin.Fullscreen = (mode == GLFW_FULLSCREEN ? 1 : 0); _glfwWin.WindowNoResize = _glfwWinHints.WindowNoResize; // Platform specific window opening routine if( !_glfwPlatformOpenWindow( width, height, redbits, greenbits, bluebits, alphabits, depthbits, stencilbits, mode, AccumRedBits, AccumGreenBits, AccumBlueBits, AccumAlphaBits, AuxBuffers, Stereo, RefreshRate, Samples ) ) { return GL_FALSE; } // Flag that window is now opened _glfwWin.Opened = GL_TRUE; // Clear window hints _glfwWinHints.RefreshRate = 0; _glfwWinHints.AccumRedBits = 0; _glfwWinHints.AccumGreenBits = 0; _glfwWinHints.AccumBlueBits = 0; _glfwWinHints.AccumAlphaBits = 0; _glfwWinHints.AuxBuffers = 0; _glfwWinHints.Stereo = 0; _glfwWinHints.WindowNoResize = 0; _glfwWinHints.Samples = 0; // Get window parameters (such as color buffer bits etc) _glfwPlatformRefreshWindowParams(); // Get OpenGL version glfwGetGLVersion( &_glfwWin.GLVerMajor, &_glfwWin.GLVerMinor, &x ); // Do we have non-power-of-two textures? _glfwWin.Has_GL_ARB_texture_non_power_of_two = glfwExtensionSupported( "GL_ARB_texture_non_power_of_two" ); // Do we have automatic mipmap generation? _glfwWin.Has_GL_SGIS_generate_mipmap = (_glfwWin.GLVerMajor >= 2) || (_glfwWin.GLVerMinor >= 4) || glfwExtensionSupported( "GL_SGIS_generate_mipmap" ); // If full-screen mode was requested, disable mouse cursor if( mode == GLFW_FULLSCREEN ) { glfwDisable( GLFW_MOUSE_CURSOR ); } return GL_TRUE; }
GLFWAPI int GLFWAPIENTRY glfwOpenWindow( int width, int height, int redbits, int greenbits, int bluebits, int alphabits, int depthbits, int stencilbits, int mode ) { _GLFWfbconfig fbconfig; _GLFWwndconfig wndconfig; if( !_glfwInitialized || _glfwWin.opened ) { return GL_FALSE; } // Set up desired framebuffer config fbconfig.redBits = Max( redbits, 0 ); fbconfig.greenBits = Max( greenbits, 0 ); fbconfig.blueBits = Max( bluebits, 0 ); fbconfig.alphaBits = Max( alphabits, 0 ); fbconfig.depthBits = Max( depthbits, 0 ); fbconfig.stencilBits = Max( stencilbits, 0 ); fbconfig.accumRedBits = Max( _glfwLibrary.hints.accumRedBits, 0 ); fbconfig.accumGreenBits = Max( _glfwLibrary.hints.accumGreenBits, 0 ); fbconfig.accumBlueBits = Max( _glfwLibrary.hints.accumBlueBits, 0 ); fbconfig.accumAlphaBits = Max( _glfwLibrary.hints.accumAlphaBits, 0 ); fbconfig.auxBuffers = Max( _glfwLibrary.hints.auxBuffers, 0 ); fbconfig.stereo = _glfwLibrary.hints.stereo ? GL_TRUE : GL_FALSE; fbconfig.samples = Max( _glfwLibrary.hints.samples, 0 ); // Set up desired window config wndconfig.mode = mode; wndconfig.refreshRate = Max( _glfwLibrary.hints.refreshRate, 0 ); wndconfig.windowNoResize = _glfwLibrary.hints.windowNoResize ? GL_TRUE : GL_FALSE; wndconfig.glMajor = Max( _glfwLibrary.hints.glMajor, 1 ); wndconfig.glMinor = Max( _glfwLibrary.hints.glMinor, 0 ); wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE; wndconfig.glDebug = _glfwLibrary.hints.glDebug ? GL_TRUE : GL_FALSE; wndconfig.glProfile = _glfwLibrary.hints.glProfile; if( wndconfig.glMajor == 1 && wndconfig.glMinor > 5 ) { // OpenGL 1.x series ended with version 1.5 return GL_FALSE; } else if( wndconfig.glMajor == 2 && wndconfig.glMinor > 1 ) { // OpenGL 2.x series ended with version 2.1 return GL_FALSE; } else if( wndconfig.glMajor == 3 && wndconfig.glMinor > 3 ) { // OpenGL 3.x series ended with version 3.3 return GL_FALSE; } else { // For now, let everything else through } if( wndconfig.glProfile && ( wndconfig.glMajor < 3 || ( wndconfig.glMajor == 3 && wndconfig.glMinor < 2 ) ) ) { // Context profiles are only defined for OpenGL version 3.2 and above return GL_FALSE; } if( wndconfig.glForward && wndconfig.glMajor < 3 ) { // Forward-compatible contexts are only defined for OpenGL version 3.0 and above return GL_FALSE; } // Clear for next open call _glfwClearWindowHints(); // Check input arguments if( mode != GLFW_WINDOW && mode != GLFW_FULLSCREEN ) { return GL_FALSE; } // Clear GLFW window state _glfwWin.active = GL_TRUE; _glfwWin.iconified = GL_FALSE; _glfwWin.mouseLock = GL_FALSE; _glfwWin.autoPollEvents = GL_TRUE; _glfwClearInput(); // Unregister all callback functions _glfwWin.windowSizeCallback = NULL; _glfwWin.windowCloseCallback = NULL; _glfwWin.windowRefreshCallback = NULL; _glfwWin.keyCallback = NULL; _glfwWin.charCallback = NULL; _glfwWin.mousePosCallback = NULL; _glfwWin.mouseButtonCallback = NULL; _glfwWin.mouseWheelCallback = NULL; // Check width & height if( width > 0 && height <= 0 ) { // Set the window aspect ratio to 4:3 height = (width * 3) / 4; } else if( width <= 0 && height > 0 ) { // Set the window aspect ratio to 4:3 width = (height * 4) / 3; } else if( width <= 0 && height <= 0 ) { // Default window size width = 640; height = 480; } // Remember window settings _glfwWin.width = width; _glfwWin.height = height; _glfwWin.fullscreen = (mode == GLFW_FULLSCREEN ? GL_TRUE : GL_FALSE); // Platform specific window opening routine if( !_glfwPlatformOpenWindow( width, height, &wndconfig, &fbconfig ) ) { glfwCloseWindow(); return GL_FALSE; } // Flag that window is now opened _glfwWin.opened = GL_TRUE; // Read back window and context parameters _glfwPlatformRefreshWindowParams(); _glfwRefreshContextParams(); if( _glfwWin.glMajor < wndconfig.glMajor || ( _glfwWin.glMajor == wndconfig.glMajor && _glfwWin.glMinor < wndconfig.glMinor ) ) { glfwCloseWindow(); return GL_FALSE; } // Do we have non-power-of-two textures (added to core in version 2.0)? _glfwWin.has_GL_ARB_texture_non_power_of_two = ( _glfwWin.glMajor >= 2 ) || glfwExtensionSupported( "GL_ARB_texture_non_power_of_two" ); // Do we have automatic mipmap generation (added to core in version 1.4)? _glfwWin.has_GL_SGIS_generate_mipmap = ( _glfwWin.glMajor >= 2 ) || ( _glfwWin.glMinor >= 4 ) || glfwExtensionSupported( "GL_SGIS_generate_mipmap" ); if( _glfwWin.glMajor > 2 ) { _glfwWin.GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress( "glGetStringi" ); if( !_glfwWin.GetStringi ) { // This is a very common problem among people who compile GLFW // on X11/GLX using custom build systems, as the glfwGetProcAddress // code path selection needs explicit configuration // // See readme.html section 2.2 for details glfwCloseWindow(); return GL_FALSE; } } // If full-screen mode was requested, disable mouse cursor if( mode == GLFW_FULLSCREEN ) { glfwDisable( GLFW_MOUSE_CURSOR ); } // Start by clearing the front buffer to black (avoid ugly desktop // remains in our OpenGL window) glClear( GL_COLOR_BUFFER_BIT ); _glfwPlatformSwapBuffers(); return GL_TRUE; }