First, you need to "unwrap" the mesh. This isn't easy to do
algorithmically, and is normally done by hand in a modelling package such
as 3DS or Blender. For a closed surface, you have to add seams so that the
mesh can be mapped to a flat plane. Unwrapping requires some amount of
practice to do well (i.e. minimising distortion, scale variation and the
number of seams, and maximising the proportion of the texture area which
is used).
Chances are that whichever modelling package you use for unwrapping
will also allow vertex colours to be "baked" into a texture. Failing that,
you can generate a texture by rendering the mesh to a texture (e.g. using
glFramebufferTexture, or just using software rendering), using the texture
coordinates as vertex coordinates.