• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Yura

Enable the depth for text

15 posts in this topic

Hi,

I'm using sprites for text rendering. I need to enable z-buffer (depth) for text, but standart function does not require 3rd component, only X and Y.

Vector3 point = Vector3.Project(....);

            if (!string.IsNullOrEmpty(textToRender))
            {
                infoLine.DrawText(sprite, textToRender, (int)point.X, (int)point.Y, black);
            }

 

So my text is always "at the top", and I need to hide it under other elements. What can I do?

 

EDIT: infoLine is a SharpDX.Direct3D9.Font class member

Edited by Yura
0

Share this post


Link to post
Share on other sites

You need to set transform to your sprite object. Don't know SharpDX but for pure DX9 it's like this:

 

void D3DFont::DrawText(RECT rect, LPCWSTR lpText, DWORD dFlags, float f, D3DCOLOR color)
{
	m_mTransform(3,2) = 1.0f - f;
	m_lpD3DSprite->SetTransform(&m_mTransform);
	m_lpFont->DrawText(m_lpD3DSprite, lpText, -1, &rect, dFlags, color);
}

Whereas m_mTransform is a D3DXMATRIX-object initialized to identity -> D3DXMatrixIdentity(&m_mTransform). Check out the SharpDX documentation for the equivalent to this.

1

Share this post


Link to post
Share on other sites

You could pass a constant in a constant buffer for your text that indicates the depth that it should reside at.  Then you can directly copy the depth value from your constant buffer into the z-coordinate of your output vertex structure in the vertex shader.  This will give you direct control of the text depth without modifying your vertex sizes or anything like that.

1

Share this post


Link to post
Share on other sites

You could pass a constant in a constant buffer for your text that indicates the depth that it should reside at.  Then you can directly copy the depth value from your constant buffer into the z-coordinate of your output vertex structure in the vertex shader.  This will give you direct control of the text depth without modifying your vertex sizes or anything like that.

 

And how do I check if input vertice is a part of the text or a part of the primitive? Primitives can have 0.0 z-component as well...

0

Share this post


Link to post
Share on other sites

You need to set transform to your sprite object. Don't know SharpDX but for pure DX9 it's like this:

 

void D3DFont::DrawText(RECT rect, LPCWSTR lpText, DWORD dFlags, float f, D3DCOLOR color)
{
	m_mTransform(3,2) = 1.0f - f;
	m_lpD3DSprite->SetTransform(&m_mTransform);
	m_lpFont->DrawText(m_lpD3DSprite, lpText, -1, &rect, dFlags, color);
}

Whereas m_mTransform is a D3DXMATRIX-object initialized to identity -> D3DXMatrixIdentity(&m_mTransform). Check out the SharpDX documentation for the equivalent to this.

 

Can you make some explanation: what if F-value (float f)? 

And m_mTransform is World matrix?

0

Share this post


Link to post
Share on other sites

Can you make some explanation: what if F-value (float f)?

And m_mTransform is World matrix?

 

Naming failure ftw.

"float f" is meant to be "float z", therefore the 3rd coordinate, and therefore the depth for your text. m_mTransform initialially is an identity matrix, getting filled with the inverse (depending on how you sort your sprites - front to back or back to front, so you might want to try on that one) z coordinate. You can create it in the function call, but I decided to "cache" it in the class for (small) performance reason. So the better understandable function might go:

 

void D3DFont::DrawText(RECT rect, LPCWSTR lpText, DWORD dFlags, float z, D3DCOLOR color)
{
    D3DXMATRIX mTransform;
    D3DXMatrixIdentity(&mTransform);
    m_mTransform(3,2) = 1.0f - z;
    m_lpD3DSprite->SetTransform(&mTransform);
    m_lpFont->DrawText(m_lpD3DSprite, lpText, -1, &rect, dFlags, color);
}
Edited by The King2
1

Share this post


Link to post
Share on other sites

Can you make some explanation: what if F-value (float f)?

And m_mTransform is World matrix?

 

Naming failure ftw.

"float f" is meant to be "float z", therefore the 3rd coordinate, and therefore the depth for your text. m_mTransform initialially is an identity matrix, getting filled with the inverse (depending on how you sort your sprites - front to back or back to front, so you might want to try on that one) z coordinate. You can create it in the function call, but I decided to "cache" it in the class for (small) performance reason. So the better understandable function might go:

 

void D3DFont::DrawText(RECT rect, LPCWSTR lpText, DWORD dFlags, float z, D3DCOLOR color)
{
    D3DXMATRIX mTransform;
    D3DXMatrixIdentity(&mTransform);
    m_mTransform(3,2) = 1.0f - z;
    m_lpD3DSprite->SetTransform(&mTransform);
    m_lpFont->DrawText(m_lpD3DSprite, lpText, -1, &rect, dFlags, color);
}

 

Nope, text is still at the top

 

sprite.Begin(SpriteFlags.AlphaBlend);
Matrix matr = Matrix.Identity;
matr.M32 = -5; //hardcoded, just a try variat, primitives min z is -1
sprite.Transform = matr; //transform sprite with this matrix
SignFont.DrawText(sprite, "o", new Rectangle((int)(screenPoint.X - 1), (int)(screenPoint.Y - 1), 
                        (int)(screenPoint.X + 1), (int)(screenPoint.Y + 1)), FontDrawFlags.NoClip | FontDrawFlags.Center | FontDrawFlags.VerticalCenter, 
                        new ColorBGRA(100, 0, 255, 255));
sprite.Transform = Matrix.Identity; // after rendering text cancel transform for other elements
.............................
sprite.End();
0

Share this post


Link to post
Share on other sites

Did you try different values for matr.M32? 0.0f, 1.0f, 5.0f ...? It must be in the same range as the z for your sprites, obviously, but if changing the value doesn't do anything, well, at least we know there is some issue with eigther the transformation as is or the z-sorting itself. Also, make sure you enable depth sorting - if you do not manually sort the text along with your sprites and draw accordingly, you need to Begin() your sprite with the Alpha-Blending flag, eigther front to back.

Edited by The King2
1

Share this post


Link to post
Share on other sites

You could pass a constant in a constant buffer for your text that indicates the depth that it should reside at.  Then you can directly copy the depth value from your constant buffer into the z-coordinate of your output vertex structure in the vertex shader.  This will give you direct control of the text depth without modifying your vertex sizes or anything like that.

 

And how do I check if input vertice is a part of the text or a part of the primitive? Primitives can have 0.0 z-component as well...

Do you perform separate draw calls for your meshes and your text?  I would assume so, since text rendering is significantly different than mesh rendering and would probably use different shaders.  Sorry if I wasn't clear about that - you need to have a specialized shader that is only used on your text.

1

Share this post


Link to post
Share on other sites

Do you perform separate draw calls for your meshes and your text? I would assume so, since text rendering is significantly different than mesh rendering and would probably use different shaders. Sorry if I wasn't clear about that - you need to have a specialized shader that is only used on your text.

 

From what he posted it looks like he is using SharpDXs LPD3DXSPRITE-encapsulation, so I suppose there is any shader involved at all. At least the functions and objects he uses are perfect meshes for raw DirectX9's sprite/font objects.

1

Share this post


Link to post
Share on other sites

The King2

I've tried different variants with M32 value - result the same, text is at the top..

 

 

Jason Z

The King2 is right, I'm using Sprites for text rendering, they are out of shader at all. But if there is no other chance to enable Z-value with sprites, I'm ready to try to implement your variant

Edited by Yura
0

Share this post


Link to post
Share on other sites

Does it work if you call flush on your sprite object afterwards? Try that with different z-values..

Edited by The King2
1

Share this post


Link to post
Share on other sites

Does it work if you call flush on your sprite object afterwards? Try that with different z-values..

 

No, it doesnt. Still the same. I've tried with different values

0

Share this post


Link to post
Share on other sites

Did you explicitely set this flag to eigther front to back or back to front?

 

I've just tried it. Didn't help.

0

Share this post


Link to post
Share on other sites
An idea I had was ID3DXSprite might thrash the depth-related render states, but there aren't any flags for Begin and the SharpDX docs list all the states - no depth related stuff. This is really the moment to fire up PIX and check states, your vertex positions and look at the depth buffer.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0