Sign in to follow this  
FortisVenaliter

Shaders with C++

Recommended Posts

I already know how to write shaders and have done so using XNA. The question I have is, are there any tutorials that focus on the C++ side of using the DirectX9 Effects? I have found a few that do DX10, and several for C#/XNA, but I cannot find one for C++. The MSDN doc for creating shaders from a file doesn't have an example, nor does the Effect structure page. Thanks, Louis

Share this post


Link to post
Share on other sites
Assuming you mean unmanaged C++ and the sdk samples are the same in your version of the sdk as mine, then check out the sample named "BasicHLSL".

Share this post


Link to post
Share on other sites
It's really not much different than it is in XNA. You'll find that the XNA Framework classes really aren't much more than light wrappers when it comes to most D3D objects, and the ID3DXEffect object is no exception.

On thing you may have to deal with but avoided with XNA is compiling your effects. Typically in XNA you'll add an effect to the Content project, which compiles it for you at build time so that you can just load it with your ContentManager. In native D3D9 you're on your own for this stuff. You have two basic options for this:

1. Compile your effect at runtime using D3DXCreateEffectFromFile. This will compile your .fx file, and give you an ID3DXEffect interface that you can use. When you do this you have to be aware that the function will fail if your effect fails to compile. When this happens the function will return a failing HRESULT code, and the compilation error will be placed in a string embedded in the ID3DXBuffer that you receive via the ppCompilationErrors parameter.

2. Compile your effects offline using the command-line effect compiler: fxc. You can call fxc right from the command prompt and direct it to write the compiled output to a file, or you can have Visual Studio invoke fxc as a post-build step (this makes it much like XNA, where your effects are built at compile-time). You can then load the compiled effect at runtime, using the same D3DXCreateEffectFromFile function.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this