Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In Short:
How to 'render to a per pixel transparent/alpha Bitmap' using OpenGL

In Detail:
I'm writing a program in VC++, using OpenGL (Platform: Windows XP).
The idea is to use OpenGL to render a scene (say, a few triangles) that has semi transparent Vertex Colors (for eg: r,g,b,a= 0,1,1,0.5) to a 32Bit Bitmap, With Alpha Channel.
Then, display that perpixel-alpha-blended bitmap on screen using a Layered window.

Displaying an Alpha-channel bitmap as a layered window works fine.
But the problem is, the bitmap that is rendered doesn't has an alpha channel(meaning, all the alpha values are Zero).

I tried searching a lot around the internet, only to find 'colorkeyed' rendering of OpenGL-based transparent windows; what I would like to do is to display a 'per-pixel-alpha' based window, rendered using OpenGL.

EDIT:
C++
void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
{
	PIXELFORMATDESCRIPTOR pfd;
	int format;
	
	//the hDC parameter is created earlier as: hDC=CreateCompatibleDC(...);
	//SelectObject(hDC,hbmp);
	
	// set the pixel format for the DC
	ZeroMemory( &pfd, sizeof( pfd ) );
	pfd.nSize = sizeof( pfd );
	pfd.nVersion = 1;
	pfd.dwFlags =PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 32;
	pfd.cDepthBits = 32;
	pfd.iLayerType = PFD_MAIN_PLANE;
	format = ChoosePixelFormat( *hDC, &pfd );
	SetPixelFormat( *hDC, format, &pfd );

	// create and enable the render context (RC)
	*hRC = wglCreateContext( *hDC );
	wglMakeCurrent( *hDC, *hRC );
	
}
Posted
Updated 12-Nov-11 5:37am
v4
Comments
Amir Mahfoozi 6-Nov-11 7:35am    
So you think that the problem is from OpenGL or Window configurations ? And did you use PFD_TYPE_RGBA in PIXELFORMATDESCRIPTOR ?
Ashok Gowtham 12-Nov-11 11:31am    
i'm sure the problem is with setting up gl.
yes i did specify PFD_TYPE_RGBA.
Ashok Gowtham 14-Nov-11 11:38am    
thanks for editing André Kraak :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900