cg_draw.c refactoring