Problem D3D9 HUD Sketchpad Issue

tl8

Addon Developer
Addon Developer
Tutorial Publisher
Joined
Oct 16, 2007
Messages
3,645
Reaction score
25
Points
88
Location
Gold Coast QLD
I am having an issue with the HUD on my Aircraft Tug.

It works well in the default in-line client, however when I move to the D3D9 client, the pens don't work correctly. I am not sure what the exact issue is though.

Any help would be appreciated.

D3D9:


In-Line:


Code:
Code:
bool JBT_B1200::clbkDrawHUD  ( int  mode, const HUDPAINTSPEC *  hps, oapi::Sketchpad *  skp)
{
    
    //VESSEL3::clbkDrawHUD (mode, hps, skp);
    
    //oapiSetHUDMode(HUD_NONE);
    //oapiOpenMFD(MFD_NONE,MFD_LEFT);
    //oapiOpenMFD(MFD_NONE,MFD_RIGHT);

    


    skp->SetOrigin(0,0);

    oapi::Pen* pOrgPen;

    int rightThirdCentreX = hps->W/6*5;
    int rightThirdCentreY = hps->H/2;

    
    oapi::Font* speedoFont = oapiCreateFont(30,true,"Sans",(FontStyle)(oapi::Font::BOLD));
    oapi::Font*    infoFont = oapiCreateFont(20,true,"Sans",(FontStyle)(oapi::Font::BOLD));
    oapi::Font* indicatorFont =oapiCreateFont(50,true,"Sans",(FontStyle)(oapi::Font::BOLD));

    //Problem below here?
    oapi::Pen* needleRedPen = oapiCreatePen(1,4,0x0000CC);
    //oapi::Pen* infoPen = oapiCreatePen(1,8,0x00CCCC);
    
    
    oapi::Pen* infoPen[4];

    /*
    infoPen[0]= oapiCreatePen(1,4,0x0000CC);
    infoPen[1]= oapiCreatePen(1,4,0x0000CC);
    infoPen[2]= oapiCreatePen(1,4,0x0000CC);
    infoPen[3]= oapiCreatePen(1,4,0x0000CC);
    */
    infoPen[0]= oapiCreatePen(1,4,B1200_HUDCOLOURS[0]);
    infoPen[1]= oapiCreatePen(1,4,B1200_HUDCOLOURS[1]);
    infoPen[2]= oapiCreatePen(1,4,B1200_HUDCOLOURS[2]);
    infoPen[3]= oapiCreatePen(1,4,B1200_HUDCOLOURS[3]);

    //Draw our 4 Letter inicators Lights, Strobe, Park, Gear
    int letterX = rightThirdCentreX + 100;
    int letterX1 = letterX + 50;
    
    
    

    
    int RX1 = letterX - 25;
    int RX2 = letterX1 + 10;
    int RX = (RX1+RX2)/2;
    int RDist = (RX2-RX1)/3*2;

    //oapi::Pen* rectPen = oapiCreatePen(1,RDist,0x666666);

    int RY1 = rightThirdCentreY - 150;
    int RY2 = rightThirdCentreY + 50;
    
    //--------------------------------------------
    //Indicator Lights
    //--------------------------------------------
    {
    
    skp->SetFont(indicatorFont);
        
    //pOrgPen = skp->SetPen(rectPen);
    //skp->Line(RX,RY1,RX,RY2);

    int letterY = rightThirdCentreY - 150;
    int letterY1 = letterY + 50;

    if(indicators[0]) {
        //Headlight
        skp->SetBackgroundMode(skp->BK_OPAQUE);
        skp->SetBackgroundColor(0xFF0000);
        skp->SetTextColor(0xFFFFFF);
        skp->TextBox(letterX,letterY,letterX1,letterY1,"H",1);
        }//if Headlights
    else {
        skp->SetBackgroundMode(skp->BK_OPAQUE);
        skp->SetBackgroundColor(0x000000);
        skp->SetTextColor(0xFF0000);
        skp->TextBox(letterX,letterY,letterX1,letterY1,"H",1);
    }//else Headlights

    letterY = rightThirdCentreY - 100;
    letterY1 = letterY + 50;

    if(indicators[1]) {
        //Warning / Flash
        skp->SetBackgroundMode(skp->BK_OPAQUE);
        skp->SetBackgroundColor(0x0066FF);
        skp->SetTextColor(0xFFFFFF);
        skp->TextBox(letterX,letterY,letterX1,letterY1,"F",1);
        }//if Warning / Flash
    else {
        skp->SetBackgroundMode(skp->BK_OPAQUE);
        skp->SetBackgroundColor(0x000000);
        skp->SetTextColor(0x0066FF);
        skp->TextBox(letterX,letterY,letterX1,letterY1,"F",1);
    }//else Warning / Flash

    letterY = rightThirdCentreY - 50;
    letterY1 = letterY + 50;

    if(indicators[2]) {
        //Park Brake
        skp->SetBackgroundMode(skp->BK_OPAQUE);
        skp->SetBackgroundColor(0x0000FF);
        skp->SetTextColor(0xFFFFFF);
        skp->TextBox(letterX,letterY,letterX1,letterY1,"P",1);
        }//if Park Brake
    else {
        skp->SetBackgroundMode(skp->BK_OPAQUE);
        skp->SetBackgroundColor(0x000000);
        skp->SetTextColor(0x0000FF);
        skp->TextBox(letterX,letterY,letterX1,letterY1,"P",1);
    }//else Park Brake

    letterY = rightThirdCentreY + 0;
    letterY1 = letterY + 50;

    skp->SetBackgroundMode(skp->BK_TRANSPARENT);
    //skp->SetBackgroundColor(0x000000);
    skp->SetTextColor(0x00FF00);
    switch (transmission) {
        case 2: skp->TextBox(letterX,letterY,letterX1,letterY1,"L",1);
                break;
        case 1: skp->TextBox(letterX,letterY,letterX1,letterY1,"D",1);
                break;
        case 0: skp->TextBox(letterX,letterY,letterX1,letterY1,"N",1);
                break;
        case -1: skp->TextBox(letterX,letterY,letterX1,letterY1,"R",1);
                break;
    }//switch
    
    }//Indicator
    
    

    //--------------------------------------------
    //Speedo
    //--------------------------------------------
    {
    //Set the pen to draw the arc
    
    pOrgPen =    skp->SetPen(infoPen[HudColour]);
    //Set centre
    int dialX = rightThirdCentreX, dialY = rightThirdCentreY;
    
    //Set intial conditions
    double radius, angle1, angle2;
    radius = 200;
    angle1 = 195 * RAD;
    angle2 = 75 * RAD;
    int x1 = 0,y1 = 0,x2 = 0,y2 = 0;
    
    //Run through the arc and draw it
    for(double i = angle1; i > angle2; i -= 0.01){
        x1 = (int)(-sin(i)*radius + 0.5 + dialX);
        y1 = (int)(cos(i)*radius + 0.5 + dialY);
        skp->Line(x1,y1,x1,y1);
    }//for
    
    //Interval Markings
    //Here No. is 6 with 5 spaces
    double interval = (angle1 - angle2)/5;
    double angle;
    
    //For the Text display
    int x3,y3;
    char* speedo[6] = {"25","20","15","10","5","0"};
    skp->SetTextAlign(skp->CENTER,skp->TOP);
    
    //Set font for Text
    skp->SetFont(speedoFont);
    skp->SetTextColor(B1200_HUDCOLOURS[HudColour]);

    //Draw text and markers at correct spots
    for(int i = 0; i <= 5; i++){
        angle = angle1 - interval*i;
        x1 = (int)(-sin(angle)*radius + 0.5 + dialX);
        y1 = (int)(cos(angle)*radius + 0.5 + dialY);
        x2 = (int)(-sin(angle)*radius*0.9 + 0.5 + dialX);
        y2 = (int)(cos(angle)*radius*0.9 + 0.5 + dialY);
        x3 = (int)(-sin(angle)*radius*0.8 + 0.5 + dialX);
        y3 = (int)(cos(angle)*radius*0.8 + 0.5 + dialY);
        skp->Text(x3,y3,speedo[i],2);
        skp->Line(x1,y1,x2,y2);
    }//for
    
    //Draw Title
    x3 = (int)(-sin(PI/4*3)*radius*0.4 + 0.5 + dialX);
    y3 = (int)(cos(PI/4*3)*radius*0.4 + 0.5 + dialY);
    skp->Text(x3,y3,"Km/h",4);
    skp->SetTextAlign(skp->LEFT,skp->TOP);

    //Set pen for Needle
    skp->SetPen(needleRedPen);
    
    //Calculate deflection of needle
    double speedRatio = 0;
    //if (currentSpeed > 0)
        speedRatio = (fabs(currentSpeed)/B1200_MAXSPEED);

    angle = (angle1 - angle2)*speedRatio + angle2;
    
    //Draw needle
    x1 = (int)(-sin(angle)*radius*0.95 + 0.5 + dialX);
    y1 = (int)(cos(angle)*radius*0.95 + 0.5 + dialY);
    skp->Line(x1,y1,dialX,dialY);

    }//Speedo

    //--------------------------------------------
    //Rev Counter
    //--------------------------------------------
    {
    //Set the pen to draw the arc

    skp->SetPen(infoPen[HudColour]);
    
    //Set centre
    int dialX = rightThirdCentreX - 160, dialY = rightThirdCentreY + 200;
    
    //Set intial conditions
    double radius, angle1, angle2;
    radius = 100;
    angle1 = 135 * RAD;
    angle2 = 240 * RAD;
    int x1 = 0,y1 = 0,x2 = 0,y2 = 0;
    
    //Interval Markings
    //Here No. is 6 with 5 spaces
    double interval = (angle1 - angle2)/5;
    double angle;
    
    //For the Text display
    int x3,y3;
    char* rev[6] = {"0","5","10","15","20","25"};
    skp->SetTextAlign(skp->CENTER,skp->TOP);
    
    //Set font for Text
    skp->SetFont(infoFont);
    skp->SetTextColor(B1200_HUDCOLOURS[HudColour]);

    //Draw text and markers at correct spots
    for(int i = 0; i <= 5; i++){
        angle = angle1 - interval*i;
        x1 = (int)(-sin(angle)*radius + 0.5 + dialX);
        y1 = (int)(cos(angle)*radius + 0.5 + dialY);
        x2 = (int)(-sin(angle)*radius*0.9 + 0.5 + dialX);
        y2 = (int)(cos(angle)*radius*0.9 + 0.5 + dialY);
        x3 = (int)(-sin(angle)*radius*0.8 + 0.5 + dialX);
        y3 = (int)(cos(angle)*radius*0.8 + 0.5 + dialY);
        skp->Text(x3,y3,rev[i],2);
        skp->Line(x1,y1,x2,y2);
    }//for
    
    //Draw Title
    x3 = (int)(-sin(PI)*radius*0.4 + 0.5 + dialX);
    y3 = (int)(cos(PI)*radius*0.4 + 0.5 + dialY);
    skp->Text(x3,y3,"x100 RPM",8);
    skp->SetTextAlign(skp->LEFT,skp->TOP);

    //Set pen for Needle
    skp->SetPen(needleRedPen);
    
    //Calculate deflection of needle
    angle = (angle2 - angle1)*(engineRPM/2500) + angle1;
    
    //Draw needle
    x1 = (int)(-sin(angle)*radius*0.95 + 0.5 + dialX);
    y1 = (int)(cos(angle)*radius*0.95 + 0.5 + dialY);
    skp->Line(x1,y1,dialX,dialY);

    }

    //--------------------------------------------
    //Steering Indicator
    //--------------------------------------------
    {
    //Set the pen to draw the arc
    skp->SetPen(infoPen[HudColour]);
    
    //Set centre
    int dialX = rightThirdCentreX, dialY = rightThirdCentreY + 200;
    
    //Set intial conditions
    double radius, angle1, angle2;
    radius = 100;
    angle1 = 135 * RAD;
    angle2 = 225 * RAD;
    int x1 = 0,y1 = 0,x2 = 0,y2 = 0;
    
    //Interval Markings
    //Here No. is 5 with 4 spaces
    double interval = (angle1 - angle2)/4;
    double angle;
    
    //For the Text display
    int x3,y3;
    char* rev[5] = {"20","10","0","10","20"};
    skp->SetTextAlign(skp->CENTER,skp->TOP);
    
    //Set font for Text
    skp->SetFont(infoFont);
    skp->SetTextColor(B1200_HUDCOLOURS[HudColour]);

    //Draw text and markers at correct spots
    for(int i = 0; i <= 4; i++){
        angle = angle1 - interval*i;
        x1 = (int)(-sin(angle)*radius + 0.5 + dialX);
        y1 = (int)(cos(angle)*radius + 0.5 + dialY);
        x2 = (int)(-sin(angle)*radius*0.9 + 0.5 + dialX);
        y2 = (int)(cos(angle)*radius*0.9 + 0.5 + dialY);
        x3 = (int)(-sin(angle)*radius*0.8 + 0.5 + dialX);
        y3 = (int)(cos(angle)*radius*0.8 + 0.5 + dialY);
        skp->Text(x3,y3,rev[i],2);
        skp->Line(x1,y1,x2,y2);
    }//for
    
    //Draw Title
    x3 = (int)(-sin(PI)*radius*0.4 + 0.5 + dialX);
    y3 = (int)(cos(PI)*radius*0.4 + 0.5 + dialY);
    skp->Text(x3,y3,"Degrees",7);
    skp->SetTextAlign(skp->LEFT,skp->TOP);

    //Set pen for Needle
    skp->SetPen(needleRedPen);
    
    //Calculate deflection of needle
    angle = -(angle1 - angle2)*GetControlSurfaceLevel(AIRCTRL_RUDDER)/2 + PI;
    
    //Draw needle
    x1 = (int)(-sin(angle)*radius*0.95 + 0.5 + dialX);
    y1 = (int)(cos(angle)*radius*0.95 + 0.5 + dialY);
    skp->Line(x1,y1,dialX,dialY);


    }
    //--------------------------------------------
    //Fuel Level
    //--------------------------------------------
    {
    //Set the pen to draw the arc
    skp->SetPen(infoPen[HudColour]);
    //skp->SetPen(infoPen);
    //Set centre
    int dialX = rightThirdCentreX + 160, dialY = rightThirdCentreY + 200;
    
    //Set intial conditions
    double radius, angle1, angle2;
    radius = 100;
    angle1 = 135 * RAD;
    angle2 = 225 * RAD;
    int x1 = 0,y1 = 0,x2 = 0,y2 = 0;
    
    //Interval Markings
    //Here No. is 5 with 4 spaces
    double interval = (angle1 - angle2)/4;
    double angle;
    
    //For the Text display
    int x3,y3;
    char* rev[5] = {"E"," "," "," ","F"};
    skp->SetTextAlign(skp->CENTER,skp->TOP);
    
    //Set font for Text
    skp->SetFont(infoFont);
    skp->SetTextColor(B1200_HUDCOLOURS[HudColour]);

    //Draw text and markers at correct spots
    for(int i = 0; i <= 4; i++){
        angle = angle1 - interval*i;
        x1 = (int)(-sin(angle)*radius + 0.5 + dialX);
        y1 = (int)(cos(angle)*radius + 0.5 + dialY);
        x2 = (int)(-sin(angle)*radius*0.9 + 0.5 + dialX);
        y2 = (int)(cos(angle)*radius*0.9 + 0.5 + dialY);
        x3 = (int)(-sin(angle)*radius*0.8 + 0.5 + dialX);
        y3 = (int)(cos(angle)*radius*0.8 + 0.5 + dialY);
        skp->Text(x3,y3,rev[i],2);
        skp->Line(x1,y1,x2,y2);
    }//for
    
    //Draw Title
    x3 = (int)(-sin(PI)*radius*0.4 + 0.5 + dialX);
    y3 = (int)(cos(PI)*radius*0.4 + 0.5 + dialY);
    skp->Text(x3,y3,"Fuel",4);
    skp->SetTextAlign(skp->LEFT,skp->TOP);

    //Set pen for Needle
    skp->SetPen(needleRedPen);
    
    //Calculate deflection of needle
    angle = (angle2 - angle1)*fuel/B1200_FUELMASS + angle1;
    
    //Draw needle
    x1 = (int)(-sin(angle)*radius*0.95 + 0.5 + dialX);
    y1 = (int)(cos(angle)*radius*0.95 + 0.5 + dialY);
    skp->Line(x1,y1,dialX,dialY);

    }

    //--------------------------------------------
    //Attachment Text
    //--------------------------------------------
    {
    int leftThirdCentreX = hps->W/6;
    int leftThirdCentreY = hps->H/2 - 60;
    int lineoffset = 30;

    skp->SetFont(infoFont);
    skp->SetTextAlign(skp->LEFT,skp->TOP);
    
    int x = leftThirdCentreX, y = leftThirdCentreY;
    skp->Text(x,y,"Vessel Attached:",16);
    
    y = leftThirdCentreY + 2 * lineoffset;
    skp->Text(x,y,"Towbar Attached to:",16);
    
    char vesselName[32];

    switch (JBT_B1200::mode) {
        case -2 :    y = leftThirdCentreY + lineoffset;
                    
                    oapiGetObjectName(GetAttachmentStatus(back),vesselName,32); 
                    skp->Text(x,y,vesselName,32);
                    y = leftThirdCentreY + 3*lineoffset;
                    skp->Text(x,y,"Rear",4);
                    break;

        case -1 :    y = leftThirdCentreY + lineoffset;
                    skp->Text(x,y,"None",4);
                    y = leftThirdCentreY + 3*lineoffset;
                    skp->Text(x,y,"Rear",4);
                    break;

        case 0 :    y = leftThirdCentreY + lineoffset;
                    skp->Text(x,y,"None",4);
                    y = leftThirdCentreY + 3*lineoffset;
                    skp->Text(x,y,"None",4);
                    break;

        case 1 :    y = leftThirdCentreY + lineoffset;
                    skp->Text(x,y,"None",4);
                    y = leftThirdCentreY + 3*lineoffset;
                    skp->Text(x,y,"Front",5);
                    break;

        case 2 :    y = leftThirdCentreY + lineoffset;
                    oapiGetObjectName(GetAttachmentStatus(front),vesselName,32); 
                    skp->Text(x,y,vesselName,32);
                    y = leftThirdCentreY + 3*lineoffset;
                    skp->Text(x,y,"Front",5);
                    break;
        }//switch

    }//AttachmentInfo
    
    // UMmu display messages
    if(dHudMessageDelay>0)
    {
        skp->Text(5,hps->H/60*15,cUmmuHudDisplay,strlen(cUmmuHudDisplay));
        dHudMessageDelay-=oapiGetSimStep();
        if(dHudMessageDelay<0)
            dHudMessageDelay=0;
    }

    skp->SetPen(pOrgPen);

    //Cleanup
    oapiReleaseFont(infoFont);
    oapiReleaseFont(speedoFont);
    oapiReleaseFont(indicatorFont);//Remove our previously created font

    oapiReleasePen(needleRedPen);
    //oapiReleasePen(rectPen);//Remove our Pen
    
    //oapiReleasePen(infoPen);
    oapiReleasePen(infoPen[0]);
    oapiReleasePen(infoPen[1]);
    oapiReleasePen(infoPen[2]);
    oapiReleasePen(infoPen[3]);
    

    
    

    return true;
}

D3D9.cfg
Code:
FrameRate = 200
EnableLimiter = 0
PlanetPreloadMode = 0
PlanetTexLoadFreq = 20
Anisotrophy = 8
SceneAntialias = 4
SketchpadMode = 1
SketchpadFont = 0
PreLoadBaseVisuals = 0
EnableNormalMapping = 1
NearClipPlaneMode = 0
RwyLightAnimate = 1
RwyLightAngle = 120
RwyBrightness = 1.8
NightLightsAngle = 10
BumpMapAmplitude = 1
PlanetGlow = 1.1
EnvMapSize = 512
EnvMapMode = 1
EnvMapFaces = 1
ShadowMapMode = 1
ShadowMapSize = 1024
EnableGlass = 1
EnableMeshDbg = 1
StereoSeparation = 65
StereoConvergence = 0.2
Shaders = Default
DebugLvl = 1
VCNearPlane = 0.1
LightSourcesInUse = 12
MemAllocLogic = 0
DisableDrvMgm = 0
NVPerfHUD = 0
RejectRTDC = 0
DebugLineFontSize = 18
GDIRTSDebug = 0
LoadTexturesInSystemMem = 0
ManagedTiles = 0
DisableVisualHelperReadout = 0
SolCfg = Sol
DebugLineFont = Fixed
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,666
Reaction score
795
Points
128
The D3D9Client doesn't support pen width option, therefore, only a hair lines are drawn. I don't know about the missing arcs and letters. It might work if you set Sketchpad device to "GDI only" and you enable "GDI compatibility mode". But it won't help much.

Code:
//Run through the arc and draw it
    for(double i = angle1; i > angle2; i -= 0.01){
        x1 = (int)(-sin(i)*radius + 0.5 + dialX);
        y1 = (int)(cos(i)*radius + 0.5 + dialY);
        skp->Line(x1,y1,x1,y1);
    }//for

This ain't drawing anything. Shouldn't it be something like skp->Line(x1,y1,x2,y2). But still need to initialize x2, y2 properly.
 

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,216
Reaction score
1,562
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
BTW pen widths work for me on the XR HUD using D3D9 R12, at least. Code is:

Code:
oapi::Pen *pNewPen = oapiCreatePen(1, Get2DHUDGearIndicatorPenWidth(), hudColor);
oapi::Pen *pOrgPen = skp->SetPen(pNewPen);

// render the gear indicators
skp->Rectangle (cx-(d/2), cy-(d*5), cx+(d/2), cy-(d*4));
skp->Rectangle (cx-(d*3), cy-(d*2), cx-(d*2), cy-d);
skp->Rectangle (cx+(d*2), cy-(d*2), cx+(d*3), cy-d);
...
// free the new pen
oapiReleasePen(pNewPen);

// restore the previous pen
skp->SetPen(pOrgPen);

...where Get2DHUDGearIndicatorPenWidth() returns either 3 (for 1280-pixel-wide panels) or 4 (for larger panel sizes). I tested it by hotwiring pen width to 8 as well.
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,666
Reaction score
795
Points
128
BTW pen widths work for me on the XR HUD using D3D9 R12, at least. Code is:

Rectangle() is the only exception where it works.
 

tl8

Addon Developer
Addon Developer
Tutorial Publisher
Joined
Oct 16, 2007
Messages
3,645
Reaction score
25
Points
88
Location
Gold Coast QLD
Thanks jarmonik for your feedback.

Now I know where I stand.

FWIIW, that for loop outputs the speedo arc. It worked in the in-line client and that was when it was first developed.

I am going to develop a VC to solve the problem.

I'll make a stop gap solution until that is done.
 

Enjo

Mostly harmless
Addon Developer
Tutorial Publisher
Donator
Joined
Nov 25, 2007
Messages
1,665
Reaction score
13
Points
38
Location
Germany
Website
www.enderspace.de
Preferred Pronouns
Can't you smell my T levels?
Just do
Line(x1,y1,x1+1,y1+1);
 
Top