It works just fine with the stencil buffer/mirror demo of Sascha Willems which does not use SDL. My code is quite the same as his one. So I suppose it's just some problem with SDL. Not with my graphics card.