#### Archived

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

# 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.

## 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 on other sites
just fiction, but it does not support multiple lines or try using \n\r instead or just \r

##### Share on other sites
I''ve not even looked at the code for glPrint, but make sure you''re using \n, not /n.

How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

##### Share on other sites
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 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 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 textbecomesThis 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 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!

##### 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 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 on other sites
So _DarkWIng_, I guess no beginners should ever use int main() then, eh?

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002278
×

## Important Information

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!