Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2012
62
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GLFWAPI int GLFWAPIENTRY glfwOpenWindow( int width, int height,
  2. int redbits, int greenbits, int bluebits, int alphabits,
  3. int depthbits, int stencilbits, int mode )
  4. {
  5. _GLFWfbconfig fbconfig;
  6. _GLFWwndconfig wndconfig;
  7.  
  8. if( !_glfwInitialized || _glfwWin.opened )
  9. {
  10. return GL_FALSE;
  11. }
  12.  
  13. // Set up desired framebuffer config
  14. fbconfig.redBits = Max( redbits, 0 );
  15. fbconfig.greenBits = Max( greenbits, 0 );
  16. fbconfig.blueBits = Max( bluebits, 0 );
  17. fbconfig.alphaBits = Max( alphabits, 0 );
  18. fbconfig.depthBits = Max( depthbits, 0 );
  19. fbconfig.stencilBits = Max( stencilbits, 0 );
  20. fbconfig.accumRedBits = Max( _glfwLibrary.hints.accumRedBits, 0 );
  21. fbconfig.accumGreenBits = Max( _glfwLibrary.hints.accumGreenBits, 0 );
  22. fbconfig.accumBlueBits = Max( _glfwLibrary.hints.accumBlueBits, 0 );
  23. fbconfig.accumAlphaBits = Max( _glfwLibrary.hints.accumAlphaBits, 0 );
  24. fbconfig.auxBuffers = Max( _glfwLibrary.hints.auxBuffers, 0 );
  25. fbconfig.stereo = _glfwLibrary.hints.stereo ? GL_TRUE : GL_FALSE;
  26. fbconfig.samples = Max( _glfwLibrary.hints.samples, 0 );
  27.  
  28. // Set up desired window config
  29. wndconfig.mode = mode;
  30. wndconfig.refreshRate = Max( _glfwLibrary.hints.refreshRate, 0 );
  31. wndconfig.windowNoResize = _glfwLibrary.hints.windowNoResize ? GL_TRUE : GL_FALSE;
  32. wndconfig.glMajor = Max( _glfwLibrary.hints.glMajor, 1 );
  33. wndconfig.glMinor = Max( _glfwLibrary.hints.glMinor, 0 );
  34. wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE;
  35. wndconfig.glDebug = _glfwLibrary.hints.glDebug ? GL_TRUE : GL_FALSE;
  36. wndconfig.glProfile = _glfwLibrary.hints.glProfile;
  37.  
  38. if( wndconfig.glMajor == 1 && wndconfig.glMinor > 5 )
  39. {
  40. // OpenGL 1.x series ended with version 1.5
  41. return GL_FALSE;
  42. }
  43. else if( wndconfig.glMajor == 2 && wndconfig.glMinor > 1 )
  44. {
  45. // OpenGL 2.x series ended with version 2.1
  46. return GL_FALSE;
  47. }
  48. else if( wndconfig.glMajor == 3 && wndconfig.glMinor > 3 )
  49. {
  50. // OpenGL 3.x series ended with version 3.3
  51. return GL_FALSE;
  52. }
  53. else
  54. {
  55. // For now, let everything else through
  56. }
  57.  
  58. if( wndconfig.glProfile &&
  59. ( wndconfig.glMajor < 3 || ( wndconfig.glMajor == 3 && wndconfig.glMinor < 2 ) ) )
  60. {
  61. // Context profiles are only defined for OpenGL version 3.2 and above
  62. return GL_FALSE;
  63. }
  64.  
  65. if( wndconfig.glForward && wndconfig.glMajor < 3 )
  66. {
  67. // Forward-compatible contexts are only defined for OpenGL version 3.0 and above
  68. return GL_FALSE;
  69. }
  70.  
  71. // Clear for next open call
  72. _glfwClearWindowHints();
  73.  
  74. // Check input arguments
  75. if( mode != GLFW_WINDOW && mode != GLFW_FULLSCREEN )
  76. {
  77. return GL_FALSE;
  78. }
  79.  
  80. // Clear GLFW window state
  81. _glfwWin.active = GL_TRUE;
  82. _glfwWin.iconified = GL_FALSE;
  83. _glfwWin.mouseLock = GL_FALSE;
  84. _glfwWin.autoPollEvents = GL_TRUE;
  85. _glfwClearInput();
  86.  
  87. // Unregister all callback functions
  88. _glfwWin.windowSizeCallback = NULL;
  89. _glfwWin.windowCloseCallback = NULL;
  90. _glfwWin.windowRefreshCallback = NULL;
  91. _glfwWin.keyCallback = NULL;
  92. _glfwWin.charCallback = NULL;
  93. _glfwWin.mousePosCallback = NULL;
  94. _glfwWin.mouseButtonCallback = NULL;
  95. _glfwWin.mouseWheelCallback = NULL;
  96.  
  97. // Check width & height
  98. if( width > 0 && height <= 0 )
  99. {
  100. // Set the window aspect ratio to 4:3
  101. height = (width * 3) / 4;
  102. }
  103. else if( width <= 0 && height > 0 )
  104. {
  105. // Set the window aspect ratio to 4:3
  106. width = (height * 4) / 3;
  107. }
  108. else if( width <= 0 && height <= 0 )
  109. {
  110. // Default window size
  111. width = 640;
  112. height = 480;
  113. }
  114.  
  115. // Remember window settings
  116. _glfwWin.width = width;
  117. _glfwWin.height = height;
  118. _glfwWin.fullscreen = (mode == GLFW_FULLSCREEN ? GL_TRUE : GL_FALSE);
  119.  
  120. // Platform specific window opening routine
  121. if( !_glfwPlatformOpenWindow( width, height, &wndconfig, &fbconfig ) )
  122. {
  123. glfwCloseWindow();
  124. return GL_FALSE;
  125. }
  126.  
  127. // Flag that window is now opened
  128. _glfwWin.opened = GL_TRUE;
  129.  
  130. // Read back window and context parameters
  131. _glfwPlatformRefreshWindowParams();
  132. _glfwRefreshContextParams();
  133.  
  134. if( _glfwWin.glMajor < wndconfig.glMajor ||
  135. ( _glfwWin.glMajor == wndconfig.glMajor &&
  136. _glfwWin.glMinor < wndconfig.glMinor ) )
  137. {
  138. glfwCloseWindow();
  139. return GL_FALSE;
  140. }
  141.  
  142. // Do we have non-power-of-two textures (added to core in version 2.0)?
  143. _glfwWin.has_GL_ARB_texture_non_power_of_two =
  144. ( _glfwWin.glMajor >= 2 ) ||
  145. glfwExtensionSupported( "GL_ARB_texture_non_power_of_two" );
  146.  
  147. // Do we have automatic mipmap generation (added to core in version 1.4)?
  148. _glfwWin.has_GL_SGIS_generate_mipmap =
  149. ( _glfwWin.glMajor >= 2 ) || ( _glfwWin.glMinor >= 4 ) ||
  150. glfwExtensionSupported( "GL_SGIS_generate_mipmap" );
  151.  
  152. if( _glfwWin.glMajor > 2 )
  153. {
  154. _glfwWin.GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress( "glGetStringi" );
  155. if( !_glfwWin.GetStringi )
  156. {
  157. // This is a very common problem among people who compile GLFW
  158. // on X11/GLX using custom build systems, as the glfwGetProcAddress
  159. // code path selection needs explicit configuration
  160. //
  161. // See readme.html section 2.2 for details
  162.  
  163. glfwCloseWindow();
  164. return GL_FALSE;
  165. }
  166. }
  167.  
  168. // If full-screen mode was requested, disable mouse cursor
  169. if( mode == GLFW_FULLSCREEN )
  170. {
  171. glfwDisable( GLFW_MOUSE_CURSOR );
  172. }
  173.  
  174. // Start by clearing the front buffer to black (avoid ugly desktop
  175. // remains in our OpenGL window)
  176. glClear( GL_COLOR_BUFFER_BIT );
  177. _glfwPlatformSwapBuffers();
  178.  
  179. return GL_TRUE;
  180. }
Advertisement
RAW Paste Data Copied
Advertisement