Jump to content
  • Advertisement
Sign in to follow this  
Funkiemonkey

Rendering text to an image texture

This topic is 3059 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, So I'm using managed direct x *puke* and I'm trying to load an image to use as a background and render some text over the top. The idea is that this will be a single texture which is then applied to the back of a mesh. So far I am able to render text to a texture and apply that to the back of a mesh, which is all good. See the code below:
            m_textTexture = new Texture(device, m_imageToLoad.Width, m_imageToLoad.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);
            
            Microsoft.DirectX.Direct3D.Surface origSurface = device.GetRenderTarget(0);
            Microsoft.DirectX.Direct3D.Surface textSurface = m_textTexture.GetSurfaceLevel(0);

            try
            {
                device.SetRenderTarget(0, textSurface);
                device.Transform.World = Matrix.Identity;
                device.Clear(ClearFlags.Target, System.Drawing.Color.WhiteSmoke.ToArgb(), 1f, 0); 
                m_font.DrawText(null, m_imageDetail.Text, new System.Drawing.Rectangle(0, 0, (int)background.Width, (int)background.Height), DrawTextFormat.Center | DrawTextFormat.VerticalCenter | DrawTextFormat.WordBreak, System.Drawing.Color.DarkGray);
                device.SetRenderTarget(0, origSurface);
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }

Which is all good. But I've tried loading the background image directly as a texture using this:
            m_textTexture = new Texture(device, background, Usage.RenderTarget, Pool.Default);
Except this call fails as it loads it using the vertex buffer lock, which requires Usage.Dynamic. If I use that I can't use RenderTarget and if I don't use RenderTarget I can't render my text onto it! :s Any ideas? I've tried rendering a separate sprite with a separate texture to the texture but then I get the error "Can not render to a render target that is also used as a texture". I guess in a sense when I simply render the text to the texture and then use it on the mesh I'm doing this, so why only error when I use a second texture? Hmmm, on top of that I've been doing some reading and it seems that rendering to a texture is a capability (http://msdn.microsoft.com/en-us/library/ms792919.aspx) so I'm assuming some set-ups won't support this anyway? It seems quite basic functionality... but perhaps I'm going around this completely the wrong way and there's more generic functionality that could achieve this? Any help or suggestions would be appreciated. (Sorry for the long post!) Andy.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Funkiemonkey

I've tried rendering a separate sprite with a separate texture to the texture but then I get the error "Can not render to a render target that is also used as a texture". I guess in a sense when I simply render the text to the texture and then use it on the mesh I'm doing this, so why only error when I use a second texture?



This means you're trying to render to a render target that's still bound as an input to the device. You'll need to set that texture input back to NULL, or to another texture.

Share this post


Link to post
Share on other sites
Quote:
Original post by Funkiemonkey
So I'm using managed direct x *puke*

So how about SlimDX instead? :)

BTW, the right tag to use is 'source', not 'code'.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!