到目前为止,我已经在DirectX 9中完成了一个框架,它使用了一个Single VertexBuffer来绘制我加载的每个纹理,我使用了一个Vertex数组,它在Lock和Unlock调用中绘制每个Texture Quad。我听说有一个叫做Batching的东西,我可以把它锁定一次,当我绘制所有东西时解锁。我知道我可以在一次调用中绘制每个纹理四边形来锁定和解锁,但我不知道如何为每个纹理设置不同的纹理。这里有人可以指导我吗?
vertexBufferRHW->Lock(0, 0, (void**)&VerticesRHW, NULL);
VerticesRHW[0].Color = color;
VerticesRHW[0].X = (float) Position.X;
VerticesRHW[0].Y = (float) Position.Y;
VerticesRHW[0].Z = 0.0f;
VerticesRHW[0].RHW = 1.0f;
VerticesRHW[0].U = 0.0f;
VerticesRHW[0].V = 0.0f;
VerticesRHW[1].Color = color;
VerticesRHW[1].X = (float) (Position.X+TextureFile.Width);
VerticesRHW[1].Y = (float) Position.Y;
VerticesRHW[1].Z = 0.0f;
VerticesRHW[1].RHW = 1.0f;
VerticesRHW[1].U = 1.0f;
VerticesRHW[1].V = 0.0f;
VerticesRHW[2].Color = color;
VerticesRHW[2].X = (float) (Position.X+TextureFile.Width);
VerticesRHW[2].Y = (float) (Position.Y+TextureFile.Height);
VerticesRHW[2].Z = 0.0f;
VerticesRHW[2].RHW = 1.0f;
VerticesRHW[2].U = 1.0f;
VerticesRHW[2].V = 1.0f;
VerticesRHW[3].Color = color;
VerticesRHW[3].X = (float) Position.X ;
VerticesRHW[3].Y = (float) (Position.Y+TextureFile.Height);
VerticesRHW[3].Z = 0.0f;
VerticesRHW[3].RHW = 1.0f;
VerticesRHW[3].U = 0.0f;
VerticesRHW[3].V = 1.0f;
vertexBufferRHW->Unlock();
spriteDevice->SetTexture(0,TextureFile.TextureFile);
spriteDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,0,2);
答案 0 :(得分:0)
您可以使所有四边形的高度/宽度为1,然后执行for循环,如下所示:
for( ... loop through all the textures )
{
// create a matrix that scales your quad to make it the correct width/height and in the correct location
D3DXMATRIX matrix, scale, translation;
D3DXMatrixScaling( &scale, texture.width, texture.height, 0 );
D3DXMatrixTranslation( &translation, position.x, position.y, 0 );
matrix = scale * translation;
spriteDevice->SetTransform( D3DTS_WORLDMATRIX, &matrix );
spriteDevice->SetTexture(0,texture);
spriteDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,0,2);
}