Immediate mode text alternative.

Started by
8 comments, last by Yours3!f 9 years, 10 months ago

I'm moving away from Immediate mode rendering and display lists, and started using vertex buffers... but I've hit a problem when it comes to rendering text.

For example when drawing my FPS meter, the value changes all the time, so currently my text render sends a texture mapped quad to the GPU for each character, and this works exactly as I want... but if immediate mode rendering is deprecated... how am I supposed to draw data that changes every frame?

Surely using buffers would be a bit overkill? What does everyone else use for this?

- Jonathan

Advertisement

Assuming you have a four digit counter, the vertices for the 4 quads (8 tris) will be static, but the texture coordinates will change each frame. Say each characters uses a 16x16 section of the texture: if you initially assign the texture coordinates based on [0,0] to [15,15], you only need to send in 4 new [x,y] offset values to add to the existing ones.

However, when debugging, there's actually nothing inherently wrong with immediate mode, and it could be argued that it makes you're code cleaner and leaner in release mode. Use whatever is most convenient.

Surely using buffers would be a bit overkill? What does everyone else use for this?


Buffers aren't overkill. They're _how the GPU works_. Any other interface you might use will just be (probably poorly) using buffer behind the scenes.

You might use instancing and the geometry shader instead of precomputing the whole quad, though. You can fill up a single dynamic buffer with the data about each glyph's location, size, and color, and then use the geometry shader to generate quads of the right size from an existing constant buffer describing the font. Whether this is worth it depends on how much text you're drawing.

Sean Middleditch – Game Systems Engineer – Join my team!

The driver will be implementing immediate mode internally by using buffers.
Every engine I've used also does this itself (has a simple 'immediate' render API, which is implemented using buffers) - every graphics API except for GL has already removed immediate mode completely, so engines implement it via buffers.

As stated already in this thread, buffers are the way to go!

For some example text-rendering code (plus some goodies like SDF scalable rendering + effects) take a look at:

https://github.com/rougier/freetype-gl

Personally I use a hybrid approach of using a plain pre-rendered texture-atlas for small font sizes (8-12) and a single pre-rendered signed-distance-field texture-atlas scaled to all other sizes. All using VBO's of course, only difference between rendering both variants being the fragment shader code.

look at my signature ;)

look at my signature ;)

Awesome =)

Btw. don't use if (variable) delete variable;


ptr
    A pointer to the memory block to be released, type-casted to a void*.
    If this is a null-pointer, the function does nothing.

look at my signature ;)

Awesome =)

Btw. don't use if (variable) delete variable;


ptr
    A pointer to the memory block to be released, type-casted to a void*.
    If this is a null-pointer, the function does nothing.

whoa, I actually know about this, dunno how it got into my code... where did you find it?

look at my signature ;)

Awesome =)

Btw. don't use if (variable) delete variable;


ptr
    A pointer to the memory block to be released, type-casted to a void*.
    If this is a null-pointer, the function does nothing.

whoa, I actually know about this, dunno how it got into my code... where did you find it?

Not a big deal at all. Nice library though.

The extraneous if() I just happened upon is in new_raytracer/material.h

look at my signature ;)

Awesome =)

Btw. don't use if (variable) delete variable;


ptr
    A pointer to the memory block to be released, type-casted to a void*.
    If this is a null-pointer, the function does nothing.

whoa, I actually know about this, dunno how it got into my code... where did you find it?

Not a big deal at all. Nice library though.

The extraneous if() I just happened upon is in new_raytracer/material.h

thanks, will correct it :)
btw it shouldn't affect libmymath, it's just an experimental raytracer I fiddled with.

This topic is closed to new replies.

Advertisement