• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Transparent GDI+ problem

JB3DG

Resource contributor
Messages
1,325
Country
southafrica
Hi guys

Im trying to make a HUD in GDI+ and if i have this line from the start of drawing like in the ESP example:

mGraphics->Clear(Color(0, 0, 0, 0));

Then nothing is displayed at all. If i remove it though i get everything except the gauge is no longer transparent. the background is black. It is totally beyond me why it refuses to be transparent.....

Any ideas?

Thanks
JB
 
Bump*....

Gee is GDI+ so advanced that there is no one on these forums that can help me? C'mon guys....once you manage to get a hang of the basics it is VASTLY easier than XML. Except....of course....the few difficulties i am having....anyone wanna help? it would help many budding coders here....
 
HI I can only assume what you are trying to do. The Graphics.clear function is used to fill the entire window with the background color. Your usage defines a black color (0,0,0) and an alpha value of zero. The result : there is nothing. The window is completely transparent. If you now draw your HUD in that window you can use two approaches:
1. Vector graphics uses simply lines, circles and text. This is the easy way. You need not to think about any alpha value. Except, if you want to have even the line semi transparent. Then you can specify a drawing Pen with an adjusted alpha value.
2. If you use a bitmap to display a HUD, then you have to prepare a 32bit RGBA texture where all transparent pixels have an alpha value of zero and all opaque pixel have a value of 255 in the alpha channel. The ImageTool can do that for you. It converts a 24bit texture to a 32bit bitmap with all pixels, which have the same color like that in the upper left corner, being transparent.
If I assume right, you used a 24 bit texture where you expected all black pixel being transparent?
Regards
Mike
 
Im using the first approach. I draw all my lines etc after the graphics.clear function but they just dont show up. Its like the clear function is wiping everything out before or after.
 
Hi,
if it does not work, you have to go on step deeper. When you create your HUD window use the following attributes in the dwExStyle argument:
WS_EX_TOPMOST
WS_EX_LAYERED
for the style argument you shold use WS_POPUP to avoid drawing a frame.
In the windows message queue, catch the WM_CREATE message and change the windows attribute with:
SetLayeredWindowAttributes(hwnd, 0, 0, LWA_COLORKEY);
catch the WM_ERASEBKGND message and return out of this message with 0. This avoids flickering.
All drawing should now work as expected.
Regards
Mike
 
The only thing is im not using panel windows. Its mapped to a VC mesh
 
I don't know what you mean with a panel window or a VC mesh. As long as you are working with the GDI+ Graphics class you have access to the device context and to the window handle as well. If you did not create the window in your application you can at any initialization point use the call
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
followed by
SetLayeredWindowAttributes(hwnd, 0, 0, LWA_COLORKEY);
These are the only things reqired to have the window transparent.
Regards
Mike
 
Jon, what are you using for your background bitmap?

I notice in the ESP example that the gauge_background.bmp is flood-filled with RGB:1,1,1 which is required if you wish your vector drawing to be displayed in the transparent version.

The GAUGE_HEADER_FS1000 uses the BMP_BACKGROUND image:

Code:
GAUGE_HEADER_FS1000(
	GAUGEHDR_VAR_NAME, 
	GAUGE_W, 
	transparent_gauge_name, 
	&gaugeTransparent_element_list,
	gaugeTransparent_mouse_rect,
	GDIPlus_Gauge::Callback<TransparentGauge>,
	0L, 0L, 
	gauge_guid2, 
	0, 	0, 	0, 	0, 	0);

MAKE_STATIC(  gaugeTransparent_image, 
			  BMP_BACKGROUND, 
			  NULL, 
			  NULL, 
			  IMAGE_CREATE_DIBSECTION | IMAGE_USE_TRANSPARENCY | IMAGE_USE_ALPHA | IMAGE_USE_ERASE | IMAGE_ERASE_ALWAYS, 
			  0, 
			  0, 0 )
 
Im using it as is from the ESP example. Everything is pretty much identical except i elliminated Simconnect from the equation and im drawing my own stuff.

Code:
in the ESP example that the gauge_background.bmp is flood-filled with RGB:1,1,1 which is required if you wish your vector drawing to be displayed in the transparent version.

Do you actually mean the Opaque version? Cuz that would make more sense. Or does GDI+ not work on a RGB: 0,0,0 background?
 
Do you actually mean the Opaque version? Cuz that would make more sense. Or does GDI+ not work on a RGB: 0,0,0 background?

Both the opaque and the transparent versions use the same bitmap: 1,1,1

The sim treats 1,1,1 as though it were transparent, just as with normal 2d masks, the 1,1,1 is required for your GDI+ drawing to be seen...

...when used as a transparent HUD.

That's why I included the TRANSPARENT Header in my reply. Check the OPAQUE Header and note that it uses the same 1,1,1 bitmap.
 
What about the image flags where it says IMAGE_USE_ALPHA? There is no alpha channel on my bitmap. If i were to use one and set the alpha to 0 would that work? Basically my problem in the nutshell is that if i use the mGraphics->Clear function absolutely nothing gets drawn but if i dont i dont get a transparent HUD. So....whats the workaround? everything else is perfectly in place....
 
Have you tried simply using the same scheme as the ESP example?

Adjust the background image you use to be 1,1,1 instead of 0,0,0...

Have you compiled and tested the ESP example? If so, and it works then you will have a basis for comparison...
 
Um....I am using the bitmap with the 1,1,1. I havent changed it one bit.
 
Um....I am using the bitmap with the 1,1,1. I havent changed it one bit.

Okay then. It was the only possible thing I could think of that might have been different.

Have you tried compiling and testing the ESP example gauge? If so, does it work?
 
I have tested the transparent example but not mapped to a VC panel. Is it possibly my not using the zorder entry in the VC panel?
 
Well, you really need to map the transparent portion of the example gauge to the $HUD texture to see if it works properly. If it does, then you have a baseline from which to puzzle out why your's doesn't work.

If the HUD gauge is the only one on the $HUD texture, then zorder won't make any difference.

Actually zorder only affects the "layering" of sub-panels in the 2d cockpit environment anyway...
 
Ok obviously was a screw up of mine somewhere....I tested the transparent sample and it worked. Now to go back to the begining and see what controls it...ill post the fix here.
 
Ok obviously was a screw up of mine somewhere....I tested the transparent sample and it worked. Now to go back to the begining and see what controls it...ill post the fix here.

That's what I was wanting to know, Jon. Now you have a working example from which you can now try to isolate your error. Undoubtedly it will be something simple, such as a missing semi-colon or something equally obscure! :eek:
 
I dunno hey I have had some wierd things happen with C++....deffo not a missing ; though ;). The compiler wont let me get away with one of those lol.
 
Back
Top