Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: GL_XOR

  1. #1
    Junior Member Regular Contributor
    Join Date
    Mar 2010
    Posts
    209

    GL_XOR

    Hello everyone..

    Im trying to draw erasable lines using the XOR method..
    ie draw a line in XOR mode, you get a line, then XOR it, it disappears..

    But im facing the problem of generation of new colors!! since im XORing, the disppaearing of the old lines is happening, but the new line is of a different color..Is there any way i could solve this?? Heres the code:

    void MouseMove(int x,int y)
    {

    if(FLAG == 0){
    X = x;
    Y = winh - y;

    Xn = x;
    Yn = winh - y;

    FLAG = 1;
    }

    else if(FLAG == 1){
    glEnable(GL_COLOR_LOGIC_OP);
    glLogicOp(GL_XOR);

    glBegin(GL_LINES);
    glVertex2i(X,Y);
    glVertex2i(Xn,Yn);
    glEnd();
    glFlush();/*Old line erased*/

    glBegin(GL_LINES);
    glVertex2i(X,Y);
    glVertex2i(x, winh - y);
    glEnd();
    glFlush();

    Xn = x;
    Yn = winh - y;
    }
    }
    This is my mouse motion callback..Now if the screen is colored to white and if i choose my current drawing color as RED, i get a bluish color due to the XORing..How to overcome this??

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: GL_XOR

    XOR style erasing does not work well with colors.
    This is normal.
    Code :
    white XOR red = cyan
    ---       ---   ---
    255   XOR 255 =   0
    255   XOR   0 = 255
    255   XOR   0 = 255
    If you know that your background is pure white, negate your color :
    Code :
    white XOR cyan= red
    ---       ---   ---
    255   XOR   0 = 255
    255   XOR 255 =   0
    255   XOR 255 =   0
    If you know that your background is pure black, keep the original color :
    Code :
    black XOR red = red
    ---       ---   ---
      0   XOR 255 = 255
      0   XOR   0 =   0
      0   XOR   0 =   0

  3. #3
    Junior Member Regular Contributor
    Join Date
    Mar 2010
    Posts
    209

    Re: GL_XOR

    Thank you Zbuffer..
    Im actually leavin the choice of color for the user..

    Let the user choose a color:
    say given as
    r = 0.7490 (r = 191)
    g = 0.5882 (g = 150)
    b = 0.5882 (b = 150)

    Now i just multiply r,g,b by 255,

    r *= 255;
    g *= 255;
    b *= 255;

    then,
    glColor3f(~r/255.0,~g/255.0,~b/255.0);

    Well this is working fine..Will there be amy bugs if i use this method or is it fine for White background??

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: GL_XOR

    No, sound fine.
    You can simplify a bit by using glColor3ub (unsigned bytes) instead of glColor3f :
    glColor3ub(~r,~g,~b);

    For generalized backround color :
    glColor3ub(backgroundr^r,backgroundg^g,backgroundb ^b);

  5. #5
    Junior Member Regular Contributor
    Join Date
    Mar 2010
    Posts
    209

    Re: GL_XOR

    Ok Thanks!

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    3

    Re: GL_XOR

    I am using the same technique to draw and erase a line. But, even though I am redrawing on a line to erase it, i am not able to erase. What I am getting is a bunch of lines on mouse move. Could anyone tell me the possible reason for it?

  7. #7
    Junior Member Regular Contributor
    Join Date
    Jun 2009
    Location
    FL , USA
    Posts
    194

    Re: GL_XOR

    Quote Originally Posted by shiva
    But, even though I am redrawing on a line to erase it, i am not able to erase. What I am getting is a bunch of lines on mouse move. Could anyone tell me the possible reason for it?
    Are you drawing exactly over the line to be erased? The technique you are referring to is doing color changing w.r.t background to give you illusion of line deletion.
    Perhaps your mouse movement is exactly not over the line and is replacing color of some other portion ;for deletion.

  8. #8
    Junior Member Newbie
    Join Date
    Dec 2011
    Posts
    3

    Re: GL_XOR

    I am drawing exactly over the same line. I am storing the coordinates when drawn, and erasing the old line when the mouse goes to a new point. Has it anything to do with the settings?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •