コード例 #1
0
	bool Device::Create(void)
	{
		PIXELFORMATDESCRIPTOR pixelFormatDesc;
		ZeroMemory(&pixelFormatDesc, sizeof PIXELFORMATDESCRIPTOR);

		pixelFormatDesc.nSize = sizeof PIXELFORMATDESCRIPTOR; // Size of this pixel format descriptor.
		pixelFormatDesc.nVersion = 1; // Version number.
		pixelFormatDesc.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
		pixelFormatDesc.iPixelType = PFD_TYPE_RGBA; // Request an RGBA format.
		pixelFormatDesc.cColorBits = 24;
		pixelFormatDesc.cDepthBits = 16;
		pixelFormatDesc.iLayerType = PFD_MAIN_PLANE; // Main drawing layer.

		_deviceContext = GetDC(_windowHandle);

		int pixelFormatIdx = ChoosePixelFormat(_deviceContext, &pixelFormatDesc);
		if (pixelFormatIdx == 0)
		{
			ReleaseDC(_windowHandle, _deviceContext);
			return false;
		}

		if (SetPixelFormat(_deviceContext, pixelFormatIdx, &pixelFormatDesc))
		{
			_renderContext = wglCreateContext(_deviceContext);
			if (_renderContext)
				MakeCurrentContext();
			else
			{
				ReleaseDC(_windowHandle, _deviceContext);
				wglDeleteContext(_renderContext);
				return false;
			}
		}
		else
		{
			ReleaseDC(_windowHandle, _deviceContext);
			return false;
		}

		_version = (const char*)glGetString(GL_VERSION);
		_vendorName = (const char*)glGetString(GL_VENDOR);
		_rendererName = (const char*)glGetString(GL_RENDERER);
		_GLSLVersion = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);

		glGetIntegerv(GL_MAJOR_VERSION, &_majorVersion);
		glGetIntegerv(GL_MINOR_VERSION, &_minorVersion);

		// Инициализируем расширения.
		InitializeExtensions();

		return true;
	}
コード例 #2
0
ファイル: PBuffer.cpp プロジェクト: ArchyInf/HPL1Engine
	bool cPBuffer::Init(unsigned int alWidth,unsigned int alHeight, cColor aCol)
	{
		#ifdef WIN32
		unsigned int lFormatNum=0;
		int lFormat=0;

		mlWidth = alWidth;
		mlHeight = alHeight;

		HDC CurrentHdc = wglGetCurrentDC();
		HGLRC CurrentGGlRc = wglGetCurrentContext();

		//Set the pixel format:
		wglChoosePixelFormatARB(CurrentHdc, &mvAttribFormat[0], NULL, 1, &lFormat, &lFormatNum);
		if(lFormatNum==0){
			Error("Couldn't find any pixel format!\n");
			return false;
		}
				
		//Create the buffer
		mPBuffer = wglCreatePbufferARB(CurrentHdc, lFormat, mlWidth, mlHeight, &mvAttribBuffer[0]);
		if (!mPBuffer)
		{
			int err = GetLastError();
			Error("pbuffer creation error!\n");
			return false;
		}

		//Get the Device Context
		mDeviceContext = wglGetPbufferDCARB(mPBuffer);
		if(!mDeviceContext){
			Error("Some DC error!\n");
		}

		//Get the GL Context
		mGLContext = wglCreateContext(mDeviceContext);
		if(!mGLContext){
			Error("Some GLRC error!\n");
		}

		if(mbShareObjects){
			if(!wglShareLists(CurrentGGlRc, mGLContext))
			{
				Error("Error sharing lists.\n");
			}
		}
		
		//Check the real dimensions of the PBuffer
		wglQueryPbufferARB(mPBuffer, WGL_PBUFFER_WIDTH_ARB, &mlWidth);
		wglQueryPbufferARB(mPBuffer, WGL_PBUFFER_HEIGHT_ARB, &mlHeight);
			
		//Init some GL stuff with the Buffer.
		#ifdef WIN32
		HDC OldHDC = wglGetCurrentDC();
		HGLRC OldGLRC = wglGetCurrentContext();
		#endif
		MakeCurrentContext();
				
		if(mbShareObjects)
		{
			cLowLevelGraphicsSDL* pSDLGfx = static_cast<cLowLevelGraphicsSDL*>(mpLowLevelGraphics);
			pSDLGfx->SetupGL();
		}
		
		mpLowLevelGraphics->SetClearColor(aCol);
		mpLowLevelGraphics->ClearScreen();

		wglMakeCurrent(OldHDC,OldGLRC);
		#elif defined(__linux__)
		return false;
		#endif
	
		return true;
	}