begin of the reimplementation of render_states. segfault for the moment.