0

I am trying to create a card game. I want to have a deck of cards where the back of the card is a fixed texture but the front is dynamic, i.e. it has some text fields on it as well as a picture. I have created a box sized 3x2x0.16 to represent my card. I can get the fixed texture to load but I cannot find any code examples on the web that show me how to load a fixed texture on one side of the box and a dynamic one on the other. Can anyone point me to some examples please. I'm using DirectXTK mainly, but can probably fathom it out from any DirectX code too.
DirectX11 is version of DirectX I am using.

Any recommendations on how to do this would also be welcome.

Thanks

Rolonos
  • 1
  • 3
  • How "dynamic" is your texture data? Does it change all the time or is it generated once at startup? – Alex Jun 14 '20 at 10:04
  • @Alex Just generated at start up. I will have multiple instances of the object each with different front faces. – Rolonos Jun 14 '20 at 10:54

1 Answers1

0

Easiest method for generating your cards, depending on how many there are and how large you want them, is to generate the faces at startup by using render to texture. Effectively, draw your dynamic card faces exactly like you would draw them in the world, but use an orthographic projection matrix and a blank 2D texture object as the render target. Once you have that, cache these "dynamic" textures in an std::map and bind them when drawing a specific card.

If your faces are relatively small, or you want to save on texture memory, you can stitch multiple card faces together into a large sheet of textures, then use some shader scaling logic to reference a subsection of the sheet for rendering a specific texture. With this, you can assemble "decks" of cards that only contain the faces in use in that particular game, allowing you to evict the others from GPU RAM.

Alex
  • 1,794
  • 9
  • 20
  • That's what I envisaged doing, however I have not found any examples for creating a map and applying the map to a box rather than a cube, especially as I only have 2 textures not 6. This is where I am struggling. – Rolonos Jun 14 '20 at 13:30
  • An `std::map`. Not a cubemap. Two different things. The map is to organize the textures on the CPU side so you know which one to select come render time. – Alex Jun 14 '20 at 20:12