Skip to content

Instantly share code, notes, and snippets.

@ofZach
Created February 9, 2021 15:53
Show Gist options
  • Save ofZach/9cc3bf0b0c8e1f22eeae97e3a53fb522 to your computer and use it in GitHub Desktop.
Save ofZach/9cc3bf0b0c8e1f22eeae97e3a53fb522 to your computer and use it in GitHub Desktop.
hunt for blend func
// written by Golan Levin
// for example, huntForBlendFunc(1, -1, -1);
void huntForBlendFunc(float period, int defaultSid, int defaultDid){
// sets all possible (24) combinations of blend functions,
// changing modes every period seconds.
int sfact[] = {
GL_ZERO,
GL_ONE,
GL_DST_COLOR,
GL_ONE_MINUS_DST_COLOR,
GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA,
GL_DST_ALPHA,
GL_ONE_MINUS_DST_ALPHA,
GL_SRC_ALPHA_SATURATE
};
int dfact[] = {
GL_ZERO,
GL_ONE,
GL_SRC_COLOR,
GL_ONE_MINUS_SRC_COLOR,
GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA,
GL_DST_ALPHA,
GL_ONE_MINUS_DST_ALPHA
};
if ((defaultSid == -1) && (defaultDid == -1)) {
int sid = ((int)(ofGetElapsedTimef()*1000)/(8*(int)(period*1000)))%9;
int did = ( (int)(ofGetElapsedTimef()*1000)/(int)((period)*1000))%8;
glEnable(GL_BLEND);
glBlendFunc(dfact[sid], dfact[did]);
printf("SRC %d DST %d\n", sid, did);
} else {
glEnable(GL_BLEND);
glBlendFunc(dfact[defaultSid], dfact[defaultDid]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment