• 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.

C++ gauge problem

JB3DG

Resource contributor
Messages
1,325
Country
southafrica
Hi

I got around most of those issues that I was having with my GDI+ gauge. Now I have discovered that the last issue of my gauge refusing to draw is due to my using a IMAGE_USE_TRANSPARENCY draw flag in both the MAKE_STATIC macros as can be seen below:

MAKE_STATIC
(
HUD_surface,
HUD_SURF,
NULL,
NULL,
IMAGE_USE_TRANSPARENCY,
0,
0,0
)

PELEMENT_HEADER HUD_next[] = { &HUD_surface.header, NULL };

MAKE_STATIC
(
HUD_background,
HUD_BGND,
HUD_next,
NULL,
IMAGE_USE_TRANSPARENCY,
0,
0,0
)

PELEMENT_HEADER HUD_list = &HUD_background.header;

If I use any other draw flag in the HUD_surface object it shows up but I need the gauge to be transparent (it is 0,0,0 black) because this is for a HUD. Anyone who can help?

Thanks
JB
 
I strongly urge you to download and study this example "how to" on drawing both opaque and transparent GDI+ gauges:

http://archive.msdn.microsoft.com/ESPDrawingGaugesGDI/Release/ProjectReleases.aspx?ReleaseId=1640

Among other things, it also illustrates how to implement the new GAUGE_HEADER_FS1000, how to implement custom module_init and module_deinit sections, and...

...how to implement SimConnect.

In any case, in your example above you (again) forgot to include the DIBSECTION. It's a bit tough to draw on a memory map that hasn't been instantiated... ;)

If you are able to create a GDI driven gauge, you will need to define your background image the following way if you want transparency:

Code:
MAKE_STATIC(  background_hud_ogl,    
              BMP_GAUGE_TRANSPARENT_ID,    
              NULL,    
              NULL,    
              IMAGE_CREATE_DIBSECTION | IMAGE_USE_TRANSPARENCY | IMAGE_USE_ALPHA | IMAGE_USE_ERASE | IMAGE_ERASE_ALWAYS,    
              0,    
              0, 0 )

Next, draw the gauge data in the Callback. If it is transparent, be sure to Clear the graphics object first:

Code:
using namespace Gdiplus;   
       
case PANEL_SERVICE_PRE_DRAW:   
    if(mCanvas)    
    {   
             if (mHasAlpha)  // A local variable telling us if there is no background 
            mGraphics->Clear(Color(0, 0, 0, 0));   
...   
             OnDraw();     
...        
             mGraphics->DrawImage(mBitmap, 0, 0, mDimX, mDimY);   
    }   
    break;

The only downside to the above is that this technique will only work with FSX SP2 or Acceleration. For a more universal method, refer to this discussion:
http://www.fsdeveloper.com/forum/archive/index.php?t-22024.html
 
Last edited:
Back to the drawing board......Sigh....:) Thanks Bill. Was hoping to avoid simconnect as im trying to keep things simple for now but looks like Ill have to go back to GAUGE_HEADER_FS1000....
 
Back to the drawing board......Sigh....:) Thanks Bill. Was hoping to avoid simconnect as im trying to keep things simple for now but looks like Ill have to go back to GAUGE_HEADER_FS1000....

You don't HAVE to include SimConnect if you don't want or need it. It's just that this example tried to cover as many bases as possible!

Of particular interest, notice that this method (transparent background) means that you only need one MAKE_STATIC declaration.

Also, unless you are going to have both opaque and transparent elements in your gauge, this test is completely unnecessary:

Code:
if (mHasAlpha)  // A local variable telling us if there is no background

IOW, it shouldn't be at all difficult to make the required changes to your existing work...
 
Last edited:
The problem I have had though when I have tried to use only one MAKE_STATIC is that I get a null pointer error.

MAKE_STATIC
(
HUD_background,
HUD_BGND,
HUD_next,
NULL,
IMAGE_USE_TRANSPARENCY,
0,
0,0
)

When I set HUD_next to NULL and remove:

MAKE_STATIC
(
HUD_surface,
HUD_SURF,
NULL,
NULL,
IMAGE_USE_BRIGHT,
0,
0,0
)

PELEMENT_HEADER HUD_next[] = { &HUD_surface.header, NULL };

it crashes the sim and in the debug output i get the null pointer error.
 
If you remove the HUD_surface static, then this statement:
PELEMENT_HEADER HUD_next[] = { &HUD_surface.header, NULL };
is where your problem is.

The expression in the braces refers to HUD_surface, which is now undefined, because you have removed it.

Doug
 
Doug is correct. You need to revise the PELEMENT_HEADER declaration:
Code:
extern PELEMENT_HEADER HUD_element_list;


MAKE_STATIC
(
     HUD_surface,
     HUD_SURF,
     NULL,
     NULL,
     IMAGE_CREATE_DIBSECTION | 
     IMAGE_USE_TRANSPARENCY | 
     IMAGE_USE_ALPHA | 
     IMAGE_USE_ERASE | 
     IMAGE_ERASE_ALWAYS, 
     0,
     0,0
)

PELEMENT_HEADER HUD_element_list =  &HUD_surface.header;
 
If you remove the HUD_surface static, then this statement:
PELEMENT_HEADER HUD_next[] = { &HUD_surface.header, NULL };
is where your problem is.

The expression in the braces refers to HUD_surface, which is now undefined, because you have removed it.

Doug

I was removing that PELEMENT_HEADER as well.....anyways trying with n4gix's revision quick...
 
Nope no go. Wont compile

'IMAGE_ERASE_ALWAYS' : undeclared identifier
 
Nope no go. Wont compile

'IMAGE_ERASE_ALWAYS' : undeclared identifier

Your copy of gauges.h is missing the entries for this new flag. Either edit the file to add the missing (new) entries, or use the file from Dai Griffith's latest sd2gau30.zip file.

Code:
#define         IMAGE_USE_LUMINOUS_PARTIAL              BIT15       // Parts of image are lit by interior light (alpha channel)
#define         IMAGE_ERASE_ALWAYS                      BIT16

Code:
#define         SET_GAUGE_NOT_FAILED( element)          element->image_flags &= ~GAUGE_FAILURE
	
#define         GET_IMAGE_ERASE_ALWAYS( element )       (element->image_flags &   IMAGE_ERASE_ALWAYS)
 
Still no go. Getting null pointer errors again. Made sure that i changed all the HUD_list into HUD_element_list. But no change....
 
If you remove the HUD_surface static, then this statement:
PELEMENT_HEADER HUD_next[] = { &HUD_surface.header, NULL };
is where your problem is.

The expression in the braces refers to HUD_surface, which is now undefined, because you have removed it.

Doug

I was going to point that out too...

When I work on stubborn pointers, I usually check to see if they are NULL before using them and if they are,
display a message box telling me so, so I know where the fault is.

if (!p_NULLPointer) { MessageBox(hWnd,"Oh oh, p_NULLPointer is NULL!! Check your work!!", "FAULT",MB_ICONINFORMATION); }

I don't think you can do this with C++ gauges though, since I've never programmed any. =P
 
Last edited:
Well...that one doesnt exactly apply anymore

this is how things are now

char HUD_gauge_name[] = GAUGE_NAME;
extern PELEMENT_HEADER HUD_element_list;
extern MOUSERECT HUD_rect[];
GAUGE_CALLBACK PFDCallBack;
GAUGE_HEADER_FS700(GAUGE_W, HUD_gauge_name, &HUD_element_list, HUD_rect, PFDCallBack, 0, 0, 0);

extern PELEMENT_HEADER HUD_element_list;


MAKE_STATIC
(
HUD_surface,
HUD_SURF,
NULL,
NULL,
IMAGE_CREATE_DIBSECTION |
IMAGE_USE_TRANSPARENCY |
IMAGE_USE_ALPHA |
IMAGE_USE_ERASE |
IMAGE_ERASE_ALWAYS,
0,
0,0
)

PELEMENT_HEADER HUD_element_list = &HUD_surface.header;

Still getting NULL pointer exceptions. Havent messed with any other pointers though.
 
I strongly suggest that you load up the entire solution for the ESP example and work with that until you can get a successful compiled gauge.
 
Only problem with the ESP version is the bitmaps wont load and its a little tougher on me to see where nitty gritty starts and the scaffholding ends.....
 
You don't HAVE to include SimConnect if you don't want or need it. It's just that this example tried to cover as many bases as possible!

So if I understand correctly in the ESP example, simconnect is only used as a different medium to access variables?
 
So if I understand correctly in the ESP example, simconnect is only used as a different medium to access variables?

I'll try to explain this as clearly as possible, since from my perspective it remains in the realm of possibilities, not actuality. IOW, I haven't ever used SimConnect myself, but do understand the principles involved.

This example shows how to (a) read variables from the sim and (b) how to send those variables back to the sim to be used in the display.

What is not covered in this example is what can take place within the SimConnect module in between (a) and (b). In other words additional processing.

If you look at the SDK's documents on A:vars, there is a column named "Settable" in which most of the A:vars are marked "Yes." This means that the SimConnect module can effectively intercept any such marked A:vars, then write entirely NEW values back to the sim.

In theory, one could write an entirely new "autopilot" for example...

...or a fully customised FADEC controller as another example...

...or customized AI that may be "injected" into the sim dynamically (such as that Chris D. managed).

But, for the purposes of simply testing out the SDK example, this is simply extraneous and unnecessary.
 
IOW its the gauge option of using simconnect instead of FSX modules. I got it now thanks :)
 
IOW its the gauge option of using simconnect instead of FSX modules. I got it now thanks :)

More precisely, it shows how to use SimConnect rather than requiring the customer to have a registered version of FSUIPC!

For example, Ed's FADEC implementation for the Citation X had to use FSUIPC because the project had to be both FS9 and FSX compatible.

Had we only built the CX for FSX, he could have used SimConnect instead, which in terms of user friendliness would have been a far better method.
 
Now if I can figure out how to remove the simconnect stuff and get around all the compiler errors when i try to mod things.....
 
Back
Top