static bool ReadInitExtensions() { HDC hDC; HGLRC hRC; HWND dummy; PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, // color depth 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, // z depth 0, // stencil buffer 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; int pixelFormat; // we have to create a dummy window to init stuff from or the full init stuff fails dummy = InitDummy(); hDC = GetDC(dummy); pixelFormat = ChoosePixelFormat(hDC, &pfd); DescribePixelFormat(hDC, pixelFormat, sizeof(pfd), &pfd); SetPixelFormat(hDC, pixelFormat, &pfd); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB"); // any extra stuff here? wglMakeCurrent(NULL, NULL); wglDeleteContext(hRC); ReleaseDC(dummy, hDC); ShutdownDummy(dummy); return true; }
bool WINDOW::Init( char * windowTitle, int newWidth, int newHeight, int newRedBits, int newGreenBits, int newBlueBits, int newAlphaBits, int newDepthBits, int newStencilBits, bool newFullscreen, bool newVSync, bool dialogBox) { //Set member variables title=windowTitle; width=newWidth; height=newHeight; redBits=newRedBits; greenBits=newGreenBits; blueBits=newBlueBits; alphaBits=newAlphaBits; depthBits=newDepthBits; stencilBits=newStencilBits; fullscreen=newFullscreen; vSync=newVSync; LOG::Instance()->OutputSuccess("Creating temporary window"); LOG::Instance()->OutputNewLine(); //Init dummy window to get extension pointers if(!InitDummy()) return false; LOG::Instance()->OutputNewLine(); bool revertToStandard=false; //Initiate the WGL extensions. If not supported, use the standard window if( !SetUpWGL_ARB_extensions_string()) revertToStandard=true; //If ARB_extensions_string is supported, if(!revertToStandard) { //Get the WGL extensions string const char * wglExtensions; wglExtensions=wglGetExtensionsStringARB(hDC); //If the necessary extensions are not supported, use the standard window if( !SetUpWGL_ARB_pixel_format(wglExtensions) || !SetUpWGL_EXT_swap_control(wglExtensions)) revertToStandard=true; //Also initialise ARB_multisample SetUpWGL_ARB_multisample(wglExtensions); } //If we need to revert to standard, shut down the dummy window, Create standard window //and return if(revertToStandard) { LOG::Instance()->OutputNewLine(); LOG::Instance()->OutputSuccess("Destroying temporary window"); ShutdownDummy(); LOG::Instance()->OutputNewLine(); LOG::Instance()->OutputSuccess("Replacing with standard, non WGL_extension window"); LOG::Instance()->OutputNewLine(); InitStandard(); return true; } //If we have reached here, the ARB extensions are supported. //Shutdown this window and create a window using ARB_pixel_format etc //Find supported AA samples with given color bits, if ARB_multisample is supported for(int i=0; i<17; ++i) samplesSupported[i]=false; if(WGL_ARB_multisample_supported) { FindSamplesSupported(); } else { samplesSupported[0]=true; } //Destroy temporary window LOG::Instance()->OutputNewLine(); LOG::Instance()->OutputSuccess("Destroying temporary window"); ShutdownDummy(); //Creat WGL extension window LOG::Instance()->OutputNewLine(); LOG::Instance()->OutputSuccess("Replacing with WGL_extension window"); LOG::Instance()->OutputNewLine(); if(InitExtended(dialogBox)) return true; //If we reached here, InitExtended failed. //Try a standard window as a last resort //Destroy extended window LOG::Instance()->OutputNewLine(); LOG::Instance()->OutputSuccess("Extended window creation failed - Destroying"); ShutdownDummy(); //Use ShutdownDummy as we have not hidden the cursor yet. //So, we do not want the call to show it //Create standard window LOG::Instance()->OutputNewLine(); LOG::Instance()->OutputSuccess("Replacing with standard window"); LOG::Instance()->OutputNewLine(); if(InitStandard()) return true; //All window creation attempts failed LOG::Instance()->OutputNewLine(); LOG::Instance()->OutputError("All window Creation attempts failed!"); Shutdown(); return false; }