Advanced Question Drawing on a texture in VC

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Ok. We have a VC got the mfd screens, and buttons labeled and working:thumbup:.

This is a 3d vc

Next obstacle is we need to draw green bars on the VC to show thrust level, fuel amount,.......

So I look at the Shuttle A Vc code. But even though we have the length set no rectangle is shown.

On the VC mesh the center part is textured with TEX_TESTVC_ENDURANCEVC2A

here is what the mesh looks like.

vctest2_zpsqhckbkou.jpg


and what it looks like in flight

vctest1_zpsnjrgr7m6.jpg

As you can see no bar.

Code:
void TESTVC::clbkPostStep(double simt, double simdt, double mjd)
{
    UpdateCentralStatusMonitor();

}

void TESTVC::UpdateCentralStatusMonitor()
{
    RedrawPanel_Fuelstatus();
}





void TESTVC::RedrawPanel_Fuelstatus()
{
    SURFHANDLE const tex1 = oapiGetTextureHandle(meshhg_VC, TEX_TESTVC_ENDURANCEVC2A);
    HDC const hDC = oapiGetDC(tex1);

    float const m = 55.; //GetThrusterLevel(th_main[0]);
    if (m > 0) {
        float const level = (m);



        // Draws an filled rectangle

        SelectObject(hDC, g_Param.hBrush[1]);//green box
        Rectangle(hDC, 55, 15, 55 + (int)(level * 25.0), 38);
    }
}


---------- Post added 04-27-16 at 05:24 AM ---------- Previous post was 04-26-16 at 04:11 PM ----------

Ok the shuttle A doesn't use a 3d VC. That is what we are are building.

So that center panel I guess is a surface with a textured applied.

Not sure what to do next. I think that surface need to be defined?
 
Last edited:

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,615
Reaction score
2,335
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire

Ok the shuttle A doesn't use a 3d VC.

Wrong - it also has a VC.

Did you check that the texture you want to paint on is dynamic?

Finally did you register a VCRedrawEvent? Your code looks like it does not do so.

Next: Not all textures are made for drawing rectangles and text on. In that case, you need to create your own surface in memory and use this for drawing and finally blit this texture on the target texture.

That is the code in SSU we use for the talkbacks, which has a fair amount of blitting going on.

https://sourceforge.net/p/shuttleul...rbitersdk/Space Shuttle Ultra/vc/Talkback.cpp
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
I meant it didn't have a 3d VC.

Weird I set that textures as dynamic and now it doesn't show

INTERSTELLAR/VESSEL/ENDURANCE/endurancevc2A.dds D

Yes I have this
Code:
bool TESTVC::clbkVCRedrawEvent(int id, int event, SURFHANDLE surf) {
	bool result = false;
	result = result || mfdController->HandleRedrawEvent(id, event, surf);
	//sult = result || LAPTOPTerminalScreen->HandleRedrawEvent(id, event, surf);
//	result = result || HABLAPTOPTerminalScreen->HandleRedrawEvent(id, event, surf);

	result = result || VCRedrawEvent(id, event, surf);
	return result;
}

bool TESTVC::VCRedrawEvent(int const id, int const event, SURFHANDLE const surf) {
	return false;
}
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
You are right about the Shuttle A VC. Not sure why I didn't notice it.

I will look at the code and check to see if the event is register.
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,615
Reaction score
2,335
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
You are right about the Shuttle A VC. Not sure why I didn't notice it.

It isn't a beauty right now. But AFAIR, it was planned to improve it a lot.

(If not, I would love to do this, I love the truck-like functional design of the Shuttle-A)
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
THANKS


On on my center part. It is a rectangle that a texture is applied. So that surface needs to be registered. When I get back to my PC I will check the Shuttle A code. Not sure why it disappeared when I made the texture dynamic, though
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
37,615
Reaction score
2,335
Points
203
Location
Wolfsburg
Preferred Pronouns
Sire
THANKS


On on my center part. It is a rectangle that a texture is applied. So that surface needs to be registered. When I get back to my PC I will check the Shuttle A code. Not sure why it disappeared when I made the texture dynamic, though

One problem you need to remember is, that textures in Orbiter and the clients are typically optimized for fast 3D rendering and not for drawing lines on them. You often need to create a special surface for that, draw everything you need and then copy the pixels of the surface on the target texture.
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks.

Confused. I will look at the code and mesh and see if I get it.

Right now I just want the bars to indicated levels of fuel, thrust


One problem you need to remember is, that textures in Orbiter and the clients are typically optimized for fast 3D rendering and not for drawing lines on them. You often need to create a special surface for that, draw everything you need and then copy the pixels of the surface on the target texture.
 

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
Hi Gattis,this is my code to draw the propellant status,i'm copy to shuttle_A

Code:
void Eagle::RedrawPanel_Fuelstatus (SURFHANDLE surf, int part)
{
	char cbuf[20];
    HDC hDC = oapiGetDC (surf);
	SelectObject (hDC, g_Param.font[2]);	
	SetTextColor (hDC, RGB(224,224,224));
	SetTextAlign (hDC, TA_RIGHT);
	SetBkMode (hDC, TRANSPARENT);
    double m1= GetPropellantMass (ph_hoverr);
    double m2= GetPropellantMass (ph_hoverl);
    double rm1 = GetPropellantFlowrate (ph_hoverr);
    double rm2 = GetPropellantFlowrate (ph_hoverl);

    double r1o1= (rm1/3.61)*2.61;
    double r1o= r1o1/1.45;
    double r1f1= (rm1/3.61);
    double r1f= r1f1/0.79;

    double r2o2= (rm2/3.61)*2.61;
    double r2o= r2o2/1.45;
    double r2f2= (rm2/3.61);
    double r2f= r2f2/0.79;
			  
	if (m1 > 0) {
			SelectObject (hDC, g_Param.brush[0]);
			Rectangle (hDC,  4, 105, 43,(int) ((1.0-m1/MAX_HOVERR_FUEL)*105.0));
                        SelectObject (hDC, g_Param.brush[0]);
			Rectangle (hDC,  52, 105, 90,(int) ((1.0-m1/MAX_HOVERR_FUEL)*105.0));	
			sprintf (cbuf, "%0.2f", r1o);
			TextOut (hDC, 41, 113, cbuf, strlen (cbuf));
			sprintf (cbuf, "%0.2f", r1f);
			TextOut (hDC, 89, 113, cbuf, strlen (cbuf));
                        sprintf (cbuf, "%0.2f", r1o+r1f);
			TextOut (hDC, 65, 155, cbuf, strlen (cbuf)); 			
		}
	if (m2 > 0) {
			SelectObject (hDC, g_Param.brush[0]);
			Rectangle (hDC,  114, 105, 151,(int) ((1.0-m2/MAX_HOVERL_FUEL)*105.0));
                        SelectObject (hDC, g_Param.brush[0]);
			Rectangle (hDC,  161, 105, 199,(int) ((1.0-m2/MAX_HOVERL_FUEL)*105.0));
			sprintf (cbuf, "%0.2f", r2o);
			TextOut (hDC, 150, 113, cbuf, strlen (cbuf));
			sprintf (cbuf, "%0.2f", r2f);
			TextOut (hDC, 198, 113, cbuf, strlen (cbuf));
			sprintf (cbuf, "%0.2f", r2o+r2f);
			TextOut (hDC, 175, 155, cbuf, strlen (cbuf));
			
		}
	oapiReleaseDC (surf, hDC);
}

Code:
bool Eagle::clbkLoadVC (int id)
{

SetCameraOffset (_V(-0.8375505f,1.65612f,4.058297f));
	static VCMFDSPEC mfds_left  = {3, 134};
	static VCMFDSPEC mfds_right = {3, 135}; 
	static VCHUDSPEC hud_pilot  = {3, 254,{-0.8375505,1.65212,4.50},0.35};
	ReleaseSurfaces();
	InitVC (id);

	
	switch (id) {
	case 0: 
                    oapiVCRegisterArea (AID_FUELSTATUS,_R( 1, 28, 206, 267),                                                              PANEL_REDRAW_ALWAYS, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND,tex3);

              }

	
		return true;
}

Code:
bool Eagle::clbkVCRedrawEvent (int id, int event, SURFHANDLE surf)
{

	switch (id) {	
    case AID_FUELSTATUS:
			RedrawPanel_Fuelstatus (surf, id-AID_FUELSTATUS);
			return true;
}
	return false;

}

If it can help


OscgeHQ.jpg
 

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
sorry, it was missing a piece of code :facepalm:

Code:
bool Eagle::clbkLoadVC (int id)
{

SetCameraOffset (_V(-0.8375505f,1.65612f,4.058297f));
	static VCMFDSPEC mfds_left  = {3, 134};
	static VCMFDSPEC mfds_right = {3, 135}; 
	static VCHUDSPEC hud_pilot  = {3, 254,{-0.8375505,1.65212,4.50},0.35};
	ReleaseSurfaces();
	InitVC (id);

	
	switch (id) {
	case 0: 

         SURFHANDLE [COLOR="Red"]tex3[/COLOR] = oapiGetTextureHandle ([COLOR="red"]vcmesh_tpl,14[/COLOR]); 
                    oapiVCRegisterArea (AID_FUELSTATUS,_R( 1, 28, 206, 267),PANEL_REDRAW_ALWAYS, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND,[COLOR="Red"]tex3[/COLOR]);

              }

	
		return true;
}

vcmesh_tpl is the virtual cockpit mesh
14 is the number of texture to draw

Code:
vcmesh_tpl           = oapiLoadMesh ("VCEAGLE");

VCEAGLE.msh

MATERIAL HUD
0.757 0.980 0.761 0.500
0.757 0.980 0.761 0.500
1.000 1.000 1.000 0.500
0 0 0 1
MATERIAL hudglass
0.757 0.980 0.761 0.500
0.757 0.980 0.761 0.500
1.000 1.000 1.000 0.500
0 0 0 1
MATERIAL material02
0.812 0.827 0.937 0.300
0.812 0.827 0.937 0.300
1.000 1.000 1.000 0.300
0 0 0 1
TEXTURES 46
RCSon.dds
RCSoff.dds
TASTIERA1.dds
MFDBUTTON1.dds
hudmode2.dds
hudmode1.dds
SPY2.dds
SPY1.dds
NAVBUTTON2.dds
dysplay05.dds D
dysplay04.dds
dysplay02.dds
dysplay03.dds
dysplay01.dds
BUTTON.dds
...etc

(AID_FUELSTATUS,_R( 1, 28, 206, 267) are the coordinates where you draw
WMH5N80.jpg
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks. So on the vc mesh. do I apply the texture to the center surface. Then get the coordinates from the bitmap.

(0,0,486,302)

then get the area where the green bars should be?
 

Attachments

  • endurancefroncenter.jpg
    endurancefroncenter.jpg
    52.6 KB · Views: 3

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
The texture must be 256 x 256 or 512 x 512

W3Gzz5W.jpg


You go to draw directly on the image in dds format

You must declare AID_FUELSTATUS in .H
Code:
#define AID_FUELSTATUS         115

In clbkLoadVC
Code:
oapiVCRegisterArea (AID_FUELSTATUS,_R( 0,0,486,302),PANEL_REDRAW_ALWAYS, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND,tex3);
Your drawing area inside the texture:
GbuADKZ.jpg


In void TESTVC::RedrawPanel_Fuelstatus()

Your rectangle draw coordinates inside your drawing area
Code:
SelectObject(hDC, g_Param.hBrush[1]);//green box
        Rectangle(hDC, 114, 34, (int) (-level * 25.0), 75);

Your rectangle inside draw area...inside your texture.dds

tODTIte.jpg



In clbkVCRedrawEvent
Code:
clbkVCRedrawEvent (int id, int event, SURFHANDLE surf)
{

	switch (id) {	
    case AID_FUELSTATUS:
			RedrawPanel_Fuelstatus (surf, id-AID_FUELSTATUS);
			return true;
}
	return false;

}
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Thanks.
OK I made the texture 512x512
painted on the mesh

On the code: H:

Code:
#define AID_FUELSTATUS         115
Code:
    void RedrawPanel_Fuelstatus(SURFHANDLE surf, int part);

cpp:
Code:
PROPELLANT_HANDLE tank = CreatePropellantResource(FUELMASS);

    th_main[0] = CreateThruster(_V(0, 0, 0), _V(0, 0, 1), MAXMAINTH, tank, ISP);
    thg_main = CreateThrusterGroup(th_main, 1, THGROUP_MAIN);

Code:
void TESTVC::RedrawPanel_Fuelstatus(SURFHANDLE surf, int part)

{

    char cbuf[20];
    HDC hDC = oapiGetDC(surf);
    
    
    double level = GetPropellantMass(tank);
    


        SelectObject(hDC, g_Param.hBrush[1]);//green box
        Rectangle(hDC, 114, 34, (int)(-level * 25.0), 75);

    



}

Code:
bool TESTVC::clbkLoadVC(int id) { // ID is the Preset Camera Position
    SURFHANDLE const tex3 = oapiGetTextureHandle(meshhg_VC, 5);

    
    
    mfdController->HandleLoadVC(id);    
    oapiVCRegisterArea(AID_FUELSTATUS, _R(0, 0, 486, 302), PANEL_REDRAW_ALWAYS, PANEL_MOUSE_IGNORE, PANEL_MAP_BACKGROUND, tex3);


    return HandleLoadVC(id);
}

Code:
bool TESTVC::clbkVCRedrawEvent(int id, int event, SURFHANDLE surf) {
    //bool result = false;
    //result = result || mfdController->HandleRedrawEvent(id, event, surf);
    //sult = result || LAPTOPTerminalScreen->HandleRedrawEvent(id, event, surf);
//    result = result || HABLAPTOPTerminalScreen->HandleRedrawEvent(id, event, surf);

    //result = result || VCRedrawEvent(id, event, surf);
    {

        switch (id) {
        case AID_FUELSTATUS:
            RedrawPanel_Fuelstatus(surf, id - AID_FUELSTATUS);
            return true;
        }
        return false;

    }
    //return result;
}

bool TESTVC::VCRedrawEvent(int const id, int const event, SURFHANDLE const surf) {
    return false;
}



But I see no bar. What is odd if I have the bar show thrust level no ctd but with fuel level I get a ctd.

Well also now the mfd button labels are showing up. that is controlled by mfdcontroller

I can post all the code or email it to you
 
Last edited:

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
Missing this in the code?

Code:
void TESTVC::RedrawPanel_Fuelstatus(SURFHANDLE surf, int part)

{

    char cbuf[20];
    HDC hDC = oapiGetDC(surf);
    
    
   // double level = GetPropellantMass(tank);
    [COLOR="Red"] double level = GetThrusterLevel(th_main);[/COLOR]
    


        SelectObject(hDC, g_Param.hBrush[1]);//green box
        Rectangle(hDC, 114, 34, (int)(-level * 25.0), 75);

    
         [COLOR="Red"]oapiReleaseDC (surf, hDC);[/COLOR]


}
 

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Ok will add that. So does that get the thrust level, propellant mass or do I need to call that RedrawPanel_Fuelstatus(SURFHANDLE surf, int part) in the poststep?
 

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
Ok will add that. So does that get the thrust level, propellant mass or do I need to call that RedrawPanel_Fuelstatus(SURFHANDLE surf, int part) in the poststep?

does not serve poststep call, you can also put propellant mass or what you want ...

Changing the coordinates of the rectangle you can draw more parameters in the same area
 
Last edited:

gattispilot

Addon Developer
Addon Developer
Joined
Oct 17, 2007
Messages
8,707
Reaction score
2,683
Points
203
Location
Dallas, TX
Ok it draw, yeah. Still issues. When no thrust is applied the box is on the left. If I slowly apply thust the box goes to the right all the way.

The staring point is 110 and ending point should 346

Code:
void TESTVC::RedrawPanel_Fuelstatus(SURFHANDLE surf, int part)

{
	//SURFHANDLE const tex3 = oapiGetTextureHandle(meshhg_VC,5 );
	char cbuf[20];
	HDC hDC = oapiGetDC(surf);
	
	
	double level = GetThrusterLevel(th_main[0]);
	//double level2 = GetPropellantMass(tank);

		SelectObject(hDC, g_Param.hBrush[1]);//green box
		Rectangle(hDC, 114, 34, (int)(level * 346.0), 75);

		oapiReleaseDC(surf, hDC);


}

it I uncomment //double level2 = GetPropellantMass(tank);

I get a CTD.

h:
Code:
PROPELLANT_HANDLE tank;

cpp:
Code:
// propellant resources
	PROPELLANT_HANDLE tank = CreatePropellantResource(FUELMASS);

	th_main[0] = CreateThruster(_V(0, 0, 0), _V(0, 0, 1), MAXMAINTH, tank, ISP);
	thg_main = CreateThrusterGroup(th_main, 1, THGROUP_MAIN);




So the next big step is I want to add nav status lights. So when Horizon level is pressed the light lights up.
 

Attachments

  • VCTHRUST.jpg
    VCTHRUST.jpg
    59.7 KB · Views: 10
Last edited:

marcogavazzeni

Addon Developer
Addon Developer
Joined
Jan 5, 2009
Messages
219
Reaction score
0
Points
16
Location
Near Verona
Website
orbiteritalia.forumotion.com
Delete propellant handle

cpp:
Code:
// propellant resources
	tank = CreatePropellantResource(FUELMASS);

	th_main[0] = CreateThruster(_V(0, 0, 0), _V(0, 0, 1), MAXMAINTH, tank, ISP);
	thg_main = CreateThrusterGroup(th_main, 1, THGROUP_MAIN);

So the next big step is I want to add nav status lights. So when Horizon level is pressed the light lights up.


Code:
if (GetNavmodeState(2)==true){
		spotlight1->Activate(true);
                 beacon[1].active = true;
		}else{ 
	spotlight1->Activate(false);
        beacon[1].active = false;
	}
 
Top