Camera follow object.

can anyone give me some clues on how i make the camera follow an object as i move the object left or right in 2D?

object position: (objx, objy)
camera pisition: (camx, camy)

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho...
glTranslatef(-camx, -camy, 0.0f);

glMatrixModw(GL_MODELVIEW);
glLoadIdentity();

DrawStaticWorld();

glPushMatrix();
glTranslatef(-camx, -camy, 0.0f);
DrawObject();
glPopMatrix();

That’s it - now you must only make camx,camy follow objx,objy in any way you want. Simplest would be:
camx = objx;
camy = objy;

That’s better:

glMatrixModw(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(-camx, -camy, 0.0f);

DrawStaticWorld();

The camera position and orientation defines the transformation from world to view space, thus it should be part of the modelview matrix.

If you’re using the GL matrix stack with separate projection and modelview matrices at all then at least separate them the right way.