コード例 #1
0
static already_AddRefed<GLContextWGL>
CreateWindowOffscreenContext(const gfxIntSize& aSize,
                             const ContextFormat& aFormat)
{
    // CreateWindowOffscreenContext must return a global-shared context
    GLContextWGL *shareContext = GetGlobalContextWGL();
    if (!shareContext) {
        return nsnull;
    }
    
    HDC dc;
    HWND win = CreateDummyWindow(&dc);
    if (!win) {
        return nsnull;
    }
    
    HGLRC context = sWGLLibrary.fCreateContext(dc);
    if (!context) {
        return nsnull;
    }

    if (!sWGLLibrary.fShareLists(shareContext->Context(), context)) {
        NS_WARNING("wglShareLists failed!");

        sWGLLibrary.fDeleteContext(context);
        DestroyWindow(win);
        return nsnull;
    }

    nsRefPtr<GLContextWGL> glContext = new GLContextWGL(aFormat, shareContext,
                                                        dc, context, win, PR_TRUE);

    return glContext.forget();
}
コード例 #2
0
// Constractor
CvJoyMonitor::CvJoyMonitor(HINSTANCE hInstance, HWND	ParentWnd) :
    m_ParentWnd(ParentWnd), m_hInstance(hInstance),  m_nvJoyDevices(0), m_thCentral(NULL)
{
    if (!m_ParentWnd || !m_hInstance)
        return;

    // Initialize
    m_DeviceDB.clear();
    m_thCentral=NULL;
    m_hDummyWnd=NULL;
    m_Id.resize(16, -1);

    // // /// //// Test if DirectInput supported.
    // Register with the DirectInput subsystem and get a pointer
    // to a IDirectInput interface we can use.
    // Create a DInput object
    if( FAILED(DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, ( VOID** )&m_pDI, NULL ) ) )
    {
        m_pDI->Release();
        m_pDI = NULL;
        return;
    };

    // Create a dummy window
    m_hDummyWnd = CreateDummyWindow();

    // Create vector of all devices
    m_EnumerateCounter=1;
    // Create a Central vJoyMonitor thread
    // It constantly monitors the activity of vJoyMonitor object
    m_CentralKeepalive = true;
    m_thCentral = new thread(_CentralThread, this);
}
コード例 #3
0
ファイル: GraphicDevice.cpp プロジェクト: larrson/metashader
	//------------------------------------------------------------------------------------------
	bool CGraphicDevice::Initialize(int i_nWidth, int i_nHeight)
	{
		HRESULT hr = S_OK;

		// D3Dオブジェクトの作成
		m_pd3d9 = Direct3DCreate9(D3D_SDK_VERSION);
		if( !m_pd3d9 )
		{
			return false;
		}

		// ダミーウィンドウを作成
		if( CreateDummyWindow() == false )
		{
			return false;
		}

		// デバイスを作成
		if( CreateDevice(i_nWidth, i_nHeight) == false )
		{
			return false;
		}

		// レンダーターゲットの作成
		if( CreateRenderTarget(i_nWidth, i_nHeight) == false )
		{
			return false;
		}

		/// 全てに成功 ///

		m_nWidth = i_nWidth;
		m_nHeight = i_nHeight;

		// ビューポートの設定
		m_viewport.X = 0;
		m_viewport.Y = 0;
		m_viewport.Width = i_nWidth;
		m_viewport.Height = i_nHeight;		
		m_viewport.MinZ = 0.0f;
		m_viewport.MaxZ = 1.0f;

		// トランスフォームの初期化(単位行列化)
		for(int i = 0; i < TransformType_Max; ++i)
		{
			D3DXMatrixIdentity( &m_mTransform[i] );
		}

		// シェーダ管理の初期化
		shader::CShaderMan::CreateInstance();
		shader::CShaderMan::GetInstance()->Initialize();

		m_bValid = true;

		return true;
	}
コード例 #4
0
static already_AddRefed<GLContextWGL>
CreateWindowOffscreenContext(const ContextFormat& aFormat)
{
    // CreateWindowOffscreenContext must return a global-shared context
    GLContextWGL *shareContext = GetGlobalContextWGL();
    if (!shareContext) {
        return nsnull;
    }
    
    HDC dc;
    HWND win = CreateDummyWindow(&dc);
    if (!win) {
        return nsnull;
    }
    
    HGLRC context = sWGLLibrary.fCreateContext(dc);
    if (sWGLLibrary.HasRobustness()) {
        int attribs[] = {
            LOCAL_WGL_CONTEXT_FLAGS_ARB, LOCAL_WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB,
            LOCAL_WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_WGL_LOSE_CONTEXT_ON_RESET_ARB,
            NULL
        };

        context = sWGLLibrary.fCreateContextAttribs(dc, shareContext->Context(), attribs);
    } else {
        context = sWGLLibrary.fCreateContext(dc);
        if (context && shareContext &&
            !sWGLLibrary.fShareLists(shareContext->Context(), context))
        {
            NS_WARNING("wglShareLists failed!");

            sWGLLibrary.fDeleteContext(context);
            DestroyWindow(win);
            return nsnull;
        }
    }

    if (!context) {
        return nsnull;
    }

    nsRefPtr<GLContextWGL> glContext = new GLContextWGL(aFormat, shareContext,
                                                        dc, context, win, true);

    return glContext.forget();
}
コード例 #5
0
ファイル: softmode.c プロジェクト: Azarien/open-watcom-v2
static void GrabThreadQueue( PID pid, TID tid )
{
    thread_data         thread;
    int                 i;

    if( HwndDummy == NULLHANDLE )
        CreateDummyWindow();
    thread.hmq = WinQueueFromID( HabDebugger, pid, tid );
    if( thread.hmq == NULLHANDLE )
        return;
    for( i = 0; i < NumAssumedQueues; ++i ) {
        if( thread.hmq == AssumedQueues[i] )
            return;
    }
    AssumedQueues[NumAssumedQueues] = thread.hmq;
    ++NumAssumedQueues;
    BeginSoftModeThread( &thread );
}
コード例 #6
0
bool
WGLLibrary::EnsureInitialized(bool aUseMesaLlvmPipe)
{
    if (mInitialized)
        return true;
    
    mozilla::ScopedGfxFeatureReporter reporter("WGL", aUseMesaLlvmPipe);

    const char* libGLFilename = aUseMesaLlvmPipe 
                                ? "mesallvmpipe.dll" 
                                : "Opengl32.dll";
    if (!mOGLLibrary) {
        mOGLLibrary = PR_LoadLibrary(libGLFilename);
        if (!mOGLLibrary) {
            NS_WARNING("Couldn't load OpenGL library.");
            return false;
        }
    }

    mUseDoubleBufferedWindows = PR_GetEnv("MOZ_WGL_DB") != nullptr;

    GLLibraryLoader::SymLoadStruct earlySymbols[] = {
        { (PRFuncPtr*) &fCreateContext, { "wglCreateContext", NULL } },
        { (PRFuncPtr*) &fMakeCurrent, { "wglMakeCurrent", NULL } },
        { (PRFuncPtr*) &fGetProcAddress, { "wglGetProcAddress", NULL } },
        { (PRFuncPtr*) &fDeleteContext, { "wglDeleteContext", NULL } },
        { (PRFuncPtr*) &fGetCurrentContext, { "wglGetCurrentContext", NULL } },
        { (PRFuncPtr*) &fGetCurrentDC, { "wglGetCurrentDC", NULL } },
        { (PRFuncPtr*) &fShareLists, { "wglShareLists", NULL } },
        { NULL, { NULL } }
    };

    if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &earlySymbols[0])) {
        NS_WARNING("Couldn't find required entry points in OpenGL DLL (early init)");
        return false;
    }

    // This is ridiculous -- we have to actually create a context to
    // get the OpenGL ICD to load.
    mWindow = CreateDummyWindow(&mWindowDC);
    NS_ENSURE_TRUE(mWindow, false);

    // create rendering context
    mWindowGLContext = fCreateContext(mWindowDC);
    NS_ENSURE_TRUE(mWindowGLContext, false);

    HGLRC curCtx = fGetCurrentContext();
    HDC curDC = fGetCurrentDC();

    if (!fMakeCurrent((HDC)mWindowDC, (HGLRC)mWindowGLContext)) {
        NS_WARNING("wglMakeCurrent failed");
        return false;
    }

    // Now we can grab all the other symbols that we couldn't without having
    // a context current.

    GLLibraryLoader::SymLoadStruct pbufferSymbols[] = {
        { (PRFuncPtr*) &fCreatePbuffer, { "wglCreatePbufferARB", "wglCreatePbufferEXT", NULL } },
        { (PRFuncPtr*) &fDestroyPbuffer, { "wglDestroyPbufferARB", "wglDestroyPbufferEXT", NULL } },
        { (PRFuncPtr*) &fGetPbufferDC, { "wglGetPbufferDCARB", "wglGetPbufferDCEXT", NULL } },
        { (PRFuncPtr*) &fBindTexImage, { "wglBindTexImageARB", "wglBindTexImageEXT", NULL } },
        { (PRFuncPtr*) &fReleaseTexImage, { "wglReleaseTexImageARB", "wglReleaseTexImageEXT", NULL } },
        { NULL, { NULL } }
    };

    GLLibraryLoader::SymLoadStruct pixFmtSymbols[] = {
        { (PRFuncPtr*) &fChoosePixelFormat, { "wglChoosePixelFormatARB", "wglChoosePixelFormatEXT", NULL } },
        { (PRFuncPtr*) &fGetPixelFormatAttribiv, { "wglGetPixelFormatAttribivARB", "wglGetPixelFormatAttribivEXT", NULL } },
        { NULL, { NULL } }
    };

    if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &pbufferSymbols[0],
         (GLLibraryLoader::PlatformLookupFunction)fGetProcAddress))
    {
        // this isn't an error, just means that pbuffers aren't supported
        fCreatePbuffer = nullptr;
    }

    if (!GLLibraryLoader::LoadSymbols(mOGLLibrary, &pixFmtSymbols[0],
         (GLLibraryLoader::PlatformLookupFunction)fGetProcAddress))
    {
        // this isn't an error, just means that we don't have the pixel format extension
        fChoosePixelFormat = nullptr;
    }

    GLLibraryLoader::SymLoadStruct extensionsSymbols[] = {
        { (PRFuncPtr *) &fGetExtensionsString, { "wglGetExtensionsStringARB", NULL} },
        { NULL, { NULL } }
    };

    GLLibraryLoader::SymLoadStruct robustnessSymbols[] = {
        { (PRFuncPtr *) &fCreateContextAttribs, { "wglCreateContextAttribsARB", NULL} },
        { NULL, { NULL } }
    };

    if (GLLibraryLoader::LoadSymbols(mOGLLibrary, &extensionsSymbols[0],
        (GLLibraryLoader::PlatformLookupFunction)fGetProcAddress)) {
        const char *wglExts = fGetExtensionsString(mWindowDC);
        if (wglExts && HasExtension(wglExts, "WGL_ARB_create_context")) {
            GLLibraryLoader::LoadSymbols(mOGLLibrary, &robustnessSymbols[0],
            (GLLibraryLoader::PlatformLookupFunction)fGetProcAddress);
            if (HasExtension(wglExts, "WGL_ARB_create_context_robustness")) {
                mHasRobustness = true;
            }
        }
    }

    // reset back to the previous context, just in case
    fMakeCurrent(curDC, curCtx);

    if (mHasRobustness) {
        fDeleteContext(mWindowGLContext);

        int attribs[] = {
            LOCAL_WGL_CONTEXT_FLAGS_ARB, LOCAL_WGL_CONTEXT_ROBUST_ACCESS_BIT_ARB,
            LOCAL_WGL_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, LOCAL_WGL_LOSE_CONTEXT_ON_RESET_ARB,
            0
        };

        mWindowGLContext = fCreateContextAttribs(mWindowDC, NULL, attribs);
        if (!mWindowGLContext) {
            mHasRobustness = false;
            mWindowGLContext = fCreateContext(mWindowDC);
        }
    }

    mInitialized = true;

    GLContext::ContextFlags flag = GLContext::ContextFlagsNone;
    if (aUseMesaLlvmPipe) {
      mLibType = WGLLibrary::MESA_LLVMPIPE_LIB;
      flag = GLContext::ContextFlagsMesaLLVMPipe;
    }

    // Call this to create the global GLContext instance,
    // and to check for errors.  Note that this must happen /after/
    // setting mInitialized to TRUE, or an infinite loop results.
    if (GLContextProviderWGL::GetGlobalContext(flag) == nullptr) {
        mInitialized = false;
        return false;
    }

    reporter.SetSuccessful();
    return true;
}
コード例 #7
0
PRBool
WGLLibrary::EnsureInitialized()
{
    if (mInitialized)
        return PR_TRUE;

    if (!mOGLLibrary) {
        mOGLLibrary = PR_LoadLibrary("Opengl32.dll");
        if (!mOGLLibrary) {
            NS_WARNING("Couldn't load OpenGL DLL.");
            return PR_FALSE;
        }
    }

    LibrarySymbolLoader::SymLoadStruct earlySymbols[] = {
        { (PRFuncPtr*) &fCreateContext, { "wglCreateContext", NULL } },
        { (PRFuncPtr*) &fMakeCurrent, { "wglMakeCurrent", NULL } },
        { (PRFuncPtr*) &fGetProcAddress, { "wglGetProcAddress", NULL } },
        { (PRFuncPtr*) &fDeleteContext, { "wglDeleteContext", NULL } },
        { (PRFuncPtr*) &fGetCurrentContext, { "wglGetCurrentContext", NULL } },
        { (PRFuncPtr*) &fGetCurrentDC, { "wglGetCurrentDC", NULL } },
        { (PRFuncPtr*) &fShareLists, { "wglShareLists", NULL } },
        { NULL, { NULL } }
    };

    if (!LibrarySymbolLoader::LoadSymbols(mOGLLibrary, &earlySymbols[0])) {
        NS_WARNING("Couldn't find required entry points in OpenGL DLL (early init)");
        return PR_FALSE;
    }

    // This is ridiculous -- we have to actually create a context to
    // get the OpenGL ICD to load.
    gSharedWindow = CreateDummyWindow(&gSharedWindowDC);
    NS_ENSURE_TRUE(gSharedWindow, PR_FALSE);

    // create rendering context
    gSharedWindowGLContext = fCreateContext(gSharedWindowDC);
    NS_ENSURE_TRUE(gSharedWindowGLContext, PR_FALSE);

    HGLRC curCtx = fGetCurrentContext();
    HDC curDC = fGetCurrentDC();

    if (!fMakeCurrent((HDC)gSharedWindowDC, (HGLRC)gSharedWindowGLContext)) {
        NS_WARNING("wglMakeCurrent failed");
        return PR_FALSE;
    }

    // Now we can grab all the other symbols that we couldn't without having
    // a context current.

    LibrarySymbolLoader::SymLoadStruct pbufferSymbols[] = {
        { (PRFuncPtr*) &fCreatePbuffer, { "wglCreatePbufferARB", "wglCreatePbufferEXT", NULL } },
        { (PRFuncPtr*) &fDestroyPbuffer, { "wglDestroyPbufferARB", "wglDestroyPbufferEXT", NULL } },
        { (PRFuncPtr*) &fGetPbufferDC, { "wglGetPbufferDCARB", "wglGetPbufferDCEXT", NULL } },
        { (PRFuncPtr*) &fBindTexImage, { "wglBindTexImageARB", "wglBindTexImageEXT", NULL } },
        { (PRFuncPtr*) &fReleaseTexImage, { "wglReleaseTexImageARB", "wglReleaseTexImageEXT", NULL } },
        { NULL, { NULL } }
    };

    LibrarySymbolLoader::SymLoadStruct pixFmtSymbols[] = {
        { (PRFuncPtr*) &fChoosePixelFormat, { "wglChoosePixelFormatARB", "wglChoosePixelFormatEXT", NULL } },
        { (PRFuncPtr*) &fGetPixelFormatAttribiv, { "wglGetPixelFormatAttribivARB", "wglGetPixelFormatAttribivEXT", NULL } },
        { NULL, { NULL } }
    };

    if (!LibrarySymbolLoader::LoadSymbols(mOGLLibrary, &pbufferSymbols[0],
         (LibrarySymbolLoader::PlatformLookupFunction)fGetProcAddress))
    {
        // this isn't an error, just means that pbuffers aren't supported
        fCreatePbuffer = nsnull;
    }

    if (!LibrarySymbolLoader::LoadSymbols(mOGLLibrary, &pixFmtSymbols[0],
         (LibrarySymbolLoader::PlatformLookupFunction)fGetProcAddress))
    {
        // this isn't an error, just means that we don't have the pixel format extension
        fChoosePixelFormat = nsnull;
    }

    // reset back to the previous context, just in case
    fMakeCurrent(curDC, curCtx);

    mInitialized = PR_TRUE;

    // Call this to create the global GLContext instance,
    // and to check for errors.  Note that this must happen /after/
    // setting mInitialized to TRUE, or an infinite loop results.
    if (GLContextProviderWGL::GetGlobalContext() == nsnull) {
        mInitialized = PR_FALSE;
        return PR_FALSE;
    }

    return PR_TRUE;
}
コード例 #8
0
ファイル: GraphicsCaptureHook.cpp プロジェクト: Andypro1/OBS
static DWORD WINAPI DummyWindowThread(LPVOID lpBla)
{
    WNDCLASS wc;
    ZeroMemory(&wc, sizeof(wc));
    wc.style = CS_OWNDC;
    wc.hInstance = hinstMain;
    wc.lpfnWndProc = (WNDPROC)DefWindowProc;

    wc.lpszClassName = TEXT("OBSOGLHookClass");
    if (RegisterClass(&wc)) {
        hwndOpenGLSetupWindow = CreateDummyWindow(
            TEXT("OBSOGLHookClass"),
            TEXT("OBS OpenGL Context Window")
            );

        if (!hwndOpenGLSetupWindow) {
            logOutput << CurrentDateTimeString() << "could not create gl dummy window" << endl;
            return 0;
        }
    } else {
        logOutput << CurrentDateTimeString() << "could not create gl dummy window class" << endl;
        return 0;
    }

    wc.lpszClassName = TEXT("OBSDummyD3D9WndClassForTheGPUHook");
    if (RegisterClass(&wc)) {
        hwndD3DDummyWindow = CreateDummyWindow(
            TEXT("OBSDummyD3D9WndClassForTheGPUHook"),
            TEXT("OBS OpenGL D3D Temp Device Window")
            );

        if (!hwndD3DDummyWindow) {
            logOutput << CurrentDateTimeString() << "could not create gl d3d interop dummy window" << endl;
            return 0;
        }
    } else {
        logOutput << CurrentDateTimeString() << "could not create gl d3d interop dummy window class" << endl;
        return 0;
    }

    wc.lpszClassName = SENDER_WINDOWCLASS;
    if (RegisterClass(&wc)) {
        hwndSender = CreateDummyWindow(
            SENDER_WINDOWCLASS,
            NULL
            );

        if (!hwndSender) {
            logOutput << CurrentDateTimeString() << "could not create sender window" << endl;
            return 0;
        }
    } else {
        logOutput << CurrentDateTimeString() << "could not create sender window class" << endl;
        return 0;
    }

    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return 0;
}
コード例 #9
0
CPUTResult CPUT_OGL::CreateOGLContext(CPUTContextCreation ContextParams )
{
	HWND hWnd;

	hWnd = CreateDummyWindow( GetModuleHandle(NULL));
    // Create dummy window to gather information about OpenGL
    if ( ! hWnd) 
    {
        return CPUT_ERROR;
    }

    // To get list of supported extensions, this 
    // code should be used since OpenGL 3.0 Core:
    //
    // uint32 count = 0;
    // glGetIntegerv(GL_NUM_EXTENSIONS, (GLint*)&count);
    // for(uint16 i=0; i<count; i++)
    //    support.m_extensions.insert(support.m_extensions.end(),string((char*)glGetStringi(GL_EXTENSIONS,i));
    //
    // But data about gpu, are gathered in dummy
    // OpenGL context which works in deprecaded
    // mode. This forces implementation in old
    // deprecated way:
    
    // Creates table of supported extensions strings
    extensions.clear();
    string tmp;
    sint32 begin, end;
    tmp   = string( (char*)glGetString( GL_EXTENSIONS ) );
    begin = 0;
    end   = tmp.find( ' ', 0 );
    while( end != string::npos )
    {
        extensions.insert( extensions.end(), tmp.substr( begin, end-begin ) );
        begin = end + 1;
        end   = tmp.find( ' ', begin );
    }
    
    // This extension together with WGL_EXT_swap_interval
    // should be returned in list of supported extensions
    // after calling glGetString(GL_EXTENSIONS);
    // Because NVidia drivers don't follow this rule it's
    // specification says as follow:
    // 
    // "Applications should call wglGetProcAddress to see 
    // whether or not wglGetExtensionsStringARB is supported."
    // ( http://www.opengl.org/registry/specs/ARB/wgl_extensions_string.txt )
    //
    bool wglexts = false;
    wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress( "wglGetExtensionsStringARB" );  
    if ( wglGetExtensionsStringARB != NULL )
    {
        tmp = string( (char*)wglGetExtensionsStringARB( mhDC ) );
        wglexts = true;
    }
    else
    {
        wglGetExtensionsStringEXT = (PFNWGLGETEXTENSIONSSTRINGEXTPROC) wglGetProcAddress( "wglGetExtensionsStringEXT" );
        if ( wglGetExtensionsStringEXT != NULL )
        {
            tmp = string( (char*)wglGetExtensionsStringEXT() ); 
            wglexts = true; 
        }
    }

    // If it is possible to obtain WGL extensions list add
    // them to the rest of supported extensions.
    if ( wglexts )
    {
        begin = 0;
        end   = tmp.find( ' ', 0 );
        while( end != string::npos )
        {
            extensions.insert( extensions.end(), tmp.substr( begin, end-begin ) );
            begin = end + 1;
            end   = tmp.find( ' ', begin );
        }
	}

	// Get pointers to WGL specific functions that are required during window creation
    wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" );
    wglChoosePixelFormatARB    = (PFNWGLCHOOSEPIXELFORMATARBPROC)    wglGetProcAddress( "wglChoosePixelFormatARB" );
    wglChoosePixelFormatEXT    = (PFNWGLCHOOSEPIXELFORMATEXTPROC)    wglGetProcAddress( "wglChoosePixelFormatEXT" );
 
	// Set Samples count in Advanced Pixel Format
	iAttributes[27] = ContextParams.samples;

    // Choosing advanced Pixel Format in modern way 
    uint32 PixelFormat = 0;
    bool choosedPixelFormat = false;   
    if ( supportExtension( "WGL_ARB_pixel_format" ) )
    {
        uint32 numFormats;
        if ( wglChoosePixelFormatARB( mhDC, (const int*)iAttributes, fAttributes, 1, (int*)&PixelFormat, (unsigned int*)&numFormats ) )
            if ( numFormats >= 1 )
                choosedPixelFormat = true;
    }
    
    // Old way for choosing advanced Pixel Format
    if ( !choosedPixelFormat &&
         supportExtension( "WGL_EXT_pixel_format" ) )
    {
        uint32 numFormats;
        if ( wglChoosePixelFormatEXT( mhDC, (const int*)iAttributes, fAttributes, 1, (int*)&PixelFormat, (unsigned int*)&numFormats ) )
            if ( numFormats >= 1 )
                choosedPixelFormat = true;
    }

    // Basic Pixel Format
    if ( !choosedPixelFormat )
        PixelFormat = ChoosePixelFormat( mhDC, &pfdLegacy );

    // If couldn't find Pixel Format report error
    if ( PixelFormat == NULL )
    {
        cerr << "Error! Cannot find aproprieate pixel format." << endl;	
        DestroyOGLContext();	
        return CPUT_ERROR;
    } 


   // Data about OpenGL are gathered, proper Pixel Format is choosed.
    // Destroy Dummy Window and proceed to creation of proper window.
    // Disabling and deleting all rendering contexts
    wglMakeCurrent( NULL, NULL ); 
    wglDeleteContext( mhRC );
    mhRC = NULL;
    // Disabling device context
    ReleaseDC( hWnd, mhDC ); 
    mhDC = 0;
   
	// Deleting window
    DestroyWindow( hWnd );  

    // Unregistering window class
    if(TRUE != UnregisterClass( L"DummyWindowClass", GetModuleHandle(NULL) ))
	{
		return CPUT_ERROR;
	}

    // Clear message queue
    MSG msg = { 0 };
    while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );

    }

	hWnd = mpWindow->GetHWnd();

   

    // Acquiring Device Context
    mhDC = GetDC( hWnd );
    if ( mhDC == NULL )
    {
        cerr << "Error! Cannot create device context." << endl;		
        DestroyOGLContext();	
        return CPUT_ERROR;
    }  

    // Activating Pixel Format
    if ( !SetPixelFormat( mhDC, PixelFormat, &pfdLegacy ) )
    {	
        cerr << "Error! Cannot init pixel format." << endl;
        DestroyOGLContext();	
        return CPUT_ERROR;
	} 

    // OpenGL 4.0 Core profile settings
    uint32 glAttributes[] = { WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
                              WGL_CONTEXT_MINOR_VERSION_ARB, 0,
                              WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
                              GL_CONTEXT_PROFILE_MASK, GL_CONTEXT_CORE_PROFILE_BIT,
                              0, 0 };
   //         GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
     //   GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
    // Debug version supports better debugging
#ifdef _DEBUG
    glAttributes[5] |= WGL_CONTEXT_DEBUG_BIT_ARB;
#endif 

    // Try to create OpenGL context in new way
    mhRC = wglCreateContextAttribsARB( mhDC, 0, (const int *) &glAttributes );
    if ( mhRC == NULL )
    {
        cerr << "Error! Cannot create window rendering context." << endl;
        DestroyOGLContext();				
        return CPUT_ERROR;
    }  

    // Activating rendering context
    if( !wglMakeCurrent( mhDC, mhRC ) )
    {	
        std::cerr << "Error! Cannot activate rendering context." << endl;
        DestroyOGLContext();	
        return CPUT_ERROR;
    } 
    
    
    // Setting created window as current 
    ShowWindow( hWnd, SW_SHOW );
    SetForegroundWindow( hWnd );
    SetFocus( hWnd );
    
    // Link all OpenGL function pointers
    glewExperimental = TRUE;
    if ( glewInit() != GLEW_OK )
    {
        cerr << "Error! Cannot activate GLEW." << endl;
        DestroyOGLContext();	
        return CPUT_ERROR;
    }

    // GLEW's problem is that it calls glGetString(GL_EXTENSIONS) which causes 
    // GL_INVALID_ENUM on GL 3.2 core context as soon as glewInit() is called.
    // Clear errors indicator 
    glGetError();
    
    wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) wglGetProcAddress( "wglSwapIntervalEXT" );
    wglSwapIntervalEXT(0);

    return CPUT_SUCCESS;
}