0

到目前为止,我已经在 DirectX 9 中完成了一个框架,它使用单个 VertexBuffer 来绘制我加载的每个纹理,我使用了一个顶点数组来绘制 Lock 和 Unlock 调用中的每个纹理 Quad。我听说有一种叫做批处理的东西,我可以将它锁定一次,然后在我绘制所有内容时解锁。我知道我可以在一次调用中绘制每个纹理四边形来锁定和解锁,但我不知道如何为每个纹理设置不同的纹理。这里有人可以指导我吗?

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);
4

1 回答 1

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);
}
于 2013-02-22T19:12:36.590 回答