glPrint("and doing more than 1!!!");
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
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
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.
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
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
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.
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.
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:
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.
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.
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
Thanks for all your reply nevertheless :D
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.
Examine the code for glPrint and see if it does that.
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]
There are more worlds than the one that you hold in your hand...
[edited by - _DarkWIng_ on April 10, 2002 3:22:52 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement