我想要做的是在明亮的紅色(1,0,0, 1)。對於第一層它工作正常,結果是(0.9,0,0,1);但是,當紅色值達到0.5時,它不能低於該值。OPENGL混合功能 - 以分層方式緩慢替換顏色
第一層表現出以下等式,並且正常工作:進一步
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 // Here is the result
現在向下許多層後的線,它會得到一個點,所述目標顏色較暗:0.5,現在色彩永遠不會爲證明它下面有0.5,0,0開始任何較深,但結果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
下面是這意味着顏色緩衝區並沒有改變結果和我的色彩覆蓋不再有任何效果。
我怎樣才能讓我的深紅色層,直到它取代明亮的紅色?
簡單加工SKETCH證明了問題 - 你會發現在這裏我想GL_SRC_ALPHA,它仍然有一個問題:在所需
http://studionu.net/files/OPENGL_test.zip
下圖描述了右邊的左邊的問題影響。
編輯這裏是代碼
因此,這裏是我的代碼:
我成立了一個紋理緩衝對象和附加到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);'
然後清除幀緩衝區:
' 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); '
在這裏,我綁定幀緩衝區,並吸引到它,我設定的顏色在這裏膨脹:
' 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); '
這裏我繪製紋理屏幕:
' 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(); '
我選擇GL_ONE作爲源的因素,因爲我沒有任何背景,所以抽取因爲顏色緩衝區將不會出現第一個位基本上是0在各方面RGBA至少那它做什麼對我來說,當我不有任何背景。如果背景不透明SRC_ALPHA在某種程度上起作用。 – Carson
BTW蒂姆,你有處理,我可以給你一個複製問題的簡單草圖?這裏是:http://studionu.net/files/OPENGL_test.zip嘗試一下,讓我知道。 SRC_ALPHA也會遇到這個問題,因爲您會看到 – Carson
我不同意SRC_ALPHA存在同樣的問題,請參閱我的編輯(我沒有該軟件)。 – Tim