简体   繁体   English

使用一侧带有动态纹理的 DirectXTK 创建 3d 卡

[英]Creating a 3d card using DirectXTK with Dynamic texture on one side

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, ie it has some text fields on it as well as a picture.我想要一副卡片,卡片的背面是固定纹理但正面是动态的,即它上面有一些文本字段以及一张图片。 I have created a box sized 3x2x0.16 to represent my card.我创建了一个大小为 3x2x0.16 的盒子来代表我的卡片。 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.我可以加载固定纹理,但在 web 上找不到任何代码示例,这些示例向我展示了如何在盒子的一侧加载固定纹理,在另一侧加载动态纹理。 Can anyone point me to some examples please.谁能指点我一些例子。 I'm using DirectXTK mainly, but can probably fathom it out from any DirectX code too.我主要使用 DirectXTK,但也可以从任何 DirectX 代码中理解它。
DirectX11 is version of DirectX I am using. DirectX11 是我正在使用的 DirectX 版本。

Any recommendations on how to do this would also be welcome.任何关于如何做到这一点的建议也将受到欢迎。

Thanks谢谢

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.有效地绘制动态卡片面,就像在世界中绘制它们一样,但使用正交投影矩阵和空白 2D 纹理 object 作为渲染目标。 Once you have that, cache these "dynamic" textures in an std::map and bind them when drawing a specific card.一旦你有了它,将这些“动态”纹理缓存在std::map中,并在绘制特定卡片时绑定它们。

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.如果您的面相对较小,或者您想节省纹理 memory,您可以将多个卡片面拼接成一张大的纹理,然后使用一些着色器缩放逻辑来引用该表的一个子部分以渲染特定纹理。 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.有了这个,您可以组装仅包含该特定游戏中使用的面孔的卡片“甲板”,从而可以将其他人从 GPU RAM 中驱逐出去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM