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

Started by
3 comments, last by RubenRS 6 years, 6 months ago

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:

Capture.PNG.703c279bef997c6c31ce5efc35c978bf.PNG

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:

Capture2.PNG.6b210d0ba3754bb8042be88bca436c71.PNG

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

Advertisement

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

 

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?:)

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.

Capture2.PNG.f32daf2261d559ca83c7332a248e8eaa.PNG

This topic is closed to new replies.

Advertisement