Say I have a triangle with normal X. How do I rotate so it has a given normal Y?

# How to rotate a surface so it has a given normal?

The rotation from X to Y is the same as the desired rotation of the triangle. X x Y = Z is some vector perpendicular to both of those, around which you want to rotate. Assuming the normals are, in fact, normalized, the magnitude Z is the sine of the angle between them. So, you essentially need to use the following call:

glRotatef(arcsin(Z.mag())*180/pi, Z.x, Z.y, Z.z);

Depending on where/how you choose to implement this transformation, there may be a better way that avoids the arcsin. You could go straight to the transformation matrix.