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??

XOR style erasing does not work well with colors.
This is normal.


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 :


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 :


black XOR red = red
---       ---   ---
  0   XOR 255 = 255
  0   XOR   0 =   0
  0   XOR   0 =   0

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??

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

Ok Thanks!

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?

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.

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?