How to draw transparent rubberband on OpenGL scene

2k Views Asked by At

i'm using OpenGL for showing grabbed frames from video camera with texture mapping. There is no problem at all but i have to select some region of the grabbed frame then i have to zoom it, first of all i can't draw a Rubber rectangle it must be transparent when i select the some region of grabbed frame i have to see textured frame transparently could you gimme some piece of code or clue, btw i'm showing grabbed frames like that any suggestion will be good for me...

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();
}

I'm passing captured frame data to setTextureData it's working but i dunno does it good way ...


Thanks for reply @genpfault,

i used x1=0, y1=0, x2=1, y2=1 but it's drawing rectangle to all texture area. and draws 1 more rectangle to coordinates x1,y1... . How can i fix it. Btw how can i remove that rectangle ?, There is one more issue if i draw a rectangle then texture again rectangle going invisible ...

1

There are 1 best solutions below

0
On BEST ANSWER

Just draw a translucent (alpha < 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);