# DX11 How can i correctly render a character from a bitmap using dynamic vertex buffer?

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

## Recommended Posts

I'm trying to render the characters of a bitmap texture that i generated with stb_truetype.h.

Currently i have the texcoords and the longitude of each character, my DirectXTexture2D is 512x512 normilized from -1 to 1.

So, i send to render the character "C", creating my triangulation starting from coords (0,0) -> (X0,Y0).

Then i get my X1 adding X0 + longitude. NOTE: I transformed my longitude to screen space coordinates dividing out of 512 (texture width size) before.

This is my bitmap texture:

This is my vertex buffer:

float sizeX = static_cast<float>(tempInfo.longitude) / 512;
float sizeY = 0.0625f; //32/512 (32->height of font)

spritePtr[0].Pos = XMFLOAT3(0.0f + sizeX, 0.0f + sizeY, 1.0f);
spritePtr[1].Pos = XMFLOAT3(0.0f + sizeX, 0.0f, 1.0f);
spritePtr[2].Pos = XMFLOAT3(0.0f, 0.0f, 1.0f);

spritePtr[3].Pos = XMFLOAT3(0.0f, 0.0f, 1.0f);
spritePtr[4].Pos = XMFLOAT3(0.0f, 0.0f + sizeY, 1.0f);
spritePtr[5].Pos = XMFLOAT3(0.0f + sizeX, 0.0f + sizeY, 1.0f);

spritePtr[0].Tex = XMFLOAT2(tempInfo.Tex_u1, tempInfo.Tex_v0);
spritePtr[1].Tex = XMFLOAT2(tempInfo.Tex_u1, tempInfo.Tex_v1);
spritePtr[2].Tex = XMFLOAT2(tempInfo.Tex_u0, tempInfo.Tex_v1);

spritePtr[3].Tex = XMFLOAT2(tempInfo.Tex_u0, tempInfo.Tex_v1);
spritePtr[4].Tex = XMFLOAT2(tempInfo.Tex_u0, tempInfo.Tex_v0);
spritePtr[5].Tex = XMFLOAT2(tempInfo.Tex_u1, tempInfo.Tex_v0);

NOTE: spritePtr is the pointer to my dynamic buffer that i map and unmap.

And this is my result:

I don't understand why it is too small compared to my bitmap and if i expand the triangulation i get a pixelated character.

Edited by RubenRS

##### Share on other sites

Grasping at straws here, but to me it just looks like your sizeX/sizeY might be wrong. In the results image your C looks like its a little distorted

I think you really just need to have sizeX = 32 and sizeY = 32 assuming the size for a letter is 32x32. As long as your tex coords are creating the right clipping rectangle on your texture I think you should be good

##### Share on other sites

I believe, font height isn't actually height of capital letters, it's the entire vertical extent of the font (consider, eg. glyphs "Ć" and "g"). So the height of glyph "C" will be less than 32, in your bitmap it's roughly 18 pixels. If you set the height to 18, it should fix the vertical stretching.
Then, there's the problem of the rendering being to small. Will it help, if I point out, that it's exactly half the size of what you expect?:)

##### Share on other sites
1 hour ago, dietrich said:

I believe, font height isn't actually height of capital letters, it's the entire vertical extent of the font (consider, eg. glyphs "Ć" and "g"). So the height of glyph "C" will be less than 32, in your bitmap it's roughly 18 pixels. If you set the height to 18, it should fix the vertical stretching.
Then, there's the problem of the rendering being to small. Will it help, if I point out, that it's exactly half the size of what you expect?:)

That have sense for me thanks.

Edited by RubenRS

1. 1
2. 2
3. 3
4. 4
Rutin
15
5. 5

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632912
• Total Posts
3009199
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!