Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Immediate mode text alternative.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 TRONJon   Members   -  Reputation: 231

Like
0Likes
Like

Posted 20 May 2014 - 02:16 PM

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



Sponsor:

#2 mark ds   Members   -  Reputation: 1488

Like
0Likes
Like

Posted 20 May 2014 - 03:50 PM

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.


Edited by mark ds, 20 May 2014 - 03:56 PM.


#3 SeanMiddleditch   Members   -  Reputation: 7269

Like
7Likes
Like

Posted 20 May 2014 - 04:13 PM

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.

#4 Hodgman   Moderators   -  Reputation: 32049

Like
8Likes
Like

Posted 20 May 2014 - 04:20 PM

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.


Edited by Hodgman, 20 May 2014 - 04:57 PM.


#5 h3xl3r   Members   -  Reputation: 174

Like
0Likes
Like

Posted 21 May 2014 - 02:17 AM

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.


Edited by h3xl3r, 21 May 2014 - 02:18 AM.


#6 Yours3!f   Members   -  Reputation: 1398

Like
1Likes
Like

Posted 28 May 2014 - 06:31 AM

look at my signature ;)



#7 Kaptein   Prime Members   -  Reputation: 2180

Like
0Likes
Like

Posted 28 May 2014 - 08:47 AM

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.

Edited by Kaptein, 28 May 2014 - 08:50 AM.


#8 Yours3!f   Members   -  Reputation: 1398

Like
0Likes
Like

Posted 01 June 2014 - 01:57 AM

 

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?



#9 Kaptein   Prime Members   -  Reputation: 2180

Like
0Likes
Like

Posted 01 June 2014 - 10:38 AM

 

 

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



#10 Yours3!f   Members   -  Reputation: 1398

Like
0Likes
Like

Posted 03 June 2014 - 09:35 AM

 

 

 

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS