Advertisement

SetPixelFormat fails on Nvidia cards

Started by November 20, 2018 01:52 PM
3 comments, last by Ed Welch 6 years, 2 months ago

	PIXELFORMATDESCRIPTOR pfd;
	memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
	pfd.nSize		= sizeof(PIXELFORMATDESCRIPTOR);
	pfd.nVersion   = 1;
	pfd.dwFlags    = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 32;
//	pfd.cAlphaBits = 8;
	pfd.cDepthBits = 24;
	pfd.iLayerType = PFD_MAIN_PLANE;

	int iPixelFormat = ChoosePixelFormat(m_hDC, &pfd);
	if (iPixelFormat == 0)
		throw("Error calling ChoosePixelFormat");

	if(!SetPixelFormat(m_hDC, iPixelFormat, &pfd))
		throw("Error calling SetPixelFormat");

I am having problems initialising OpenGL on a GTX 1050 with latest driver. SetPixelFormat always fails. I tried changing cColorBits, cDepthBits, etc. makes no difference. Also, this same code works fine with Intel and AMD GPUs. Anyone have any ideas whats wrong?

 

Damn it, i posted a full fletched text here, but now its gone ?

Here is the short one:

- stencil bits are missing!

- use DescribePixelFormat() first and then use SetPixelFormat()

 

See the following code, which works on all my machines:


fplClearStruct(&pfd);
		pfd.nSize = sizeof(pfd);
		pfd.nVersion = 1;
		pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
		pfd.iPixelType = PFD_TYPE_RGBA;
		pfd.cColorBits = 32;
		pfd.cDepthBits = 24;
		pfd.cAlphaBits = 8;
		pfd.cStencilBits = 8;
		pfd.iLayerType = PFD_MAIN_PLANE;
		int pixelFormat = wapi->gdi.ChoosePixelFormat(deviceContext, &pfd);
		if(!pixelFormat) {
			FPL_ERROR(FPL__MODULE_VIDEO_OPENGL, "Failed choosing RGBA Legacy Pixelformat for Color/Depth/Alpha (%d,%d,%d) and DC '%x'", pfd.cColorBits, pfd.cDepthBits, pfd.cAlphaBits, deviceContext);
			return false;
		}
		wapi->gdi.DescribePixelFormat(deviceContext, pixelFormat, sizeof(pfd), &pfd);
		if(!wapi->gdi.SetPixelFormat(deviceContext, pixelFormat, &pfd)) {
			FPL_ERROR(FPL__MODULE_VIDEO_OPENGL, "Failed setting RGBA Pixelformat '%d' for Color/Depth/Alpha (%d,%d,%d and DC '%x')", pixelFormat, pfd.cColorBits, pfd.cDepthBits, pfd.cAlphaBits, deviceContext);
			return false;
		}

 

Advertisement
4 hours ago, Finalspace said:

- stencil bits are missing!

It's a bad idea to set cStencilBits if you don't need it.

Set pfd to the minimum values you need.  ChoosePixelFormat() will return the best values, only if they're available. Setting them to the max values doesn't leave much room for choice.  So, if you set cColorBits(24), and cDepthBits(16), you will get cColorBits(32) and cDepthBits(24) back if your device supports it.

 


 

 

4 hours ago, Finalspace said:

Damn it, i posted a full fletched text here, but now its gone ?

Here is the short one:

- stencil bits are missing!

- use DescribePixelFormat() first and then use SetPixelFormat()

 

See the following code, which works on all my machines:



fplClearStruct(&pfd);
		pfd.nSize = sizeof(pfd);
		pfd.nVersion = 1;
		pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
		pfd.iPixelType = PFD_TYPE_RGBA;
		pfd.cColorBits = 32;
		pfd.cDepthBits = 24;
		pfd.cAlphaBits = 8;
		pfd.cStencilBits = 8;
		pfd.iLayerType = PFD_MAIN_PLANE;
		int pixelFormat = wapi->gdi.ChoosePixelFormat(deviceContext, &pfd);
		if(!pixelFormat) {
			FPL_ERROR(FPL__MODULE_VIDEO_OPENGL, "Failed choosing RGBA Legacy Pixelformat for Color/Depth/Alpha (%d,%d,%d) and DC '%x'", pfd.cColorBits, pfd.cDepthBits, pfd.cAlphaBits, deviceContext);
			return false;
		}
		wapi->gdi.DescribePixelFormat(deviceContext, pixelFormat, sizeof(pfd), &pfd);
		if(!wapi->gdi.SetPixelFormat(deviceContext, pixelFormat, &pfd)) {
			FPL_ERROR(FPL__MODULE_VIDEO_OPENGL, "Failed setting RGBA Pixelformat '%d' for Color/Depth/Alpha (%d,%d,%d and DC '%x')", pixelFormat, pfd.cColorBits, pfd.cDepthBits, pfd.cAlphaBits, deviceContext);
			return false;
		}

Unfortunately it wasn't that. Eventually, I just gave up and used glfw instead.

Thanks for the answer anyways

 

This topic is closed to new replies.

Advertisement