English 中文(简体)
HLSL and ID3DXFont/ID3DXSprite
原标题:

I ve started at the beginning, and my code will capably display the grand total of some text. I ve been adding support for sprites. The trouble that I ve run in to, is that it doesn t seem to recognize my HLSL. I set the technique, began it, began the pass, drew the sprites, flushed them, ended the pass, the technique. And D3D comes up with this little "Using FF to PS converter" in the VS output. Same for VS. I m not trying to do anything advanced with my HLSL - just use it and get a little more familiar with it and make sure I know how to implement it. That s C++0x auto, by the way, so automatic type deduction (because I m lazy).

#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());

where RenderAndCleanUp is a simple templated function that loops through the sprites, destroys those that need to be, and renders the rest, and common->sprites is a simple vector of all the sprite objects. Since DXTrace never goes off, I ll guarantee that none of the functions fail. I ve also set the control panel to max debugging.

I checked the D3DXHANDLEs and they re all non-NULL. It doesn t report any compilation errors, or any errors or warnings.

// 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();
  }
}

This is native C++ looking at Direct3D9.

问题回答

AFAIR D3DXSprite and D3DXFont rendering is implemented inside of D3DX itself. So, it sets its own shaders, states (emulates fixed-function pipeline) and renders text/sprites. So, your shaders and states have no effect on these objects. You may implement your own text/sprite rendering subsystem, it s not so hard. Another vote for this is that Microsoft officially deprecated D3DX.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签