|
我做的地图 48*48德,建立了顶点数组合索引数组,然后附上材质。
现在贴上了草地图片了,不过呢,我还想贴其他的图片,比如沙漠,不知道怎么贴,请问那位高手可以指点一下。
Device->CreateVertexBuffer(
rowidth*colheight * sizeof(Vertex), // size in bytes
D3DUSAGE_WRITEONLY, // flags
D3DFVF_XYZ | D3DFVF_TEX1, // vertex format
D3DPOOL_MANAGED, // managed memory pool
&MyTr, // return create vertex buffer
0); // not used - set to 0
Device->CreateIndexBuffer( 6 * sizeof(WORD)*rowidth*colheight,
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&MyIn,
0);
D3DXCreateTextureFromFile(
Device,
"greas.bmp",
//"dx5_logo.bmp",
&Tex);
Vertex* mymap;
MyTr->Lock(0,0,(void **) &mymap,0);
/*
mymap[0]=Vertex(-1.0f, 0.0f, 2.0f);
mymap[1]=Vertex(0.0f, 1.0f, 2.0f);
mymap[2]=Vertex(1.0f, 0.0f, 2.0f);
mymap[3]=Vertex(0.0f, 1.0f, 1.0f);*/
for (int i=0;i<rowidth;i++){
for (int j=0;j<colheight;j++){
mymap[i*rowidth+j]=Vertex(i*1.0f-rowidth/2,12.0f,j*1.0f-colheight/2,
(float)i/rowidth,(float)j/colheight);
}
}
MyTr->Unlock();
WORD* indexs;
MyIn->Lock(0,0,(void **)&indexs,0);
/*indexs[0]=0;indexs[1]=1;indexs[2]=2;
indexs[3]=1;indexs[4]=2;indexs[5]=3;*/
int bi=0;
for (int i=0;i<rowidth;i++){
for (int j=0;j<colheight;j++){
indexs[bi] = i * rowidth + j;
indexs[bi + 1] = i * rowidth + j + 1;
indexs[bi + 2] = (i+1) * rowidth + j;
indexs[bi + 3] = (i+1) * rowidth + j;
indexs[bi + 4] = i * rowidth + j + 1;
indexs[bi + 5] = (i+1) * rowidth + j + 1;
bi+=6;
}
}
MyIn->Unlock();
// Device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
Device->SetTexture(0, Tex);
Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
Device->SetRenderState(D3DRS_LIGHTING, false);
Device->SetStreamSource(0,MyTr,0, sizeof(Vertex));
Device->SetIndices(MyIn);
Device->SetFVF( D3DFVF_XYZ | D3DFVF_TEX1);
// Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0,64*64,0,64*64);
Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0,64*64,0,64*64);
//wzb end 定点设计
Device->EndScene();
Device-> resent(0, 0, 0, 0);
MyTr->Release();
Tex->Release();
MyIn->Release(); |
|