I am trying to write a small 2D graphics library using SDL. I want to implement the equivalent of the Matrix stack in openGL and implement functions like pushMatrix() and popMatrix() in openGL. I can do all the coding for matrix multiplications. But the need the algorithm for storing that stack and managing the transformations.