Render Text

Started by
8 comments, last by dawoodr 9 years, 3 months ago

Hello!

Well I am following this tutorial

on youtube and it seemed pretty cool, however when I do the same thing I can't get the text to render, and furthermore, the cubes that were being rendered before doesn't render aswell, it just blank white.

http://pastebin.com/TVbSK4wr

I am not posting my whole project because I have noticed people only get upset over it so I am just posting the core part.

If I remove theese three lines everything works fine


spriteBatch->Begin();
spriteFont->DrawString(spriteBatch.get(), L"Hello World", SimpleMath::Vector2(100, 100));
spriteBatch->End();

This is how it is suposed to look http://sv.tinypic.com/r/2s8i9af/8

However when those three lines of code are there my application is just pure blank / it is white. I hope you don't want me to show you what that looks like tongue.png

And for those interested here is my declarations and some other useful pieces of code that might help you understand


unique_ptr<SpriteBatch> spriteBatch;
unique_ptr<SpriteFont> spriteFont;
ID3D11ShaderResourceView* textTexture;

spriteBatch.reset(new SpriteBatch(deviceContext));

spriteFont.reset(new SpriteFont(device, L"C:\\Users\\Dawood\\Documents\\Visual Studio 2013\\Projects\\D3\\Arial.spriteFont"));

There is nothing else that has anything to do with rendering text, if anything is wrong then it is here. Like I said people usually don't like when I post my entire project so I won't do it in the future unless somebody asks for it.

Any help is appreciated!

Regards!

Advertisement

Do you have access to the Graphics Debugger in Visual Studio? If so, please take a frame analysis and look through the sequence of operations that have been performed. This will likely show you why your frame ended up all white - just be sure to follow the operations and it should become more clear as you go.

First: some advice for learning how to debug your own code - you did a good job of determining that your rendering is affected by just a few lines of code (the sprite batch calls.) But you didn't take the next step to see why those lines cause the problem.

You could've done one of three things:

1. Looked at the source code for spriteBatch->Begin(...), DrawString() and End() to see what the code does that might affect your own rendering.

2. Set a breakpoint in debug mode at the spriteBatch->Begin call and stepped into the calls to see what might affect your rendering.

3. As Jason Z mentions, you can use a graphics debugger to see what happens (or doesn't happen) when your objects are rendered.

Admittedly, it's a bit hidden, but, assuming you're using the DXTK, you can look at the source (or step through it in debug mode) for SpriteBatch::Impl::PrepareForRendering() to see all the states that are set by the SpriteBatch::Begin(...) call (blend state, depth stencil state, etc.)

I suspect you don't specifically set all the states you need prior to rendering your own objects, and you're just relying on the initial states you setup when you create your context. So, once SpriteBatch::Begin has been called the first time, the states sprite batch sets up (probably incompatible with your own object rendering) persist through the next cycle in your loop.

So, either prior to rendering your objects, or following the sprite batch End() call, try setting the depth stencil state, the blend state, raster states, etc., you need for your own rendering.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I read through all of this http://directxtk.codeplex.com/wikipage?title=SpriteBatch&referringTitle=Home but I can't figure out how I should remake the code, my knowledge is not that great I am just a beginner at DirectX.

However I recorded a video to show you what is happening sort of, it might be of some help. http://sv.tinypic.com/r/okze6a/8

If there is any particular information you need please ask away.

Regards!

Ok I can't believe I fell for this, the text is being rendered but the text color was white and so was the backgroundph34r.png .
So atleast one problem is now solved however my cubes only renders the first time and after the function has been running more than once only the text is being rendered.

Here is a video of it http://sv.tinypic.com/r/27xmbsk/8

And here is the moste recent code http://pastebin.com/XbwHWNeC

Regards!tongue.png


my knowledge is not that great I am just a beginner at DirectX.

I'm going to assume you want to get better at programming. IF SO, then the next step, whether it's DirectX or any API, is for you to learn more about the code you're writing. Part of that process is to learn how to debug a program, so you can determine what you need to learn more about. You've taken a step in that direction by commenting out some code, and discovering where the problem is occurring. That is really good information! The next step, if you want to get better at programming, is to determine yourself why the problem is occurring.

Jason Z and I have taken some time to provide you with suggestions to do just that, including exactly where to look! However, you've chosen to ignore those responses.


If there is any particular information you need please ask away.

Okay. Have you done anything as suggested?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Well I debugged the code and tried to figure some stuff out. So like I said I managed to figure out that the text was being rendered but it was white and so was the background so we couldn't see it, however my cubes are still messed up. I don't know perhaps you missed one of my posts, the one above your latest one :P

Ok I managed to figure out something more. My previous camera settings were camPosition = XMVectorSet(0.0f, 2.0f, -5.0f, 0.0f); So here we only saw "Hello World". However when I changed my cam settings to camPosition = XMVectorSet(0.0f, 20.0f, -300.0f, 0.0f); I can now see the cube or atleast drawings of it. This is how it looks http://sv.tinypic.com/r/amzekx/8

So I don't really know how to solve this, my guess would be that perhaps I have to create a render target or a texture that I write to? I could be completely wrong but I am thinking that DrawString function takes a position x and y so it doesn¨t determine the z axis and my cubes are somehow messed up.

Hopefully some of you might know how to fix this

Regards!

Tutorials are a horrible way to learn.

I've covered that before though, and so have others, so I won't go into a great deal of depth on the subject, but suffice it to say that tutorials don't have the depth nor breadth to cover a subject in any sufficient detail to be terribly useful. If you don't learn to program, and if you don't learn to learn, then you'll always be stuck in ruts like this...

That being said, I have written a sweet little snippet to demonstrate exactly how to render text to the screen using Direct2D.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Thanks alot Washu, great tutorial!

This topic is closed to new replies.

Advertisement