General Question VESSEL and MFD in a single project?

wingnut

Donator
Donator
Joined
May 10, 2013
Messages
129
Reaction score
0
Points
16
Yes, the basic principle of this method is understood now but I'm still struggling to get something displayed correctly.

Currently I'm trying
Code:
int surfW = 256; int surfH = 256;
SURFHANDLE surf = oapiCreateSurface(surfW, surfH);
oapi::Sketchpad *skp = oapiGetSketchpad(surf);
skp->Text(10,50, "Hello World", 11);
oapiReleaseSketchpad(skp);
oapiBlt(panel2dtex, surf, 0, 0, 0, 0, surfW, surfH);

The result is attached as a screenshot.

Does the SURFHANDLE surf need to be manipulated in any other way for this to work?

Also do I need to assign a TextColor, Pen etc. for the Sketchpad for it to work or does it have default settings for that?
 

Attachments

  • 2dpanel.jpg
    2dpanel.jpg
    7.5 KB · Views: 23

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
The screenshot's too small, I can't recognise anything. What I'm pretty sure of, though, is that 256 pixels is too small an area to print "Hello world" on in any readable font, and I'm not sure what sketchpad does when a drawing call goes outside the surface.
 

wingnut

Donator
Donator
Joined
May 10, 2013
Messages
129
Reaction score
0
Points
16
Oh, okay - I've attached the screenshot in its original size.

When the size of the surface is set to the same size as the 2d panel's background texture then only the complete gray background texture seems to be displayed without any text on it.
 

Attachments

  • panel2d.png
    panel2d.png
    63.7 KB · Views: 21

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
The screenshot's too small, I can't recognise anything. What I'm pretty sure of, though, is that 256 pixels is too small an area to print "Hello world" on in any readable font, and I'm not sure what sketchpad does when a drawing call goes outside the surface.

The under normal circumstances the draw command should return "Null" and nothing happens.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
When the size of the surface is set to the same size as the 2d panel's background texture then only the complete gray background texture seems to be displayed without any text on it.

I need more context. Namely, where the code you posted above is located, and what calls it. Also, are the visible autopilot buttons part of the background texture, or are you also blitting other stuff?
 

wingnut

Donator
Donator
Joined
May 10, 2013
Messages
129
Reaction score
0
Points
16
The code is contained in function DefineMainPanel

DefineMainPanel is called from clbkLoadPanel2D

clbkLoadPanel2D is a function of my vessels's class which is derived from VESSEL3
Code:
SURFHANDLE MyVessel::panel2dtex = NULL;

bool MyVessel::clbkLoadPanel2D (int id, PANELHANDLE hPanel, DWORD viewW, DWORD viewH) {
	switch (id) {
		case 0: 
		DefineMainPanel (hPanel);
		ScalePanel (hPanel, viewW, viewH);
		return true;
		default:
		return false;
	}
}

void MyVessel::DefineMainPanel(PANELHANDLE hPanel) {
	static DWORD panelW = 1280;
	static DWORD panelH =  300;
	float fpanelW = (float)panelW;
	float fpanelH = (float)panelH;
	static DWORD texW = 2048;
	static DWORD texH = 512;
	float ftexW = (float) texW;
	float ftexH = (float) texH;
	static NTVERTEX VTX[4] = {
		{      0,      0,0,   0,0,0,            0.0f,1.0f-fpanelH/ftexH},
		{      0,fpanelH,0,   0,0,0,            0.0f,1.0f              },
		{fpanelW,fpanelH,0,   0,0,0,   fpanelW/ftexW,1.0f              },
		{fpanelW,      0,0,   0,0,0,   fpanelW/ftexW,1.0f-fpanelH/ftexH}
	};
	static WORD IDX[6] = {
		0,2,1,
		2,0,3
	};

	if (hPanelMesh) oapiDeleteMesh (hPanelMesh);
	hPanelMesh = oapiCreateMesh (0,0);
	MESHGROUP grp = {VTX, IDX, 4, 6, 0, 0, 0, 0, 0};
	oapiAddMeshGroup (hPanelMesh, &grp);
	SetPanelBackground (hPanel, &panel2dtex, 1, hPanelMesh, panelW, panelH, 0, PANEL_ATTACH_BOTTOM | PANEL_MOVEOUT_BOTTOM);

	// sketchpad test
	int surfW = 1024; int surfH = 800;
	SURFHANDLE surf = oapiCreateSurface(surfW, surfH);
	oapi::Sketchpad *skp = oapiGetSketchpad(surf);
	
	skp->Text(10,50, "Hello World", 11);
	oapiReleaseSketchpad(skp);
	oapiBlt(panel2dtex, surf, 256, 256, 0, 0, surfW, surfH);
	
}

void MyVessel::ScalePanel (PANELHANDLE hPanel, DWORD viewW, DWORD viewH)
{
	double defscale = (double)viewW/1280.0;
	double magscale = max (defscale, 1.0);
	SetPanelScaling (hPanel, defscale, magscale);
}

DLLCLBK void InitModule(HINSTANCE hModule) {
	MyVessel::panel2dtex = oapiLoadTexture ("MyVessel\\panel2d.dds");
}
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,883
Reaction score
2,135
Points
203
Location
between the planets
Sorry for the late reply, having a really busy time here currently.

clbkLoadPanel2D is only called when a panel is initialised. Calls to drawing operations must be put into clbkPanelRedrawEvent(). Which of course means that the whole thing should be designed in a panel element to begin with. It's a bit complicated and somewhat counterintuitive, and I don't have much time to wite right now. Look good at the tutorial you used so far, take its panel element class and modify to your needs, that's about all the advice I can give for now.
 
Top