Hello there,
I’m trying to do a light mask with OpenGL.
I have a texture rendered in the background, i have light sources and i have a fragment shader generating light halo around given light.
What i can do actually:
I can render a halo of the light color around lights separately from the background texture
What i’m trying to do:
I want that the background image take the color of my light (not sure if this is very clear but i don’t want my light to be above the background, i want my light to change the background color)
I attempted to use blend equations to do that,
Here is my actual code:
private void render() {
glClear(GL_COLOR_BUFFER_BIT);
glBlendFunc(GL_ONE, GL_ONE);
Texture.TEXTURE.bind();
glBegin(GL_QUADS);
glColor4f(1f, 1f, 1f, 1);
glTexCoord2d(0, 0); glVertex2f(0, 0);
glTexCoord2d(1, 0); glVertex2f(width, 0);
glTexCoord2d(1, 1); glVertex2f(width, height);
glTexCoord2d(0, 1); glVertex2f(0, height);
glEnd();
Texture.TEXTURE.unbind();
glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
for (Light light : lights) {
glUseProgram(shaderProgram);
glUniform2f(glGetUniformLocation(shaderProgram, "lightLocation"), light.location.getX(), height - light.location.getY());
glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), light.red, light.green, light.blue);
glBegin(GL_QUADS); {
glVertex2f(0, 0);
glVertex2f(0, height);
glVertex2f(width, height);
glVertex2f(width, 0);
} glEnd();
glUseProgram(0);
}}
According to the andersriggelsen simulator (can’t put the link here), with the given parameters of blGlendFunc and with a gradiant background the result looks just like what i’m trying to do but my screen is black using this code…
Also: testing with the gradiant from the andersriggelsen simulator on my project does work like a charm (and yes my fragment shader is correct, without the blend it generate a perfect light halo)
Thanks you in advance