Problem Panel loading problems (following Martin's tutorial)

Izack

Non sequitur
Addon Developer
Joined
Feb 4, 2010
Messages
6,665
Reaction score
13
Points
113
Location
The Wilderness, N.B.
I'm following Martin's tutorial here on how to implement a 2D panel. I've finished part 1 and have tried to compile and test the panel (right now, solid yellow rectangle.) Obviously it went sour or I wouldn't be here.

What I've made is basically a copy and paste of the example code in the tutorial, plus the Carina mesh. It crashes on pressing F8 in the cockpit to bring up the panel, while calling DefineMainPanel (debugger breaks on line 76.)

Here is what I have for this experiment (Texture, config file, module, scenario):
https://dl.dropboxusercontent.com/u/26163846/devshots/Ptest.zip

Here is the complete code:
Code:
#include "Orbitersdk.h"

class Ptest: public VESSEL3
{
public:
	Ptest (OBJHANDLE hVessel, int flightmodel);
	~Ptest();
	void clbkSetClassCaps(FILEHANDLE cfg);

	MESHHANDLE hPanelMesh;
	static SURFHANDLE panel2dtex;
	bool clbkLoadPanel2D(int id, PANELHANDLE hPanel, DWORD viewW, DWORD viewH);
	void DefineMainPanel(PANELHANDLE hPanel);
	void ScalePanel(PANELHANDLE hPanel, DWORD viewW, DWORD viewH);
private:
};

Ptest::Ptest (OBJHANDLE hVessel, int flightmodel)
	: VESSEL3 (hVessel, flightmodel)
{
	hPanelMesh = NULL;
}

Ptest::~Ptest()
{
	if (hPanelMesh) oapiDeleteMesh (hPanelMesh);
}

SURFHANDLE Ptest::panel2dtex = NULL;

void Ptest::clbkSetClassCaps(FILEHANDLE cfg)
{
	SetSize(1);
	AddMesh("Carina",0);
}

bool Ptest::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 Ptest::DefineMainPanel(PANELHANDLE hPanel)
{
	static DWORD panelW = 1280;
	static DWORD panelH =  400;
	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);
}

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

DLLCLBK VESSEL *ovcInit (OBJHANDLE hvessel, int flightmodel)
{
	return new Ptest (hvessel, flightmodel);
	Ptest::panel2dtex = oapiLoadTexture("Test\\panel2d.dds");
}

DLLCLBK void ovcExit (VESSEL *vessel)
{
	if (vessel) delete (Ptest*)vessel;
	oapiDestroySurface(Ptest::panel2dtex);
}

/*DLLCLBK void InitModule(HINSTANCE hModule)
{
	Ptest::panel2dtex = oapiLoadTexture("Test\\panel2d.dds");
}

DLLCLBK void ExitModule(HINSTANCE hModule)
{
	oapiDestroySurface(Ptest::panel2dtex);
}*/

Any help is appreciated.

P.S. This is carrying over from the chatbox, to not interrupt other conversation and possibly for posterity.

---------- Post added at 06:33 PM ---------- Previous post was at 06:22 PM ----------

And naturally it's solved right after I waste a thread on it. The texture was never being loaded because of this:
Code:
SURFHANDLE Ptest::panel2dtex = NULL;
happening after ovcInit. (I think.)
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
The texture was never being loaded because of this:
Code:
SURFHANDLE Ptest::panel2dtex = NULL;
happening after ovcInit. (I think.)
No, it's because of this:

Code:
	[color=red]return[/color] new Ptest (hvessel, flightmodel);
	Ptest::panel2dtex = oapiLoadTexture("Test\\panel2d.dds");
You're returning from the function before loading the texture.


Anyway, it's static so you can load it only once and not every time a vessel is created.
 
Top