I tried to make gdiplus and opengl works together in one offscreen hdc. Current code is something like this (no Internet access)
- create a gdiplus bitmap A
- create a gdiplus graphics from A as B
- get B's HDC
- choose a proper pixelformat for HDC
- create a gdiplus graphics from HDC as C
- create an opengl context from HDC as D
- drawing with C and D
- release HDC to B
- draw A to other graphics
C is needed because I found that after I release the HDC to B, it is not possible for opengl to change the bitmap. To check if things work, I added a bitmap E by reading gl pixels before (9)
There are still a problem in current program After releasing the hdc, the bitmap A losses its alpha information. The bitmap E works fine with correct alpha, but the GL_BGRA cannot read out alpha so I have to read GL_RGBA data and do a per pixel convertion into gdiplus color format.
Should I just use E or is there any other attempt?
Example of releasehdc alpha lossing:
Bitmap bitmap(100,100);
Graphics graphics(&bitmap);
HDC hdc=graphics.GetHDC();
Graphics graphics2(hdc);
graphics2.Clear(Color(128,255,0,0));
graphics2.Flush();
graphics.ReleaseHDC(hdc);
//draw bitmap to other graphics
Note: I just figure out that gdiplus didn't actually use the alpha channel in the HDC, only the rgb channels are shared, so I wonder how it works with a BGRA target bitmap