I want to do something like this:
currentBlendFunc = glGetCurrentBlendFunc();
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// [...] do stuff
glBlendFunc(currentBlendFunc.src, currentBlendFunc.dest);
Is there a way to get the current blend func?
Years later, I ran in the same issue, the docs still are unclear or bugged.
@don's solution in incompleted/buggy though, you also need to restore the _RGB
values :
GLint last_blend_src_rgb; glGetIntegerv(GL_BLEND_SRC_RGB, &last_blend_src_rgb);
GLint last_blend_dst_rgb; glGetIntegerv(GL_BLEND_DST_RGB, &last_blend_dst_rgb);
GLint last_blend_src_alpha; glGetIntegerv(GL_BLEND_SRC_ALPHA, &last_blend_src_alpha);
GLint last_blend_dst_alpha; glGetIntegerv(GL_BLEND_DST_ALPHA, &last_blend_dst_alpha);
...
glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha);
According to the documentation the function that you are looking for is glGet with the arguements GL_BLEND_SRC, GL_BLEND_DST. This is one of the annoyances of OpenGL is that the get and sets don't match up (amongst other things).
I just ran into this exact same situation. Here is my approach to save off the previous blend state and restore when done.
// save off current state of blend enabled
GLboolean blendEnabled;
glGetBooleanv(GL_BLEND, &blendEnabled);
// save off current state of src / dst blend functions
GLint blendSrc;
GLint blendDst;
glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrc);
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDst);
//
// change blend state... do other stuff
//
// restore saved state of blend enabled and blend functions
if (blendEnabled) {
glEnable(GL_BLEND);
}
else {
glDisable(GL_BLEND);
}
glBlendFunc(blendSrc, blendDst);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With