Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Problem with font.DrawText in SharpDX 2.5 #381

Closed
jerrydx opened this issue May 12, 2014 · 6 comments
Closed

Problem with font.DrawText in SharpDX 2.5 #381

jerrydx opened this issue May 12, 2014 · 6 comments
Labels

Comments

@jerrydx
Copy link

jerrydx commented May 12, 2014

Hello,

I have serious troubles with your newest SharpDX 2.5 version. Font.Draw function does not work. Can you repair it ?

Here is sample code + screenshot. Instead of the letters I see filled oblongs only.

https://onedrive.live.com/redir?resid=6C2D62DDB1948596%21283

Thanks.

Jerry

@ArtiomCiumac
Copy link
Contributor

There are no SharpDX projects in the link you provided (found only one C++/CLI project referencing XNA). Please provide the correct link. And btw, the latest SharpDX version is 2.6.

@jerrydx
Copy link
Author

jerrydx commented May 13, 2014

Ling again

https://onedrive.live.com/redir?resid=6C2D62DDB1948596%21284

Maybe I made a mistake at link creation. I am sorry. My mistake.

Problem is identical with 2.5 or 2.6. Instead of a letter (the letters) I see set of filled oblongs only.

@jerrydx
Copy link
Author

jerrydx commented May 13, 2014

*Link ( no Ling )

@jerrydx
Copy link
Author

jerrydx commented May 13, 2014

Behaviour of the link is very suspicious. If I click on it in Forefox, result of it is ... nothing,
but If I COPY+PASTE it, OneDrive depicts me the correct file. Really very suspicious.

@ArtiomCiumac
Copy link
Contributor

After looking at the code I see that the "serious troubles" are with the code itself and not with SharpDX. Have you tried to set the alpha-blend flag and specify a font color with alpha channel different from 0 (which means completely transparent)?

Here is the updated loop code:

RenderLoop.Run(form, () =>
{
    SharpDX.ColorBGRA color1 = new ColorBGRA( 0.0f, 0.0f, 0.0f, 0.0f );
    SharpDX.ColorBGRA color2 = new ColorBGRA( 1.0f, 1.0f, 1.0f, 1.0f ); // <-- text alpha should be different from 0.

    device.Clear(ClearFlags.Target, color1, 1.0f, 0);
    device.BeginScene();


    // Make the text boucing on the screen limits
    if ((fontDimension.Right + xDir) > width)
        xDir = -1;
    else if ((fontDimension.Left + xDir) <= 0)
        xDir = 1;

    if ((fontDimension.Bottom + yDir) > height)
        yDir = -1;
    else if ((fontDimension.Top + yDir) <= 0)
        yDir = 1;

    fontDimension.Left += (int)xDir;
    fontDimension.Top += (int)yDir;
    fontDimension.Bottom += (int)yDir;
    fontDimension.Right += (int)xDir;


    // Draw the text
    _sprite.Begin(SpriteFlags.SortTexture | SpriteFlags.AlphaBlend); // <-- alpha blend flag should be specified for sprites with transparency
    font.DrawText( _sprite, displayText, 20, 20, color2);
    _sprite.End(); 

    device.EndScene();
    device.Present();
});

The original SharpDX sample is working fine because it doesn't use Sprite and in this case Font sets the correct flags automatically.

@jerrydx
Copy link
Author

jerrydx commented May 13, 2014

WOU surprisingly, its working :-)
Thank you very much 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants