Centering Images

Please Help,

First of all, this forum is great for a newbie like myself. The help I have received has advanced my knowledge of OpenGL tremendously, but I have another question I hope someone can help me with.

I am visualizing ASCII files (made up of a set of pre-defined X, Y, and Z coordinates) that are sometimes not centered (depends on the file). I am able to rotate the resulting images about the 0, 0, 0 area of the screen but, like I said, sometimes I get a file whose coordinates are not centered (i.e., the center point could be arbitarily at some point in the model). My question is this:
What is the most efficient way to make sure that a model is centered so that it can be properly rotated about this center? Is there a bounding box type of object in OpenGL I can use to automatically do this?

Thanks in advance for any help/hints.

No, there are no such functions in OpenGL. It’s an API and such funcitonality would be rather some framework’s / engine’s job.
You have two options:

  1. After you have your object loaded, calculate it’s center point and subtract this point from all object’s vertices - it will be centered then.
  2. If for some reason you don’t want to modify the object after you load it, then you should calculate that center point and render object using the following approach:
glRotatef(...); //rotate your object the way you want
glTranslatef(-centerX, -centerY, -centerZ);
(...) //draw your object here

That glTranslatef will do exactly the same transformatoin I described in #1

Thank you k_szczech for the information. I will try approach #2.