2012-10-12 44 views
1

我有擦除功能的應用程序。例如,我打開彩色圖像,它在它的頂部添加了灰度圖層,並且使用鼠標我可以擦除頂部(灰度)圖層部分。稍後有能力將圖像保存到文件。如果儲蓄像素作爲GL_RGB它的工作原理確定:glReadPixels GL_RGBA格式

enter image description here

而且如果保存像素作爲GL_RGBA我有一些問題(白色空間是透明的):

enter image description here

原始版本的圖像被繪製到framebuffer1,然後應用程序繪製畫筆描邊到framebuffer2,然後灰度版本的圖像被繪製到framebuffer3。然後,所有這些幀緩衝器被繪製到main_framebuffer,並且main_framebuffer被繪製到屏幕。擦除通過glBlendFuncglBlendFuncseparate完成。在做glReadPixels時,像素來自main_framebuffer。哪裏可以成爲我的問題?


brigadir

現在我畫主幀緩衝這樣的:

glPushMatrix(); 
glLoadIdentity(); 
glViewport(0, 0, _width, _height); 
glMatrixMode(GL_PROJECTION); 
glFrustum(0, _width, 0, _height, 0.1, 100); 
glTranslatef(0.0,0.0,-0.5); 
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, main_framebuffer); 
glClearColor(0.93, 0.93, 0.93, 1.0); 
glClear(GL_COLOR_BUFFER_BIT); 
glViewport(0, 0, _width, _height); 
glDisable(GL_DEPTH_TEST); 
glDepthMask(GL_FALSE); 
glEnable(GL_TEXTURE_2D); 
glEnable(GL_BLEND); 

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
glBindTexture(GL_TEXTURE_2D, framebuffer1_texture); 
glBegin(GL_QUADS); 
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0, _height); 
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0, 0.0); 
glTexCoord2f(1.0f, 1.0f); glVertex2f(_width, 0.0); 
glTexCoord2f(1.0f, 0.0f); glVertex2f(_width, _height); 
glEnd(); 
glBindTexture(GL_TEXTURE_2D, 0); 

glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_DST_COLOR, GL_ZERO); 
glBindTexture(GL_TEXTURE_2D, framebuffer2_texture); 
glBegin(GL_QUADS); 
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); 
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, _height); 
glTexCoord2f(1.0f, 1.0f); glVertex2f(_width, _height); 
glTexCoord2f(1.0f, 0.0f); glVertex2f(_width, 0.0f); 
glEnd(); 
glBindTexture(GL_TEXTURE_2D, 0); 

glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA); 
glBindTexture(GL_TEXTURE_2D, framebuffer3_texture); 
glBegin(GL_QUADS); 
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); 
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, _height); 
glTexCoord2f(1.0f, 1.0f); glVertex2f(_width, _height); 
glTexCoord2f(1.0f, 0.0f); glVertex2f(_width, 0.0f); 
glEnd(); 
glBindTexture(GL_TEXTURE_2D, 0); 
glDisable(GL_BLEND); 

glColorMask (0.0, 0.0, 0.0, 1.0); 
glBegin(GL_QUADS); 
glColor4f(1.0, 1.0, 1.0, 1.0); 
glVertex2f(0.0, oglAukstis); 
glColor4f(1.0, 1.0, 1.0, 1.0); 
glVertex2f(0.0, 0.0); 
glColor4f(1.0, 1.0, 1.0, 1.0); 
glVertex2f(oglPlotis, 0.0); 
glColor4f(1.0, 1.0, 1.0, 1.0); 
glVertex2f(oglPlotis, oglAukstis); 
glEnd(); 

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 
glPopMatrix(); 

當我嘗試早些時候在這個問題上加載相同的圖像,因爲我得到:
enter image description here

當我保存它時,我得到: enter image description here

回答

3

您應該禁止寫入主緩衝區的alpha通道。

// draw framebuffers 1-3 ... 
glColorMask (true, true, true, false); 
// render to main buffer ... 
glColorMask (true, true, true, true); // revert to default state 
+0

來到這裏說這個,看起來像你打敗了我。 – rjacks

+0

已更新的問題與結果 – hockeyman

+0

Julius在第一批「glColorMask」調用中設置了「(true,true,true,false)」 – brigadir