Strategy for drawing text

Hi

A little bit of background to the question, I have something already which I use to draw text on to the screen. I first generate a bitmap from a ttf font file then I use this bitmap to texture a set of quads to draw strings of text on the screen. This works fine and I have no issues with this, the question is more around how to design things if you want to have something like a text editor where the text changes in length and that length can be unknown to begin with.

The current strategy uses a VBO, but if I have a VBO built for text of size 10 and then I need it to be 11 I have to create a new ByteBuffer of data which can hold 11 bits of data rather than 10. I could of course make a very large buffer to begin with but this has issues itself.

So my question is, what coding strategy could I use to make a text editor, that reduces the need to create new buffers all the time but maximises the easiness of adding new text to an existing string.

Such as?

For drawing my sprites in a 2D game I have a VBO with a max capacity of 1,000 yet usually I’m only drawing ~300 different things each frame. So the buffer almost never get’s full but there’s adequate space for rendering my game and I can increase the maximum if I need to. I declare the FloatBuffer as final but each frame clear and reset it’s position to 0 then start populating it again.

For text I’m not using this ttf --> bitmap approach you’re talking about but instead have one .png that has ALL sprites including font. So each character has it’s own UV (ST) coordinates within the texture and it get’s mapped to a bunch of quads on the screen, which get lumped into the max 1,000 VBO.

Ndnwarrior15,

I do a similar thing to what you are doing. I have a single texture and have a maximum size of the vbo which I set at the beginning. The issue with a text editor type of scenario is that at some point I will get to the end of the vbo and I will require more space. The obvious thing to do is have multiple vbo’s and to keep adding more as the text grows.

I am after some views / ideas / suggestions for alternative ways to the above, I am not familiar with enough later 3.0 functions and 4.0 functions to know if there more optimal ways of doing this

Is this for a game?

In all my years of gaming I just can’t think of a scenario where a ton of screen space was needed for inputting text. And it’s not like I’m interested in writing a novel anyways, I want to play the game.

I would set a maximum capacity for the text based upon the dialog window where the text is going and how much text I plan to fit inside there. Even if the text overflows and scrolling is required, there is only so many characters that will need to be printed to the screen at any given time.

I just changed my maximum sprite capacity from 1000 to 10,000 and notice barely any difference in memory allocation. This is all just my own opinion and how I would end up doing things but I don’t see why making an empty larger VBO is such a big deal. My performance in the game (FPS) didn’t change nor did memory space suffer from making a larger VBO. Plus I wouldn’t plan on running around shooting blowing up a thousand things while having tons of english characters dancing on my screen anyways.