Click here to Skip to main content
13,055,861 members (49,562 online)
Rate this:
Please Sign up or sign in to vote.
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
Updated 12-Nov-11 5:37am
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 12 Nov 2011
Copyright © CodeProject, 1999-2017
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