Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Jaffer

glPrint("and doing more than 1!!!");

This topic is 5941 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, im working on opengl at the moment, and have stumbled across a problem concerning the glPrint bit. I have this glPrint("Hello Well, whats up? %7.2f", cnt1); as you may now see, im taking the nehe tutorials (thanks, great site :D) but i cant get 2 lines of text at once, IE Hello Well, whats up? is what i want, what i get is Hello Well, whats up? I have tryed using /n, and just differtant combinations of / and n :D:D any help appreciated

Share this post


Link to post
Share on other sites
Advertisement
hmm, well my glPrintf function takes all the format specifiers printf takes.


  
void glPrintf( const char *format, ...) //used like printf to display text

{
va_list args;
va_start(args,format);
numchars+=vsprintf(GLTEXT+numchars, format, args);
va_end( args );
}


I haven''t looked at nehe''s function, but if it works using vsprintf then it should be the same. And yes, you should use "\n" not "/n"

www.elf-stone.com

Share this post


Link to post
Share on other sites
Looks like wglUseFontBitmaps won''t allow you to print text with line breaks. You have to write your own font engine.

If you''ve got DX8 SDK, take a look at D3DFont. I ported D3DFont to OpenGL and enhanced it. I can send you my class if you want to look at it, but 1) it''s a part of a larger project, and may not be usable by itself without modifications and 2) it''s long and complicated, although I tried to do a good job at commenting.

Share this post


Link to post
Share on other sites
The problem with wglUseFontBitmaps (I think) is that the display lists print whatever character they were made for and advance the current raster position to the right. If you want line breaks, you have to advance raster position downward. But since you call one list for each letter, how does the list for ''\n'' know where your string starts? It has no way of knowing it, and therefore there''s no reliable way to return back to horizontal position where string rendering started. There''s little benefit in advancing vertical coordinate for letter output without returning to the beginning horizontal position, like this:

This is\nsome text
becomes
This is
some text

So you have to write your own font class that keeps track of screen coordinates. I believe it''s possible to modify NeHe''s code to do line breaks by using glGet with raster position arguments and handing ''\n'' manually, but considering that calling a display list for every character is extremely slow, you''re better off writing a new font engine.

I hope this explains why line breaks don''t work with NeHe''s code.

Share this post


Link to post
Share on other sites
right. as i said im new to OpenGL. Its really hard to understad what your saying. I understand about moving screen co-ords, but as far as building a font engine is concerned, i wouldnt know where to begin!

Thanks for all your reply nevertheless :D

Share this post


Link to post
Share on other sites
AFAIK, handling newlines in GL is a bit more complicated than doing a ''naive'' glPrint function. You need to first save the raster position, then parse the string and decompose it in individual lines. glPrint the first line, restore the raster position, move down by the size of the font, save the raster position, lather, rinse, repeat.

Examine the code for glPrint and see if it does that.

Share this post


Link to post
Share on other sites
You shouldn't use functions you don't know HOW and WHY they work.

There are more worlds than the one that you hold in your hand...

[edited by - _DarkWIng_ on April 10, 2002 3:22:52 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
So _DarkWIng_, I guess no beginners should ever use int main() then, eh?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!