Reputation: 113
I'm implementing a renderer where the shading requires front-to-back rendering. I'm having issues figuring out how to initialize the blending function.
Here's what I tried.
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
This results in a black screen.
The blog post says to use GL_ONE_MINUS_DST_ALPHA, GL_ONE and initialize the background to all black all translucent, which is what I think I'm doing. The post cites an nvidia whitepaper so I looked into that as well. I looked through the code there and they seem to do somewhat the same as me. However something is clearly wrong as it isn't working. If I don't use blending or use other blending functions things seem to work.
EDIT:
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutCreateWindow("Window");
Upvotes: 0
Views: 605
Reputation: 54592
You need to specifically request alpha planes during your GLUT initialization if you use blending that involves destination alpha. Change the call to:
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA);
You might think that specifying GL_RGBA
would be sufficient. At least I did, until I just checked the documentation, which says:
Note that GLUT_RGBA selects the RGBA color model, but it does not request any bits of alpha (sometimes called an alpha buffer or destination alpha) be allocated. To request alpha, specify GLUT_ALPHA.
Upvotes: 1