Original Post
Hello.
I have a Sprite class which renders parts of its texture invisible using ordinary blending:
(Note, this is Java, using LWJGL, that's why a GL11 is in front of everything)
(I'm manually setting the alpha of certain pixels in the texture to 1.0)
However, I'd now like to combine this blending by also somehow factoring in the alpha values which are already stored in the color buffer.
To be more precise, I'm rendering an invisible light into the RGBA buffer only using alpha values. It starts out with a vertex in the middle of the light with full light intensity as its alpha value and draws the points around it in a triangle fan with 0 alpha. This way, OpenGL interpolates the alpha values for me, creating a smooth decrease in light intensity from the middle of the light to its edge.
Now, my lights are drawn before everything else on the screen. I basically fill the buffer with alpha values, then render everything else on top of it using this kind of blending:
This also works fine and everything that is drawn where the light would be is brightened according to its distance to the center of the light... however, this way of blending geometry and the way my sprites are rendered now conflict.
I can only choose either one of those two, but I'd like to do both at the same time. Is there a way to combine blending functions together? I guess it would be possible too just render the sprites quad twice, once using ordinary blending to mask out certain parts of the texture, and after that again using DST_ALPHA blending to add the light intensities to the color. But this sounds really painful, especially since draw calls using glBegin and glEnd to the graphics card are limited (as far as I know even top notch modern cards can't handle more than a couple of thousand per frame at 60fps due to all the overhead).
This would really help me out a lot, thank you
I have a Sprite class which renders parts of its texture invisible using ordinary blending:
(Note, this is Java, using LWJGL, that's why a GL11 is in front of everything)
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
(I'm manually setting the alpha of certain pixels in the texture to 1.0)
However, I'd now like to combine this blending by also somehow factoring in the alpha values which are already stored in the color buffer.
To be more precise, I'm rendering an invisible light into the RGBA buffer only using alpha values. It starts out with a vertex in the middle of the light with full light intensity as its alpha value and draws the points around it in a triangle fan with 0 alpha. This way, OpenGL interpolates the alpha values for me, creating a smooth decrease in light intensity from the middle of the light to its edge.
GL11.glBegin(GL11.GL_TRIANGLE_FAN);
GL11.glColor4f(0.0f,0.0f,0.0f, m_intensity);
GL11.glVertex3f(m_position.x, m_position.y, m_depth);
GL11.glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
for(int i=0;i<m_vertices.size();++i)
{
Vector2f pos = m_vertices.get(i);
GL11.glVertex3f(m_position.x + pos.x,m_position.y + pos.y,m_depth);
}
GL11.glEnd();
Now, my lights are drawn before everything else on the screen. I basically fill the buffer with alpha values, then render everything else on top of it using this kind of blending:
GL11.glBlendFunc(GL11.GL_DST_ALPHA,GL11.GL_ONE);
This also works fine and everything that is drawn where the light would be is brightened according to its distance to the center of the light... however, this way of blending geometry and the way my sprites are rendered now conflict.
I can only choose either one of those two, but I'd like to do both at the same time. Is there a way to combine blending functions together? I guess it would be possible too just render the sprites quad twice, once using ordinary blending to mask out certain parts of the texture, and after that again using DST_ALPHA blending to add the light intensities to the color. But this sounds really painful, especially since draw calls using glBegin and glEnd to the graphics card are limited (as far as I know even top notch modern cards can't handle more than a couple of thousand per frame at 60fps due to all the overhead).
This would really help me out a lot, thank you