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

Started by
20 comments, last by Jaffer 22 years ago
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
glPrint("When I learn the hello world program, I like ot take a break, with refreshin cola!");
Advertisement
just fiction, but it does not support multiple lines or try using \n\r instead or just \r
I''ve not even looked at the code for glPrint, but make sure you''re using \n, not /n.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
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

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

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.
---visit #directxdev on afternet <- not just for directx, despite the name
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.
---visit #directxdev on afternet <- not just for directx, despite the name
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
glPrint("When I learn the hello world program, I like ot take a break, with refreshin cola!");
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.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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]
You should never let your fears become the boundaries of your dreams.
So _DarkWIng_, I guess no beginners should ever use int main() then, eh?

This topic is closed to new replies.

Advertisement