我从头开始,我的代码将能够显示一些文本的总数。我一直在添加对精灵的支持。我遇到的麻烦是它似乎无法识别我的 HLSL。我设置技术,开始它,开始传球,绘制精灵,冲洗它们,结束传球,技术。而 D3D 在 VS 输出中提出了这个小小的“使用 FF 到 PS 转换器”。VS 也一样。我不想用我的 HLSL 做任何高级的事情 - 只是使用它并更加熟悉它并确保我知道如何实现它。顺便说一句,那是 C++0x auto,所以是自动类型推导(因为我很懒)。
#define D3DCALL(a) { auto __ = a; if (FAILED(__)) DXTrace(__FILE__, __LINE__, __, WIDEN(#a), TRUE); }
D3DCALL(spriteeffect->SetTechnique(spritetechnique));
D3DCALL(spriteeffect->Begin(&passes, NULL));
D3DCALL(spriteeffect->BeginPass(0)); // We know this is zero.
D3DCALL(sprite->Begin(D3DXSPRITE_OBJECTSPACE | D3DXSPRITE_DO_NOT_ADDREF_TEXTURE | D3DXSPRITE_SORT_TEXTURE | D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_DEPTH_FRONTTOBACK));
RenderAndCleanUp(common->sprites);
D3DCALL(sprite->End());
D3DCALL(spriteeffect->EndPass());
D3DCALL(spriteeffect->End());
其中 RenderAndCleanUp 是一个简单的模板化函数,它循环遍历精灵,销毁那些需要的,并渲染其余部分,而 common->sprites 是所有精灵对象的简单向量。由于 DXTrace 永远不会关闭,我保证所有功能都不会失败。我还将控制面板设置为最大调试。
我检查了 D3DXHANDLE,它们都是非空的。它不报告任何编译错误,也不报告任何错误或警告。
// Contains the HLSL for sprites.
// Based on transform.fx, by Frank Luna.
// FX parameter (global variable to the shader).
uniform extern float4x4 gWVP;
// Structure
struct OutputVS
{
float4 posH : POSITION0;
float4 color : COLOR0;
};
// Vertex shader
OutputVS SpriteVS(float3 post : POSITION0,
float4 col : COLOR0)
{
// Zero out our output.
OutputVS outVS = (OutputVS)0;
outVS.posH = mul(float4(post, 1.0f), gWVP); // Transform
outVS.color = col;
// Done--return the output.
return outVS;
}
// Pixel shader - take the original colour of the pixel and just return it. Nothing fancy.
float4 SpritePS( float4 col : COLOR0 ) : COLOR
{
return col;
}
technique Sprite
{
pass P0
{
// Specify the vertex and pixel shader associated
// with this pass.
vertexShader = compile vs_3_0 SpriteVS();
pixelShader = compile ps_3_0 SpritePS();
}
}
这是着眼于 Direct3D9 的本机 C++。