Note that you can’t give arbitrary gl calls between glbegin and
glend. It is a very small subset of calls which are valid within
glbegin/end, mostly restricted to vertex attributes (position,
texture, color, normals, fog coordinate, etc). other opengl calls
such as any glenable/disable calls must happen before the glbegin
call. Changing this, your example seems to work as expected for me.
See the OpenGL Red Book (p.46 in my edition) for more information on