New Release D3D9Client Development

So far all my experiments have confirmed this, that the best solution for now is to tie horizon haze color and intensity to the actual solar angle.
Sorry, this led me to believe that you experimented with the shader code.

Also, how the atmosphere is looking can greatly depend on display settings. It looks much worse on my laptop than on desktop computer. We probably would need some-kind of build in display calibration and post-processing shader to match with the display.

But anyway here's a link to online display tests. Gamma and contrast are likely to most important ones. http://www.lagom.nl/lcd-test/gamma_calibration.php
 
All modern (last 5 years) displays should come reasonably well calibrated from factory and target sRGB
If not, there are controls on the graphic drivers that allow you to adjust gamma. Don't think we need an Orbiter specific adjustment.
 
My display is probably 12 years old running in sRGB. But, of course, there are "Movie" and "Photo" modes giving a very different color scale which don't look good for any purpose. The display on my Intel HD Graphics 4000 laptop is terrible even if it's not that old.
But, yes, agreed. Let's forget the build in calibration.
 
This have nothing do with monitor color calibration or gamma settings. I present two screenshots, taken at the same time but with different horizon color settings. The first screenshot show the sunrise with horizon color set to -1.500. The second screenshot shows the same sunrise but with horizon color set to 0.5. The first one is more realistic with a golden color (there's a reason why the hour around sunrise/sunset is called the "golden hour") than the second with a cold blue horizon. It is more suitable for a sun that is high in the sky, around midday. D3D9Client version R4.22, Orbiter 2016, scenario is Delta-glider\DG-S ready for takeoff.
 

Attachments

  • Sunrise_horizon_color_-1_500.jpg
    Sunrise_horizon_color_-1_500.jpg
    50.3 KB · Views: 18
  • Sunrise_horizon_color_0_500.jpg
    Sunrise_horizon_color_0_500.jpg
    49.8 KB · Views: 17
True, the second one looks "alien", like its another cold planet with maybe methane chemistry or such....
 
My display is probably 12 years old running in sRGB. But, of course, there are "Movie" and "Photo" modes giving a very different color scale which don't look good for any purpose. The display on my Intel HD Graphics 4000 laptop is terrible even if it's not that old.
But, yes, agreed. Let's forget the build in calibration.

The sRGB mode should be ok. Over time your white point might drift and need adjustment, but there are usually RGB controls for that.
White point can be set visually by matching an overcast sky, as clouds are usually white ;)
Laptop screens have viewing angle issues, but its possible to correct them.

Windows 10 has a built in calibration tool:

A correct setting will improve ClearType font rendering across the system, so I recommend giving it a try.
 
Could you post the modified shader ?
Just out of curiosity, which of the shaders in the D3D9Client folder of Modules\ do control the atmosphere rendering?
 
Weird. So I am converting some my HDC to sketchpad. When I run it in D3D9 I get a message Assertion fail.
I am using r4.11
[ BaseDir : D:\Orbiter2016\ ConfigDir : D:\Orbiter2016\Config\ MeshDir : D:\Orbiter2016\Meshes\ TextureDir : D:\Orbiter2016\Textures\ HightexDir : D:\Orbiter2016\Textures2\ ScenarioDir: D:\Orbiter2016\Scenarios\ 000000.000: --------------------------------------------------------------- D3D9 DLLs : C:\WINDOWS\SYSTEM32\d3d9.dll [v 10.0.19041.928] : C:\WINDOWS\SYSTEM32\d3dx9_43.dll [v 9.29.952.3111] 000000.000: --------------------------------------------------------------- 000000.000: Module D3D9Client.dll ........ [Build 200907, API 160828] 000000.000: Module ParkingBrakeMFD.dll ... [Build 210307, API 160828] 000000.000: Module CamControl.dll ........ [Build ******, API 050206] 000000.000: Module CameraMFD.dll ......... [Build 201023, API 160828] 000000.000: Module ScnEditorTLE.dll ...... [Build ******, API 060425] 000000.000: Module GPCMFD.dll ............ [Build 111222, API 100830] 000000.000: --------------------------------------------------------------- 000000.000: >>> WARNING: Obsolete API function used: oapiRegisterMFDMode 000000.000: At least one active module is accessing an obsolete interface function. 000000.000: Addons which rely on obsolete functions may not be compatible with 000000.000: future versions of Orbiter. 000000.000: --------------------------------------------------------------- 000000.000: 000000.000: **** Creating simulation session 000000.000: D3D9: [DirectX 9 Initialized] D3D9: 3D-Adapter.............. : NVIDIA GeForce GTX 1660 Ti D3D9: MaxTextureWidth......... : 16384 D3D9: MaxTextureHeight........ : 16384 D3D9: MaxTextureRepeat........ : 8192 D3D9: VolTexAddressCaps....... : 0x3F D3D9: NumSimultaneousRTs...... : 4 D3D9: VertexDeclCaps.......... : 0x30F D3D9: MiscCaps................ : 0x2FCEF2 D3D9: XNA Math Support........ : Yes D3D9: Vertex Texture.......... : Yes D3D9: Separate AlphaBlend..... : Yes D3D9: Shadow Mapping.......... : Yes D3D9: D3DFMT_A16B16G16R16F.... : Yes D3D9: D3DFMT_A32B32G32R32F.... : Yes D3D9: D3DFMT_D32F_LOCKABLE.... : Yes D3D9: D3DFMT_A2R10G10B10...... : Yes D3D9: D3DFMT_L8............... : Yes D3D9: D3DDTCAPS_DEC3N......... : No D3D9: D3DDTCAPS_FLOAT16_2..... : Yes D3D9: D3DDTCAPS_FLOAT16_4..... : Yes D3D9: Runs under WINE......... : No D3D9: D3D9Build Date.......... : 200906 D3D9: Available Texture Memory : 4073 MB 000000.000: D3D9: [3DDevice Initialized] 000000.000: D3D9: [Loading Constellations] 000000.000: D3D9: [D3D9Client Initialized] ... D3D9: ERROR: D3D9ClientSurface: GetDC() Failed D3D9: ERROR: Surface name is clbkCreateSurfaceEx Handle=0x223A5998 (256,256) D3D9: ERROR: Surface Has a Surface Interface D3D9: ERROR: Surface Is Lockable D3D9: ERROR: Surface is in a DefaultPool D3D9: ERROR: Surface has RENDERTARGET usage D3D9: ERROR: Surface Format is 22 D3D9: ERROR: ActiveFlags( OAPISURFACE_RENDERTARGET ) /ICODE] here is the code where I changed from HDC to sketchpad. I also noticed the font did not change in the rcsqty. [ICODE] void Atlantis::RedrawPanel_PANELRCSstatus(SURFHANDLE surf, int part) { char cbuf[20]; oapi::Font* font = oapiCreateFont(50, true, "Seven Segment"); oapi::Sketchpad* skp = oapiGetSketchpad(surf); skp->SetFont(font); skp->SetTextColor(0x0000FF); skp->SetTextAlign(oapi::Sketchpad::LEFT); sprintf(cbuf, "%2.0f", RCSQTY); skp->Text(0, 100, cbuf, strlen(cbuf)); skp->Text(210, 100, cbuf, strlen(cbuf)); skp->Text(105, 100, cbuf, strlen(cbuf)); oapiReleaseSketchpad(skp); }
and this:
void Atlantis::RedrawPanel_EVENTAFTstatus(SURFHANDLE surf, int part) { char cbuf[20]; oapi::Font* font = oapiCreateFont(70, true, "Arial"); oapi::Sketchpad* skp = oapiGetSketchpad(surf); skp->SetFont(font); skp->SetTextColor(0x000000); skp->SetTextAlign(oapi::Sketchpad::LEFT); sprintf(cbuf, "%d", Minutes4set); skp->Text(5, 85, cbuf, strlen(cbuf)); sprintf(cbuf, "%d", Minutes3set); skp->Text(70, 85, cbuf, strlen(cbuf)); sprintf(cbuf, "%d", Minutes2set); skp->Text(145, 85, cbuf, strlen(cbuf)); sprintf(cbuf, "%d", Minutes1set); skp->Text(220, 85, cbuf, strlen(cbuf)); oapiReleaseSketchpad(skp); }
 

Attachments

  • d3d9assertion.jpg
    d3d9assertion.jpg
    153.1 KB · Views: 2
Last edited:
Weird. So I am converting some my HDC to sketchpad. When I run it in D3D9 I get a message Assertion fail.
I am using r4.11

The stock implementation of Sketchpad is locked to 3 predefined fonts. I don't know if this is a bug or a feature but no custom user fonts allowed. However, gcCore::CreateSketchpadFont() will let you to create any font you like with additional customization options. Or you can just add '*' in the front of the name to override the build in limitation like "*Seven Segment".

The debug assertion is related to a failed GetDC() it has nothing to do with sketchpad at-least not directly. I haven't been able to find a reason for the failure, based on data everything is O.K. You could switch the Debug Level to 3 and reproduce the assertion. And then zip and attach the D3D9ClientLog.html from /Modules/D3D9Client/ to your reply.

It's possible that a use of Sketchpad has changes the surface format to something that's more sensitive to DC related errors.
 
Oh. Well I was told that "HDC is deprecated in Orbiter 2016". That is why I changed them. I did notice that the seven segment font did not work in normal graphics.

When I get home I will run it in debug level 3? and see.

And I was hoping that would fix the random CTD and call stack window issue
 
I did the *.oapi::Font* font1 = oapiCreateFont(50, true, "*Seven Segment");. And I got the font to show. No issues. but where to set the debug level?
D3D9: ERROR: UnDeleted Surface(s) Detected D3D9: ERROR: Surface 0x16D13E70 (clbkCreateSurface) (256,36) D3D9: ERROR: [Failed to Reset DirectX Device] (Likely blocked by undeleted resources)
 
Thanks.
here you go:
000000.000: D3D9: [Scene Initialized] 000000.000: Finished initialising panels D3D9: ERROR: D3D9ClientSurface: GetDC() Failed D3D9: ERROR: Surface name is clbkCreateSurfaceEx Handle=0x240824B8 (256,256) D3D9: ERROR: Surface Has a Surface Interface D3D9: ERROR: Surface Is Lockable D3D9: ERROR: Surface is in a DefaultPool D3D9: ERROR: Surface has RENDERTARGET usage D3D9: ERROR: Surface Format is 22 D3D9: ERROR: ActiveFlags( OAPISURFACE_RENDERTARGET ) D3D9: ERROR: Surface 0x16D13E70 wasn't in the catalog
 

Attachments

I went back to the HDC code. Except for one function. After severeal exits and enters I final got the error:
D3D9: ERROR: D3D9ClientSurface: GetDC() Failed
D3D9: ERROR: Surface name is clbkCreateSurfaceEx Handle=0x244A4600 (512,512)
D3D9: ERROR: Surface Has a Surface Interface
D3D9: ERROR: Surface Is Lockable
D3D9: ERROR: Surface is in a DefaultPool
D3D9: ERROR: Surface has RENDERTARGET usage
D3D9: ERROR: Surface Format is 22
D3D9: ERROR: ActiveFlags( OAPISURFACE_RENDERTARGET )


Now that I went back to HDC no assertion error. Still get the call stack.
 

Attachments

Last edited:
I have looked the log and browsed the source code and I can't find any reason why the GetDC() fails. The surface could be internally locked by the DirectX which might cause external lock request to fail. I don't really know. The HDC is old school so far back that it won't work well in parallel with modern GPU pipelines. Mostly due to multithreading and parallel processing issues. So, mixing HDC with DirectX based drawing calls is a bad idea.

If the next generation graphics client is Vulkan based then HDC won't work for anything else except for MFDs and a like. DirectX 11/12 might allow to continue HDC use but it's highly questionable how well it would work.

It's recommended to move to a Sketchpad from the HDC.

Have you been able to identify from where is the call to GetDC() made ? Is it from within your work or some add-on ? If it's from your own work then translating the part to use sketchpad would likely solve the problem.
 
Thanks. I will convert my HDC to sketchpad. Is there some where info about sketchpad commands? I know when I look at the code and hover it gives some info.
 
So I redid the all the hdc redraw thing. But keep getting a CTD. This needs to be redone. But not sure what it should look like?
void Atlantis::RedrawPanel_MFDButton(SURFHANDLE surf, int mfd) { oapi::Font* font = oapiCreateFont(-11, true, "Arial"); //g_Param.font[0] = CreateFont (-11, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, "Arial"); oapi::Sketchpad* skp = oapiGetSketchpad(surf); skp->SetFont(font); skp->SetTextColor(0x0000FF); skp->SetTextAlign(oapi::Sketchpad::CENTER); if (oapiGetMFDMode(mfd) == MFD_NONE) { RECT r = { 0, 0, 255, 13 }; FillRect(skp, &r, (HBRUSH)GetStockObject(BLACK_BRUSH)); } else { // MFD powered on HFONT pFont = (HFONT)SelectObject(skp); const char* label; int x = 24; for (int bt = 0; bt < 5; bt++) { if (label = oapiMFDButtonLabel(mfd, bt)) { skp->Text( x, 1, label, strlen(label)); x += 42; } else break; } skp->Text(234, 1, "PG", 2); SelectObject(skp, pFont); } oapiReleaseDC(surf, skp); /* HDC hDC = oapiGetDC(surf); // D. Beachy: BUGFIX: if MFD powered off, cover separator lines and do not paint buttons if (oapiGetMFDMode(mfd) == MFD_NONE) { RECT r = { 0, 0, 255, 13 }; FillRect(hDC, &r, (HBRUSH)GetStockObject(BLACK_BRUSH)); } else { // MFD powered on HFONT pFont = (HFONT)SelectObject(hDC, g_Param.font[0]); SetTextColor(hDC, RGB(0, 255, 216)); SetTextAlign(hDC, TA_CENTER); SetBkMode(hDC, TRANSPARENT); const char *label; int x = 24; for (int bt = 0; bt < 5; bt++) { if (label = oapiMFDButtonLabel(mfd, bt)) { TextOut(hDC, x, 1, label, strlen(label)); x += 42; } else break; } TextOut(hDC, 234, 1, "PG", 2); SelectObject(hDC, pFont); } oapiReleaseDC(surf, hDC); */ //oapi::Font* font = oapiCreateFont(40, true, "*Seven Segment"); //oapi::Sketchpad* skp = oapiGetSketchpad(surf); //skp->SetFont(font); //skp->SetTextColor(0x0000FF); //skp->SetTextAlign(oapi::Sketchpad::LEFT); }

From Atlantis :
void Atlantis::RedrawPanel_MFDButton (SURFHANDLE surf, int mfd) { HDC hDC = oapiGetDC (surf); // D. Beachy: BUGFIX: if MFD powered off, cover separator lines and do not paint buttons if (oapiGetMFDMode(mfd) == MFD_NONE) { RECT r = { 0,0,255,13 }; FillRect(hDC, &r, (HBRUSH)GetStockObject(BLACK_BRUSH)); } else { // MFD powered on HFONT pFont = (HFONT)SelectObject (hDC, g_Param.font[0]); SetTextColor (hDC, RGB(0,255,216)); SetTextAlign (hDC, TA_CENTER); SetBkMode (hDC, TRANSPARENT); const char *label; int x = 24; for (int bt = 0; bt < 5; bt++) { if (label = oapiMFDButtonLabel (mfd, bt)) { TextOut (hDC, x, 1, label, strlen(label)); x += 42; } else break; } TextOut (hDC, 234, 1, "PG", 2); SelectObject (hDC, pFont); } oapiReleaseDC (surf, hDC); }
 
Last edited:
This seems to work in normal graphics. In d3d9 though it locks up.
void Atlantis::RedrawPanel_MFDButton(SURFHANDLE surf, int mfd) { oapi::Font* font = oapiCreateFont(-11, true, "Arial"); //g_Param.font[0] = CreateFont (-11, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 0, "Arial"); oapi::Sketchpad* skp = oapiGetSketchpad(surf); //skp->SetTextColor(BBGGRR) skp->SetFont(font); skp->SetTextColor(0x00FF00); skp->SetTextAlign(oapi::Sketchpad::CENTER); if (oapiGetMFDMode(mfd) == MFD_NONE) { RECT r = { 0, 0, 255, 13 }; skp->Rectangle(0, 0, 255, 13); } else { // MFD powered on const char* label; int x = 24; for (int bt = 0; bt < 5; bt++) { if (label = oapiMFDButtonLabel(mfd, bt)) { skp->Text( x, 1, label, strlen(label)); x += 42; } else break; } skp->Text(234, 1, "PG", 2); } oapiReleaseSketchpad(skp); }

D3D9: ERROR: D3D9ClientSurface: GetDC() Failed D3D9: ERROR: Surface name is clbkCreateSurface Handle=0xF58D8E0 (256,36) D3D9: ERROR: Surface Has a Texture Interface D3D9: ERROR: Surface Has a Surface Interface D3D9: ERROR: Surface is in a DefaultPool D3D9: ERROR: Surface has DYNAMIC usage D3D9: ERROR: Surface Format is 22 D3D9: ERROR: Surface Has 1 MipMaps D3D9: ERROR: ActiveFlags( )

oapiGetDC is not in any noncommented code

when I exit the start screen looks like this:

And I get this in the log:

000000.000: D3D9: [Scene Initialized] 000000.000: Finished initialising panels 000023.457: D3D9: [Session Closed. Scene deleted.] 000023.457: D3D9: [Destroy Render Window Called] D3D9: ERROR: [Failed to Reset DirectX Device] (Likely blocked by undeleted resources) 000023.457: **** Closing simulation session
 

Attachments

  • d3d9log2.zip
    d3d9log2.zip
    19.2 KB · Views: 1
  • d3d9screen.jpg
    d3d9screen.jpg
    55.8 KB · Views: 3
Back
Top