0
votes

Im trying to make lighting in opengl, idea of it is to render objects normaly (with any alpha)

GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); 

        GL11.glColor4d(0 , 0 , 1 , 0.5);
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glVertex2d(100 , 100);
        GL11.glVertex2d(100 , 200);
        GL11.glVertex2d(200 , 200);
        GL11.glVertex2d(200 , 100);
        GL11.glEnd();

        GL11.glColor4d(0 , 0 , 1 , 1);
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glVertex2d(300 , 100);
        GL11.glVertex2d(300 , 200);
        GL11.glVertex2d(400 , 200);
        GL11.glVertex2d(400 , 100);
        GL11.glEnd();

and then render lights

GL14.glBlendFuncSeparate(GL11.GL_ZERO, GL11.GL_DST_COLOR, GL11.GL_ONE, GL11.GL_ONE);

        GL11.glColor4d(1 , 1 , 1 , 0.5);
        GL11.glBegin(GL11.GL_QUADS);
        GL11.glVertex2d(100 , 150);
        GL11.glVertex2d(150 , 150);
        GL11.glVertex2d(150 , 100);
        GL11.glVertex2d(100 , 100);
        GL11.glEnd();

so its ignore src color (GL11.GL_ZERO) but keeps dst color (GL11.GL_DST_COLOR) and for alpha its add src alpha and dst alpha, if my thoughts are correct than rect in (100 , 100) need to me same color as right one (300 , 100) but result :

enter image description here

1

1 Answers

0
votes

BlendFunc sets the factor, which the Color is multiplied with. For the Destinationcolor you have set the factor to the Color itself, which gives you the squared result.

Try to set GL11.GL_DST_COLOR to GL11.GL_ONE