Newline when printing text in openGL
Hi,
I''m using NEHE''s tut 24 to print text to the screen, that it reads from a string... I''m wondering if I just missed it, or is there no symbol (like \n when using cout in consoles)???
In case you don''t know the lesson 24, the code looks like this:
GLvoid glPrint(GLint x, GLint y, int set, const char *fmt, ...) // Where The Printing Happens
{
char text[1024]; // Holds Our String
va_list ap; // Pointer To List Of Arguments
if (fmt == NULL) // If There''s No Text
return; // Do Nothing
va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text
if (set>1) // Did User Choose An Invalid Character Set?
{
set=1; // If So, Select Set 1 (Italic)
}
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glLoadIdentity(); // Reset The Modelview Matrix
glTranslated(x,y,0); // Position The Text (0,0 - Top Left)
glListBase(base-32+(128*set)); // Choose The Font Set (0 or 1)
glScalef(0.8f,0.9f,1.0f); // Make The Text 1.2X Taller
glCallLists(strlen(text),GL_UNSIGNED_BYTE, text); // Write The Text To The Screen
glDisable(GL_TEXTURE_2D); // Disable Texture Mapping
glLoadIdentity();
}
I''m wondering about the ap pointer and parsing the list for variables... it seems there must be some way of telling it that a certain symbol should initiate a new line...
thanks for any help in advance
norleaf
--------------------------------------------------------------
What''s the problem? I don''t got a problem, I got fuckin'' problems!
-Tim Roth, Four Rooms
--------------------------------------------------------------What's the problem? I don't got a problem, I got fuckin' problems! plurum!-Tim Roth, Four Rooms
New line isn''t just another character. For it to work, you need to reposition the rest of the text. For example, in a console, when you print a new line, the cursor is moved down one line, moved to the start of the line, and then the rest of the text is drawn from there. You have to do the same thing. When you reach a new line character, you must stop drawing, move the position down one line, move it back to the start, and start drawing again. So split the string on each new line character into several smaller strings and draw them separately.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement