Results 1 to 3 of 3

Thread: alpha blending

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2007
    Posts
    1

    alpha blending

    I want to draw a box with GL_LINES, connect 4 lines to form a box

    Then draw a line that passes through the box created above.

    When the line is around the area of the box, line should not be visible for the area of box

    How can I achieve this, I am not understanding alpha blending correctly.

    The code is below


    //I can draw a black occlusion zone around the lined box, but it is not preferred so commented here
    /*
    glPushMatrix();
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);

    glColor3f(0.20, 0.20, 0.60);

    glBegin(GL_POLYGON);
    glVertex2f(-62, 62);
    glVertex2f( 62, 62);
    glVertex2f( 62, -2);
    glVertex2f(-62, -2);
    glEnd();

    glBlendFunc(GL_ONE, GL_ZERO);
    glDisable(GL_BLEND);

    glPopMatrix();
    */


    // Here I am drawing the lined Box before drawing the lines that passes through it
    glPushMatrix();
    glLineWidth(2);
    glColor3f(1.0, 1.0, 0.95);
    glBegin(GL_LINES);
    glVertex2f(-60, 0);
    glVertex2f(60, 0);
    glVertex2f(-60, 60);
    glVertex2f(60, 60);
    glVertex2f(60, 60);
    glVertex2f(60, 0);
    glVertex2f(-60, 0);
    glVertex2f(-60, 60);
    glEnd();
    glPopMatrix();




    // Here I am drawing a white line with width 2, this should not be visible when it goes over or under the
    // lined box area. I can draw the occlusion zone and change the order to do it. But I would like to know
    // how we can change this using alpha blending. The order has to be same, the background color I did is orange.

    glColor3f(1.0, 1.0, 1.0);

    glPushMatrix();


    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE);

    glLineWidth(2);
    glBegin(GL_LINES);
    glVertex2f(-120, 30);
    glVertex2f(120.0, 30.0);
    glEnd();


    glDisable(GL_BLEND);

    glPopMatrix();


    How can I do this using blend function. Lines should be visible all other area except the lined box area. If I draw
    the box occlusion zone, this will not match with the background image (which is a video, color is not the same always).
    Please help me.
    ntpkd

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: alpha blending

    Perhaps you could use scissor test or stencil to mask off the box area

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    20

    Re: alpha blending

    There can be many ways to achieve this effect.

    You can draw your line first, then turn off depth test and then draw your box. (So box pixels will override any line pixels even though line pixels are closer ones).

    Alpha blending is usually used for transparency. Like glass windows, fog or other sfx (when implemented as textures), etc. Not to hide parts of your object (unless you want to hide them permamently, but then why to bother gpu with sending this data to it?).


    Oh and you can always draw your box and line with the same color, and you will get your effect without any additional fuss. ;P

Similar Threads

  1. alpha blending
    By pommeC in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-05-2018, 05:22 AM
  2. Replies: 3
    Last Post: 06-16-2011, 12:51 PM
  3. alpha blending without modifying destination alpha
    By GordAllott in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 09-21-2009, 04:15 AM
  4. Source Alpha Blending without an Alpha Buffer
    By niallm in forum OpenGL ES
    Replies: 1
    Last Post: 06-18-2009, 02:51 AM
  5. alpha blending bug?
    By in forum OpenGL: User Software
    Replies: 1
    Last Post: 02-12-2001, 06:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean