Shaders with C++

Started by
4 comments, last by FortisVenaliter 15 years, 8 months ago
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
Regards,FortisVenaliterLead Developer - Unsignedhttp://www.unsigned-game.com
Advertisement
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".
For the love of god, please tell me that you've just omitted your error checking code for brevity, and you don't really assume that all those functions succeed.
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.

Hmmm... it seems that example is only in C#/VB (who honestly uses VB with DirectX anyway?)
Regards,FortisVenaliterLead Developer - Unsignedhttp://www.unsigned-game.com
If your SDK contains Managed DX, then it's very very very old. Get the latest sdk.
Heh, yea... it appears I was looking at the online docs for DX SDK March '05. Whoops. I have compiled effects using fxc before, so I will look into the functions. Thanks!
Regards,FortisVenaliterLead Developer - Unsignedhttp://www.unsigned-game.com

This topic is closed to new replies.

Advertisement