Thanks Rojart, exactly what I needed. Thanks to everyone lse too.
Here is what Ive come up with for MY needs, based on what Rojart posted. Works a treat!
//===================================================================================
//
#include <d3d9.h>
//
LPD3DXMESH Panel_Mesh;
//
void morph_to_3dpanel(ENTITY *entity)
{
D3DVERTEX vbuff[4]; memset(vbuff, 0, 0x04*ent_status(entity,22));
vbuff[0].x = 10; vbuff[0].y = 10; vbuff[1].x =-10; vbuff[1].y = 10;
vbuff[2].x =-10; vbuff[2].y =-10; vbuff[3].x = 10; vbuff[3].y =-10;
vbuff[0].u1 = 0; vbuff[0].v1 = 0; vbuff[1].u1 = 1; vbuff[1].v1 = 0;
vbuff[2].u1 = 1; vbuff[2].v1 = 1; vbuff[3].u1 = 0; vbuff[3].v1 = 1;
short ibuff[12] = { 0,1,2, 2,3,0, 2,1,0, 0,3,2 };
//--------------------------------------------------------------------------------
D3DXCreateMesh(0x04, 0x04, D3DXMESH_MANAGED , pvertexdecl, pd3ddev, &Panel_Mesh);
D3DVERTEX *vb; Panel_Mesh->LockVertexBuffer(0, (void**)&vb);
memcpy(vb, vbuff, 0x04*ent_status(entity,22));
Panel_Mesh->UnlockVertexBuffer();
short *ib; Panel_Mesh->LockIndexBuffer (0, (void**)&ib);
memcpy(ib, ibuff, 0x04*3*sizeof(short));
Panel_Mesh->UnlockIndexBuffer();
//--------------------------------------------------------------------------------
D3DXComputeNormals(Panel_Mesh,0);
ent_setmesh(entity, Panel_Mesh, 0, 0);
}
//
//===================================================================================
//
function exit_event()
{ you=NULL; while((you=ent_next(you)))
{ Panel_Mesh = ent_getmesh(you,0,0);
if(Panel_Mesh)
{ Panel_Mesh->Release(); ent_setmesh(you,0,0,0); } }
sys_exit(""); }
//
//-----------------------------------------------------------------------------------
//
void on_exit_startup() { wait(2); on_exit = exit_event; }
//
//===================================================================================
It generates a simple 2D, double-sided, uv_mapped square as a physical mesh.
(and YES, the back-side is a mirror-image intentionally)
Size is adjusted later on elsewhere by ent_setvertex'ing the 4 vertices...
But Ive got a couple of questions too... (for anyone)
This code is part of a 'plug-in' header file for my (old) 3d-Panels system.
So I want it to be pretty self-contained, bullet-proof, and non-intrusive.
1> You will notice that I run through all the currently loaded entities and
do a "Release" on them ALL. Is this a safe thing to do in a real application?
Or should I ONLY 'Release' the ones Ive created?
2> Is the way tht I hook into the 'exit' event being dont in a 'bad' way?
That is, if you had an existing application already 'somehow' hooking the
on_exit events, would my way of hooking in 'break' yours in a difficult
to find and/or fix way?
3> When performing an ent_remove on an entity carring my custom mesh, do I need
to catch them and do a "Release" myself, or will the engine do it naturally?
4> I noticed in Rojart's code then he doea a 'wait_for(create_house)'... I cant
see any need for this as the function contains no 'wait's. Is there a hidden
need for the wait_for that Im not aware of?
Thanks everyone for the hand...