Click here to Skip to main content
Rate this: bad
good
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.
 
EDIT:
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 5-Nov-11 23:55pm
Edited 12-Nov-11 6:37am
(no name)84.5K
v4
Comments
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 Sergey Alexandrovich Kryukov 535
1 OriginalGriff 275
2 BillWoodruff 260
3 Shweta N Mishra 244
4 Deepu S Nair 230
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,818
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,755


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 12 Nov 2011
Copyright © CodeProject, 1999-2014
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