The thing is, it seems to have problems with getting the 'next word' and counting its length. That much I have gathered from testing. But why doesn't the word length counting part work? I'm guessing I must be getting the word in a wrong way but I just can't figure it out. Please help? Code below.
void TextSystem::DrawWrapped(std::string text, int x, int y, int wrapWidth, int charWidth, GLfloat colorR, GLfloat colorG, GLfloat colorB){ int X = x, Y = y; //If the font has been built if( FontTex.Texture != NULL ){ //Go through the text for( int show = 0; text[ show ] != '\0'; show++ ) { //If the current character is a space if( text[ show ] == ' ' ){ //Problems start about here string nextWord = text.substr(show, text.find_first_of(' ', show)); int wordWidth; wordWidth=0; for( int showWord = 0; nextWord[ showWord ] != '\0'; showWord++ ){ int ascii = (unsigned char)nextWord[ showWord ]; int charW=32; wordWidth+=charW; } //Problems end about here if(X+wordWidth > wrapWidth){ Y += ( charWidth / ( float(FontTex.Width)/16 ) ) *newLine; X = x; } else //Move over X += space; } //If the current character is a newline else if( text[ show ] == '\n' ){ //Move down Y += ( charWidth / ( float(FontTex.Width)/16 ) ) *newLine; //Move back X = x; } else { //Get the ASCII value of the character int ascii = (unsigned char)text[ show ]; //Show the character int charW=( charWidth / ( float(FontTex.Width)/16 ) ) *chars[ascii].w; //chars[ascii].w; int charH=( charWidth / ( float(FontTex.Width)/16 ) ) *chars[ascii].h;//chars[ascii].h; int charSpace=( charWidth / ( float(FontTex.Width)/16 ) ) *characterSpace; Graphics.DrawTexturePart(FontTex, X, Y, charW, charH, chars[ascii].x, chars[ascii].y, chars[ascii].w, chars[ascii].h, colorR, colorG, colorB); //Move over the width of the character with one pixel of padding X += charW+charSpace;//+10;//chars[ ascii ].w + 10; } } }}
[Edited by - Dandi8 on July 11, 2010 2:31:46 PM]