Click here to Skip to main content
11,796,394 members (70,584 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Windows OpenGL VC++
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.

void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
	int format;
	//the hDC parameter is created earlier as: hDC=CreateCompatibleDC(...);
	// set the pixel format for the DC
	ZeroMemory( &pfd, sizeof( pfd ) );
	pfd.nSize = sizeof( pfd );
	pfd.nVersion = 1;
	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 5-Nov-11 22:55pm
Edited 12-Nov-11 5:37am
(no name)90.6K
Amir Mahfoozi at 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 at 12-Nov-11 11:31am
i'm sure the problem is with setting up gl.
yes i did specify PFD_TYPE_RGBA.
Ashok Gowtham at 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)

  Print Answers RSS
0 Maciej Los 570
1 Abhinav S 392
2 OriginalGriff 340
3 CPallini 269
4 KrunalRohit 249
0 OriginalGriff 2,012
1 Maciej Los 1,615
2 KrunalRohit 1,310
3 CPallini 1,015
4 Richard MacCutchan 828

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 12 Nov 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100