[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

OpenGL maximum speed drawing texts

Posted on 2009-12-17
10
Medium Priority
?
677 Views
Last Modified: 2013-12-26
I am passing an application from GDI to OpenGL, with C++ and Visual Studio, on Windows.
I must display Topographic/Geographic maps in an application using OpenGL. Texts have various orientations and different sizes. Though I gained speed in other elements drawing, passing from GDI to OpenGL, the same seems not to happen either using bitmap or outline fonts with glCallList function. Worse, it seems much slower than GDI... In OpenGL Bible the authors refuse to explain these topics giving an hint to use texture maps.
So which is the method giving maximum speed in drawing texts, having different dimensions and orientations? Shall I have a real increase of speed or the actual situation will stay more or less the same?
0
Comment
Question by:gpol
  • 6
  • 3
9 Comments
 
LVL 20

Expert Comment

by:ikework
ID: 26072093
Hi gpol,

If flat 2D-fonts are ok, then bitmaps are your way to go. You can combine it with displaylists.
How many texts are we talking about? Are all texts in the visible frustum? If not, you can make visibility checks and only render the visible texts.
Can you give more details data to the performance issue? What is your current framerate?

ike
0
 

Author Comment

by:gpol
ID: 26072739
Dear Ike
though much probably this has no influence on the topic, you must figure out that mine is not a "common" OpenGL program, where the scene is continuously redrawn etc., as, at least, I saw in many tutorials. The "scene" is not continuously redrawn, but stays fixed till some redraw is necessary, typically after user input. Problems arise when zooming or panning the drawing, because, yes, at this time, the scene should be redrawn at "mouse movements speed". My program displays Topographic maps, composed of symbols (actually a collection of lines, defined in a local environment (0..1), and then scaled at the appropriate dimension at the moment of rendering the map), lines, and, unfortunately, texts representing informations that must stay in the map. Just to fix ideas, imagine that for each point (whose symbol can be composed of 100 lines, for example) I can have three texts, one representing point "name", another the value of Z coord (actually terrestrial maps aren't true 3d environment), and a description. The program is developed in Windows environment and draws on GDI device context etc. I decided, for gaining speed (!!) to pass to OpenGL. Now the program is very fast (at least 5 times, but I have a poor graphic board) on lines and about 3 times slower on texts. I used outline fonts because, though the big part of the texts are horizontal, I can need also texts with any slope (orientation, not the single gliph orientation, but the entire string). For uniformity (and not knowing whether bitmap texts are faster or not) I used outline ones. My texts can be resized at any time by the user, too. My implementation creates a Windows font, then selects it in the device context, then creates the display list. This process is done only when necessary, i.e. if text typeface don't change, I don't recreate the display list. In practice the code fragments are:
1) Font created in Windows
2) Font selection in GDI
3) Creation of the list (I even "speculated" generatin only 128 chars...)
  GLYPHMETRICSFLOAT gmf[128];
   m_listbase = glGenLists(128);
  !wglUseFontOutlines(dc->m_hDC,0,128,m_listbase,0.0,0.0,WGL_FONT_LINES ,gmf))
The above is done once, before using texts.
Then drawing is done with:
1) Some stuff to invert the Y axis (necessary, ugly, but not so influent, I tested)
2) Positioning the text: (also this is not so influent)
    glTranslatef((GLfloat)x,(GLfloat)(rect.bottom-y-hei-1),0);
    glScalef(width,height,1);
    glRotatef      (angle,0,0,1);
    glPushAttrib(GL_LIST_BIT);
    glListBase(m_listbase);
    glCallLists(len, GL_UNSIGNED_BYTE, (const GLvoid*)s); // here is the drama...
    glPopAttrib();

Infact, commenting out all but the glCallList, the drawing time is acceptable.
This is the scenario. I hope I was clear. I also tried to use some fonts libs but I see this a rather expensive task. And, finally, I am also thinking to make "my fonts" with some collections of lines....
Let me know if you have any suggestion.
Thanks
Giovanni
0
 
LVL 20

Expert Comment

by:ikework
ID: 26087607
Hey Giovanni,

Can you post a screenshot? 1 picture says more than 1000 words ;)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 20

Expert Comment

by:ikework
ID: 26087670
Ok, sounds very interesting. I have some ideas in mind. I'd like to try glFonts2 (its using bitmaps), since most of the strings are static, one can try to create the entire displaylists for the strings. If the same string is used multiple times, one could try to share the displaylists. Another approach might be, only to render the strings that are really visible etc ..

Could you upload the project here?

ike
0
 

Author Comment

by:gpol
ID: 26087769
Hi Ike
Unfortunately the project is either enormous or "strategic" in my life, so I cannot easily send it worldwide. Anyway I have further information. Not hearing from you, I decided a brutal strategy, to use, after OpenGL buffer swapping,.. GDI. Actually this trivial solution seems interesting for my case, as it zeroes the difference between old program and new, on text display part. Of course I am interested in "magnitudes of increases in speed" as usually OpenGL fans claim... that seems not my case. (I am joking). So, I attach you two screen-shots. The points are over 18000. A typical medium size of my situations. A general view and a zoomed in one.
First of all the question is: shall I insist with texts and OpenGL or the benefit could not be so big?
Also, to better understand the topic, much probably I need a "vector" font, to be able to rotate and modify its dimensions "on the fly".
Thanks
Giovanni
detail.JPG
Global-map.JPG
0
 
LVL 20

Expert Comment

by:ikework
ID: 26087808
>> Also, to better understand the topic, much probably I need a "vector" font, to be able to rotate and modify its dimensions "on the fly".

You can rotate and scale it with glRotate and glScale, you already did it in the code-snippet above, that you posted.

In the screenshots that you posted is not much readable text, in the first one are only 9 texts. You really have performance issues with 9 texts?
0
 
LVL 20

Accepted Solution

by:
ikework earned 2000 total points
ID: 26087884
>> Of course I am interested in "magnitudes of increases in speed" as usually OpenGL fans claim... that seems not my case. (I am joking).

I wouldnt listen too much to such general claims, it depends on a lot of things. Test if OpenGL fits your needs better, if not drop it and use GDI.

>> First of all the question is: shall I insist with texts and OpenGL or the benefit could not be so big?

Well, I wouldnt mix GDI and OpenGL. As I said I would try some optimizations, like only render the readable texts, Google-Maps makes the same with street-names, they are only rendered at a certain zoom. But without actually trying it, its not easy to predict. I would say everything between 0 and 100 texts should make no trouble, but that is just a guess.
0
 

Author Comment

by:gpol
ID: 26088079
Ok. Also negative answers are useful. From your words I understand that OpenGL is not a choice for texts of the type I need. Good to know it.
Thanks.
Giovanni
0
 
LVL 20

Expert Comment

by:ikework
ID: 26088416
>> From your words I understand that OpenGL is not a choice for texts of the type I need

No, I wouldnt say that, all I'm saying is, that if your app works better with GDI, then stick to it.
But you said the OGL version was faster, so I would use GL, I would optimize the text-part. But that is because thats fun to me, if it was a commercial project and has to be shipped in time, I wouldnt change it.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question