What I'm trying to do is add a dark red color with alpha (0,1,0,0,0,2,2) over bright red (1,0,0,1). For the first layer, it works fine, the result is (0.9, 0, 0, 1); However, when the red value reaches 0.5, it cannot fall below this value.
The first layer is demonstrated with the following equation and works fine:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); ColorBuffer color = (1,0,0,1) Bright Red SourceColor color = (0.1,0,0,0.2) Dark Red GL_ONE = 1 , GL_ONE_MINUS_SRC_ALPHA = 1 - 0.2 = 0.8 Cf = (ColorSource * One) + (ColorBuffer * One Minus Src Alpha); Cf = ((0.1,0,0)*1 ) + ((1,0,0) * 0.8); Cf = 0.1,0,0 + 0.8,0,0; Cf = 0.9,0,0
Now, dropping below the line after many layers, it will reach the point where the destination color is darker: 0.5, now the color never becomes darker, as shown below, it starts with 0.5.0.0, but leads to 0.5, 0.0:
Cf = ((0.1,0,0)*1 ) + ((0.5,0,0) * 0.8); Cf = 0.1,0,0 + 0.4,0,0; Cf = 0.5,0,0
Here is the result, which means that the color buffer has not changed, and the color that I apply no longer has any effect.
How do I get my dark red layer until it replaces bright red?
SIMPLE PROCESSED GASKET PROBLEM DEMONSTRATION - You will notice that I am trying to use GL_SRC_ALPHA, and it still has this problem:
http://studionu.net/files/OPENGL_test.zip
The image below describes the problem with LEFT on the RIGHT - desired effect.
CHANGE HERE CODE
So here is my code:
I set the texture buffer object and connected to FBO:
'gl.glGenTextures(1, drawTex, 0); gl.glBindTexture(GL.GL_TEXTURE_2D, drawTex[0]); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA8, 1000, 500, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, null); ' ' // Creating FBO. gl.glGenFramebuffersEXT(1, drawFBO, 0); gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, drawFBO[0]); gl.glFramebufferTexture2DEXT(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_TEXTURE_2D, drawTex[0], 0); int stat = gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_EXT); if (stat != GL.GL_FRAMEBUFFER_COMPLETE_EXT) System.out.println("FBO error"); gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);'
Then I clear the frame buffer:
' gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, drawFBO[0]); // Drawing to the first color attachement of drawFBO (this is where drawTex is attached to). gl.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0_EXT); gl.glViewport(0, 0, 1000, 500); gl.glColor4f(0.0, 0.0, 0.0, 0.0); gl.glClear(gl.GL_COLOR_BUFFER_BIT); // Unbinding drawFBO. Now drawing to screen again. gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0); '
Here I snap the framebuffer and draw into it, and I set the color here:
' gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, drawFBO[0]); // Drawing to the first color attachement of drawFBO (this is where drawTex is attached to). gl.glDrawBuffer(GL.GL_COLOR_ATTACHMENT0_EXT); // Setting orthographic projection. gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glOrtho(0.0, 1000, 0.0, 500, -100.0, +100.0); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glViewport(0, 0, 1000, 500); gl.glDisable(GL.GL_TEXTURE_2D); gl.glEnableClientState(GL.GL_VERTEX_ARRAY); gl.glVertexPointer(2, GL.GL_FLOAT, 0, paintBuffer); // gl.glHint (gl.GL_POINT_SMOOTH_HINT, gl.GL_NICEST); // gl.glEnable(gl.GL_POINT_SMOOTH); gl.glEnable(gl.GL_VERTEX_PROGRAM_POINT_SIZE); gl.glEnable(gl.GL_BLEND); gl.glEnable(gl.GL_DEPTH_TEST); gl.glDepthFunc(gl.GL_NICEST); gl.glDisable(gl.GL_ALPHA_TEST); gl.glAlphaFunc(gl.GL_LESS, 0.01); gl.glPointSize(35.0); float kBrushOpacity = 0.05/3.0; println(kBrushOpacity); float colorchange = 1.0; if (timer>200) { colorchange = 0.5; //////COLOR GETS DARKER } if (timer>400) { //colorchange = 0.2; //////COLOR GETS DARKER AGAIN } timer++; gl.glDisableClientState( gl.GL_COLOR_ARRAY ); gl.glColor4f(colorchange, 0, 0.0, kBrushOpacity); gl.glBlendFuncSeparate(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA,gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_DST_ALPHA);////////THIS IS THE OPENGL BLEND EQUATION FOR PREMULTIPLIED COLORS gl.glDrawArrays(GL.GL_POINTS, 0, count); //Count tells us how many point exist to be drawn. gl.glDisable(gl.GL_BLEND); //Dont use blend when drawing the texture to screen. Just draw it. gl.glDisableClientState(GL.GL_VERTEX_ARRAY); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); // Unbinding drawFBO. Now drawing to screen again. gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0); '
Here I draw a texture for the screen:
' gl.glDrawArrays(GL.GL_POINTS, 0, count); //Count tells us how many point exist to be drawn. gl.glDisable(gl.GL_BLEND); //Dont use blend when drawing the texture to screen. Just draw it. gl.glDisableClientState(GL.GL_VERTEX_ARRAY); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); // Unbinding drawFBO. Now drawing to screen again. gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0); // Setting orthographic projection. gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glOrtho(0.0, width, 0.0, height, -100.0, +100.0); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glViewport(0, 0, width, height); // Drawing texture to screen. gl.glEnable(GL.GL_TEXTURE_2D); gl.glActiveTexture(GL.GL_TEXTURE0); gl.glBindTexture(GL.GL_TEXTURE_2D, drawTex[0]); gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f(0.0, 1.0); gl.glVertex2f(0.0, 0.0); gl.glTexCoord2f(1.0, 1.0); gl.glVertex2f(width, 0.0); gl.glTexCoord2f(1.0, 0.0); gl.glVertex2f(width, height); gl.glTexCoord2f(0.0, 0.0); gl.glVertex2f(0.0, height); gl.glEnd(); gl.glBindTexture(GL.GL_TEXTURE_2D, 0); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); '