So, I'm writing a word wrapping function for my text renderer in openGL, which, already works. Just my problem now is to get word wrapping working :S

So, here's the formula:

1 2 3 4 5 6 7 8 9
| for (int a = 0; a < text.length(); a ++){ float frame = (float)((textValues[a] - 32) * charWidth) / fontWidth; float charWidthf = (float) charWidth / fontWidth; int yy = y + ((a / boundWidth) * charHeight) + 1; int xx = (x + (charWidth * (a))); } |

charWidth and charHeight in this case are 5 and 7. fontWidth is the size of the image, which is the charWidth multiplied by 95, as we use 95 ASCII characters.

Now, yy works. It pushes the text downwards the further you get along with the text according to the boundWidth, which is how many chars are allowed horizontally before it needs to be pushed down for wrapping. The problem here is xx, which keeps going right regardless of the push of the wrap.

So, what I need is a mathematical formula so that xx will go back to the starting x position everytime it's wrapped.

Sorry if this a hard question, I'm terrible at explaining this stuff.