Jump to content
  • Advertisement
Sign in to follow this  
striker87

Help with Beginning DirectX 11

This topic is 2407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering if anyone has read Beginning DirectX 11 and has done the "on your own" projects in the book as am trying to figure out how to do the one in Ch. 3 where I am to use a different sprite for the second sprite. I'm looking at the code I've done for that chapter and am having a hard time figuring out what I need to change so that the second sprite will be different from the first one. If anyone has done this or has an even better way of learning DirectX 11 it would be greatly appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Well, I sort of got it working. I created another header and source file for my test sprite and used the same code from the other sprite but for some reason the two sprites are flashing instead of being static. I'll keep playing around with it and if anyone needs to see the code let me know and I can email it to you or post it on here if need to.

Share this post


Link to post
Share on other sites
Hi,


If anyone has done this or has an even better way of learning DirectX 11 it would be greatly appreciated.

I've started very old-fashioned one day with the samples in the DirectX SDK and read the Direct3D 11 programming guide at MSDN. Objects and functions are fairly well documented.

There is some pretty fresh book out there that could help you out as well. It is called 'Practical Rendering and Computation with Direct3D 11' by Jason Zink et al. Jason hangs out here in this forum as well.

Back in 2008 Allison Klein gave at Gamesfest an Introduction Talk on DirectX 11. You can find the slides and the audio track here. Though this is a little technical (probably too much for starters), it gives you a nice overview over the things introduced with Dx11.


Well, I sort of got it working. I created another header and source file for my test sprite and used the same code from the other sprite but for some reason the two sprites are flashing instead of being static. I'll keep playing around with it and if anyone needs to see the code let me know and I can email it to you or post it on here if need to.

What do you mean with flashing? Since you used the same code twice, I'd guess you got z-fighting. You probably just rendered two objects at the same position. Which object will be in front is totally random then. Try moving one object a little bit back and see what happens.

Good luck!

Share this post


Link to post
Share on other sites
Thanks for the book suggestions and for the sprites flashing I'm having them drawn at different positions so I don't think it's z-fighting. Wish there was another way for me to explain this better. I know that when I comment the initialization of one of the sprites the other sprite will show up normal without flashing so I'm guessing it's got something to do with the initialization or possibly the rendering.



Here is a link to a zip file containing all the source code in case anyone would like to take a look at it. http://dl.dropbox.com/u/6991288/GameSprites.zip

Share this post


Link to post
Share on other sites
I believed I figured out what was the problem with the sprites flashing but have came back to pretty much square one as am trying to figure out how to draw the second sprite on the screen. If anyone has an example of how to draw more than one sprite in DirectX 11 it will greatly be appreciated.

Share this post


Link to post
Share on other sites
Hi!

I looked at your code.
The GameSpriteDemo inherits from Dx11DemoBase, whereas Dx11DemoBase creates the ID3D11Device, the swap chain, the backbuffer and so on. You should only have one instance of that. (You had two.) The flashing you observed was because you rendered into two different backbuffers and presented them alternately. So you rendered the first sprite into the first backbuffer, showed that and then you rendered the second sprite into another backbuffer and show that. Instead you should render both sprites into the same backbuffer.

So, we can forget about the MySprite class, since it inherits from Dx11DemoBase, too and we don’t need another class that declares a device, swapchain and backbuffer etc. I commented everything out what was calling your instance of MySprite.

So, how do we show two sprites? You have already created an array of sprites, which is good! Additionally we need two ShaderResourceViews, since both sprites will have a different texture.

For the rendering you used a vertex buffer and already scaled the vertex positions to the dimensions of the sprite. This makes it difficult to reuse the buffer. It is better to create a vertex buffer with unit-corners (1,1,1), (-1,1,1), … and then scale the quad with help of the scale part of the world matrix. Since the MySprite class already has a scale property we can simply use that.

The order of matrix multiplications in the MySprite class was reversed by the way. I changed that too. First comes scale, then rotation and last translation.

Last but not least you didn’t release all resources in UnloadContent. I did that for you too.

Okay, so that’s it. I attached the modified code here. It shows two sprites as intended.

Oh and one final notice. If you attach things here please delete the Debug, Release and ipch folders, as well as *.suo, *.sdf, *.user and *.opensdf. Those are created by visual studio and are not needed to compile your code. This will decrease your file size a lot and is nicer for people who have a monthly limited download volume.

Bye!

Share this post


Link to post
Share on other sites
Thanks for the help Tsus! I really appreciate it. I'm gonna look over everything you done and make sure to note them down for future use and will remember to not add Debug when I upload something. Again thanks for the help!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!