RubenRS

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

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:

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.

Edited by RubenRS

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Capture2.PNG.f32daf2261d559ca83c7332a248e8eaa.PNG

Edited by RubenRS

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Announcements

  • Forum Statistics

    • Total Topics
      628394
    • Total Posts
      2982428
  • Similar Content

    • By KarimIO
      Hey guys,
      I'm trying to work on adding transparent objects to my deferred-rendered scene. The only issue is the z-buffer. As far as I know, the standard way to handle this is copying the buffer. In OpenGL, I can just blit it. What's the alternative for DirectX? And are there any alternatives to copying the buffer?
      Thanks in advance!
    • By rXpSwiss
      Hello,
      I am sending compressed json data from the UE4 client to a C++ server made with boost.
      I am using ZLib to compress and decompress all json but it doesn't work. I am now encoding it in base64 to avoid some issues but that doesn't change a thing.
      I currently stopped trying to send the data and I am writing it in a file from the client and trying to read the file and decompress on the server side.
      When the server is trying to decompress it I get an error from ZLib : zlib error: iostream error
      My question is the following : Did anyone manage to compress and decompress data between a UE4 client and a C++ server ?
      I cannot really configure anything on the server side (because boost has its ZLib compressor) and I don't know what is wrong with the decompression.
      Any idea ?
      rXp
    • By glportal
      GlPortal is a free and open source first person 3D teleportation based puzzle game and platformer. But we have already integrated a physics engine and are planning for some physics based puzzles.
      We want to improve our Visual Studio support. Check out this project:
      https://github.com/kungfooman/glportal-vs
      You can chat with us on gitter https://gitter.im/GlPortal/glPortal
    • By noodleBowl
      So I have some quick questions about constructors and pointers

      Question on constructors:
      1. I'm working on this Sprite class and in general sprites need some kind of texture in order to display to the screen. So I have my class looking like this:
      class Sprite { public: Sprite(Texture* texture); ~Sprite(); Texture* texture; //Other class stuff } Now in the current state of my Sprite class would I be correct in that I cannot use it as a member in a different class, because it has no no-arg (default) constructor? That the only way this class could be a member is if it was a pointer?
      class SpriteContainer { public: SpriteContainer(); ~SpriteContainer(); Sprite singleSprite; //**BAD** not allowed because Sprite has no no-arg (default) constructor Sprite* singleSpritePtr; //This is allowed because its a pointer std::vector<Sprite> sprites; //**BAD** not allowed because Sprite has no no-arg (default) constructor std::vector<Sprite*> spites; //This is allowed because its a vector of Sprite pointers } I guess my really problem here is that I struggle with when a variable/class should be a pointer or not
      2. How do you make an abstract class where there are no methods that should be pure virtual functions?
      All the functions of the base class have there implementation, but I also do not want this class to be instantiated
      //Should not be able to instantiate this class. Should be an Abstract class class BaseClass { public: BaseClass() { x = 0; }; virtual ~BaseClass() { }; int x; void coolMethod() { ++x; } } //Can instantiate this class. coolMethod can be called from this class class DerivedClass : public BaseClass { public: DerivedClass(); ~DerivedClass(); }  
      Questions about smart pointers:
      1. I have never used these before, but are smart pointers ok when working with COM objects?
      Will the smart pointer automatically call a COM object's Release function or should I wrap my COM object and explicitly call Release in the wrapper class' destructor?
      2. Lets say there is a case where I wanted to give back the user of some APIs a pointer to a resource, but I also want them to know that they don't have to worry about cleaning it up. EG There is resource loader that will clean up all loaded resources once the program shuts down. The user has to do/worry about nothing.
      What type of smart pointer should I use in a case like this? Should it be a Shared pointer? Or should I make the resource a Unique pointer and then return to the user a raw pointer?
    • By Kazuma506
      I am trying to recreate the combat system in the game Life is Feudal but make it more complex. The fighting system works by taking in the direction of the mouse movement and if you press the left click it will swing in that direction, though stab, overhead, left (up, down, left right) and right are the only swings that you can do. If you wanted to you could also hold the swing by holding left click so you are able to swing at the perfect moment in the battle. I want to change this so add in more swing directions but I also want to code this from scratch in Unreal. Can anyone give me any pointers or maybe a few snippets of code that work in Unreal that could help me start to implement this type of system?
       
       
  • Popular Now