托管DirectX:指定深度(Z顺序)含有纹理和文本的精灵 [英] Managed DirectX: Specifying the Depth (Z-Order) of Sprites containing Texture and Text

查看:206
本文介绍了托管DirectX:指定深度(Z顺序)含有纹理和文本的精灵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用托管DirectX尝试绘制质感和一段文字来使用雪碧屏幕。不幸的是,如果我把文本,并在同一精灵纹理,纹理覆盖(透支?)无论我做绘图命令的命令的文本。

I am using managed DirectX to try and draw a texture and a piece of text to the screen using a Sprite. Unfortunately, if I place the text and the texture in the same sprite, the texture overwrites (overdraws?) the text regardless of the order I do the draw commands.

由于我最终还是会希望穿插纹理和文字,我怎么指定Z-为了让这些精灵。 ?是否每一层都必须在一个单独的精灵

Since I will eventually want to intersperse textures and text, how do I specify a Z-order for these sprites. Does each layer have to be in a separate sprite?

下面是当前的代码:

m_device.BeginScene();
m_device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
m_sprite.Begin(SpriteFlags.SortTexture | SpriteFlags.AlphaBlend);

// Switching the order of following two statements doesn't change the Z-Order!
m_sprite.Draw(m_texture, Vector3.Empty, new Vector3(0, 0, 0), 
              Color.White.ToArgb());
m_d3dFont.DrawText(m_sprite, m_text, x, y, color);

m_sprite.End();
m_device.EndScene();
m_device.Present();

请注意:使用SpriteFlags.SortDepthBackToFront或SpriteFlags.SortDepthBackToFront不改变行为

Note: Using the SpriteFlags.SortDepthBackToFront or SpriteFlags.SortDepthBackToFront does not change the behaviour.

这可能是我的一个概念上的误解,但如果代码是非常有用的,我会使用C ++或其他语言感激地接受非托管的DirectX样本。

This is probably a conceptual misunderstanding on my part, but if code is useful, I'll gratefully accept samples in unmanaged DirectX using C++ or whatever language.

在事先非常感谢!

推荐答案

如果你想改变渲染,那么你必须设置在Draw命令Z值的Z顺序。如果将所有为0,你会得到各种古怪的。您的更大的问题是,DrawText的不允许您设置一个Z深度是各种垃圾。

If you want to change the Z-Order of rendering then you have to set the Z value in the Draw command. If you set the all to 0 you will get all sorts of weirdness. Your bigger issue is that DrawText doesn't allow you to set a Z-Depth which is all kinds of rubbish.

因此,你唯一的机会就是利用ID3DXSprite ::的setTransform。您需要转移只Z坐标回来与它相关的ž排序位置。所以,你可以设置你的变换(假设你使用的身份世界矩阵)如下(C ++示例)

Thus your only chance is to use ID3DXSprite::SetTransform. You need to shift only the Z-Coordinate back with it for the relevant z ordering position. So you can set your transforms (assuming you are using identity world matrices) as follows (C++ example)

D3DXMATRIX mat( 1.0f, 0.0f, 0.0f, 0.0f,
                0.0f, 1.0f, 0.0f, 0.0f,
                0.0f, 0.0f, 1.0f, 0.0f,
                0.0f, 0.0f, zOrder, 1.0f );
m_Sprite->SetTransform( &mat );



然后进行传递的位置渲染(0,0,0)和文本也将获得对z排序正确的深度。

You then carry on passing a position of (0, 0, 0) for rendering and text will also gain the correct depth for z-ordering.

希望有所帮助。

这篇关于托管DirectX:指定深度(Z顺序)含有纹理和文本的精灵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆