Rubber Lines

Here’s my problem:
I want to draw a rubber line, just like those found in any drawing tool when
you draw a polyline, for example, & a temporary ( rubber ) line is draw
between the mouse cursor and the last point you fixed. This is usually done
in XOR mode to keep the old image data after erasing the old line. Now with
no XOR in SDL, how can this be done with no noticable lag?

TIA,
Mahmoud

Mahmoud Al Gammal wrote:

I want to draw a rubber line, just like those found in any drawing tool when
you draw a polyline, for example, & a temporary ( rubber ) line is draw
between the mouse cursor and the last point you fixed. This is usually done
in XOR mode to keep the old image data after erasing the old line. Now with
no XOR in SDL, how can this be done with no noticable lag?

XOR and other bit-operations are not supported by SDL since they are rarely
useful in games. XOR gives unpredictable results unless you have a very
carefully constructed palette, and requires read-modify-write which is slow.

A modern alternative is to use opaque or alpha-blended lines instead,
since you can usually restore what is underneath anyway. If you insist on
using XOR then you can do it by direct pixel manipulation

Thanks for the hint, but can you give me a general idea of how this is done,
because I tried to use alpha blended lines and I didn’t get the expected
results, so I guess I must be doing something wrong. It’s the first time for
me to have to work with transparent surfaces, so any clue will help a lot.

Thanks again,
Mahmoud> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of Mattias
Engdeg?rd
Sent: Tuesday, January 29, 2002 1:35 AM
To: sdl at libsdl.org
Cc: Mahmoud Al Gammal
Subject: Re: [SDL] Rubber Lines

Mahmoud Al Gammal wrote:

I want to draw a rubber line, just like those found in any drawing tool
when
you draw a polyline, for example, & a temporary ( rubber ) line is draw
between the mouse cursor and the last point you fixed. This is usually done
in XOR mode to keep the old image data after erasing the old line. Now with
no XOR in SDL, how can this be done with no noticable lag?

XOR and other bit-operations are not supported by SDL since they are rarely
useful in games. XOR gives unpredictable results unless you have a very
carefully constructed palette, and requires read-modify-write which is slow.

A modern alternative is to use opaque or alpha-blended lines instead,
since you can usually restore what is underneath anyway. If you insist on
using XOR then you can do it by direct pixel manipulation


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Mahmoud Al Gammal wrote:

Thanks for the hint, but can you give me a general idea of how this is done,
because I tried to use alpha blended lines and I didn’t get the expected
results, so I guess I must be doing something wrong. It’s the first time for
me to have to work with transparent surfaces, so any clue will help a lot.

Assume you can’t get a pointer to the actual display surface then:
Assume you have three buffers, one is a clean copy of the stuff you want
to draw lines on, another is a working copy, and the third is the
actually display surface. Draw the line into the second buffer, and use
SDL_UpdateRect(s) to move the changed pixels onto the display surface.
Then clean up the working surface by blitting from the clean copy onto
the working surface (buffer #2) and draw the line again, rinse and
repeat until done. As long as the line isn’t to long this works pretty
well, but if it gets so long that a major part of the screen is being
blitted each time it will slow down.

BTW, since you will be building your own line code you can use it to
build a special blit that cleans up the second buffer by redrawing the
line but with pixels from the clean buffer rather than with a color.
This approach can be very very much faster than cleaning up using a
blit.

If you CAN get a pointer to the actual display surface, you can use the
your line code and your line blit code to both draw and clean up the
display surface very quickly.

You can use a similar approach using OpenGL buffers. If you have a fast
OpenGL render you should probably do everything in OpenGL.

	Bob Pendleton