2011-04-08 79 views
1

我使用OpenGL從視頻相機中顯示帶紋理貼圖的抓取幀。根本沒有問題,但我必須選擇抓取框架的某個區域,然後我必須放大它,首先我不能繪製橡膠矩形,當我選擇抓取框架的某個區域時它必須是透明的看到紋理邊框透明能不能給我一些代碼片段或線索,順便說一句我展示抓住幀一樣,任何建議將是對我好......如何在OpenGL場景上繪製透明橡皮條

void GLWidget::initializeGL() 
{ 
    glShadeModel(GL_SMOOTH); 
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 
    glClearDepth(1.0f); 
    glEnable(GL_DEPTH_TEST); 
    glDepthFunc(GL_LEQUAL); 
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 
    glEnable(GL_TEXTURE_2D); 
    glGenTextures(1, &m_pTextureId); 
    glBindTexture(GL_TEXTURE_2D, m_pTextureId); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
} 
void GLWidget::resizeGL(int w, int h) 
{ 
    glViewport(0,0,w,h); 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    glOrtho(-1,1,-1,1,-1,1); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
} 
void GLWidget::setTextureData(BYTE *data, int width, int height) 
{ 
    makeCurrent(); 
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
    if (m_isTextured) 
     glTexSubImage2D(GL_TEXTURE_2D,0,0,0,width,height,GL_BGRA_EXT,GL_UNSIGNED_BYTE,data); 
    else 
     glTexImage2D(GL_TEXTURE_2D,0,3,width,height,0,GL_BGRA_EXT,GL_UNSIGNED_BYTE,0); 
    glBindTexture(GL_TEXTURE_2D,m_pTextureId); 
    glBegin(GL_QUADS); 
    glTexCoord2f(0.0,0.0);glVertex2f(-1.0,-1.0); 
    glTexCoord2f(0.0,1.0);glVertex2f(-1.0,1.0); 
    glTexCoord2f(1.0,1.0);glVertex2f(1.0,1.0); 
    glTexCoord2f(1.0,0.0);glVertex2f(1.0,-1.0); 
    glEnd(); 
    swapBuffers(); 
} 

我傳遞捕獲的幀數據setTextureData它的工作,但我不知道它的確好辦法...


感謝您的回覆@genpfault,

我使用了x1 = 0,y1 = 0,x2 = 1,y2 = 1,但它對所有紋理區域繪製矩形。並在座標x1,y1 ...上畫出更多的矩形。我如何解決它。順便說一句我怎麼能刪除矩形,還有一個問題,如果我畫一個矩形,然後再質感矩形會看不見......

回答

2

只是畫一個半透明的(阿爾法< 1.0)rectangle

glEnable(GL_BLEND); 
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
glColor4ub(255, 255, 255, 128); 
glRectf(x1, y1, x2, y2); 
glDisable(GL_BLEND);