Members - Reputation: 100
Posted 21 January 2012 - 02:53 AM
Members - Reputation: 1178
Posted 21 January 2012 - 04:21 AM
In D3D you would basically create a vertex buffer which contains a unit quad and then scale and move it in a vertex shader to the appropriate size and position. In the pixel shader you would modify the texture coordinate to jump to the right sprite in your sprite sheet and finally fetch the color.
You can check out some of the samples in the DirectX SDK.
Tutorial03 would be a good starting point. It already creates a triangle. First, you would have to extend this a little to a quad. So, simply place two triangles in your vertex buffer. Don’t forget to adapt the ByteWidth of the buffer and the vertex count in the draw call. As vertex positions I would suggest for the bottom left corner (-0.5,-0.5) and for the top right corner (0.5, 0.5). (The z-component is your choice. It encodes the depth and must be in [0,1].)
If you got this you can start moving your quad around. Therefore you can pass a scale and translation vector to your shader and the scale / translate your vertex. The viewport goes from [-1,-1] to [1,1]. For the beginning you can hardcode a scale and translation in the vertex shader.
Finally you need some texture coordinates. You could either extend your vertex buffer to also contain them or you compute them from your position. Texture coordinates are in [0,1]. So, all you have to do would simply be adding a 0.5 to the vertex position the vertex shader received. You pass this texture coordinate on to the pixel shader and do a texture lookup. Tutorial 7 shows you how to do that. (You need to load a texture, get a shader resource view on it, bind that view to the pixel shader stage and you have to declare the texture in the shader.)
At the moment you would display the whole sprite sheet at once. So, last but not least, you’d have to scale and translate your texture coordinate to fit on the right sprite in your sprite sheet.
Feel free to ask if you’d like to have more help.
I always like to see and help people starting with graphics programming very soon.