simple_d3d_used
#
defining graphics' vertex' format:
struct vertextType
{
Vertex(){}
Vertex(float x, float y, float z)
{
_x = x; _y = y; _z = z;
}
float _x, _y, _z;
static const DWORD FVF;
};
const DWORD Vertex::FVF = D3DFVF_XYZ;
define vertexbuffer:
IDirect3DVertexBuffer9* vertexbuffer = NULL;
#
if needed, define indicesbuffer: (indicesbuffer is the array of the key of vertexbuffer above):
IDirect3DIndexBuffer9* indicesbuffer = NULL;
#
'bout setup:
#1.
//get a Device by "IDirect3DDevice9* Device";
#2.
void setup()
{
Device->CreateVertexBuffer(/*length*/numbers * sizeof(vertexType), /*vertex format*/FVF, ..., vertexbuffer, ...);
Device->CreateIndexBuffer(numbers * sizeof(WORD), ..., indicesbuffer, ...);
#3.
//build vertex and indices ;
vertexType* vertexPointer;
WORD* indicesPointer;
// initial ;
vertexbuffer->Lock(..., (void**)&vertexPointer, 0);
vertexPointer[n] = ......;
vertexbuffer->Unlock();
indicesbuffer->Lock(..., (void**)&indicesPointer, 0);
indicesPointer[n] = ......;
indicesbuffer->Unlock();
#4.
// arrange 投影;
......
}
#
'bout display:
void display()
{
//render one thing
///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// /////////////////////////////////////////
//////'bout a object's rendering and displaying,it's a section for every one or one group of object.
////// !BEGIN! //////
#1.
//arrange 变换
D3DXMAXTRIX matrix;
D3DXMatrixTranslation(&matrix, ...);
//or D3DXMatrixRotationX/Y/Z(& matrix, ...);
//or ......
//action! transform
Device->SetTransform(D3DST_WORLD/D3DST_PROJECTION, &matrix);
#2.
Device->Clear(......);
//go into rendering core!
Device->BeginScene(); //draw data preparing begin!
//set graphics' data
/*if draw with another data, you need define and arrange another vertexbuffer*/
/* before "setup" you need vertexType* vertexbufferAnother. */
/* and in "setup" you also need 'Device->Create...; vertexbufferAnother->Lock()...->Unlock();......' */
Device->SetStreamSource(0, vertexbuffer, 0, sizeof(vertexType));
//Device->SetIndices(indicesbuffer); //if the painting need indices undered line is needed!OR not!
//Device->DrawPrimitive(......); //draw with vertexes just!
Device->DrawIndexPrimitive(IMAGE_TYPE, ......); //draw with indices!
Device->EndScene(); //draw data preparing end!
////// !END! //////
////// 'bout a object's rendering and displaying,it's a section for every one or one group of object.
///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// /////////////////////////////////////////
}
#
'bout the WinMain():
#1.
void WinMain(......)
{
if(InitD3D(......)) //init D3D and WM and ......
{......;}
if(!setup()) //exec setup
{......;}
/* use message loop section defined very very ago.and get your 'display()' func into it. */
/* then your 'display' func and other 'communication' func would looppy effect.*/
SomeFuncSectionBoutMsgLoop(display);
}
//拿过来吧,基本不用QZONE了