By Request ill explain first then show you how to impliment it:
When centering your text all you have to do is figure out how wide your string is then divide that by 2 and subtract that from the center of what ever your rendering it over. The width paramater can be defined by the string not just an object.
find your center:
center = x + (w/2)
stringlength = strlen(string) * 7 // 7 = the pixel width of the largest char when rendered(yours may be different)
so with those 2 you need to figure out where to place your text
textX = center - (stringlength / 2) // this way id subtract half the length of your string from the center of your object
my function i use: not 100 percent perfect but it gets the job done.
Code:
void CenterText( float x, float y, float w, char* Text, int r, int g, int b)
{
float itextX = x + (w / 2) - strlen(Text)* 7.0f / 2;
float itextY = y + 3.0f;
MyDrawText(itextX, itextY, Text, r, g, b);
}
If anyone knows a better way please clue me in.