- Home /
GL drawing optimization
Well, here is the deal: I'm trying to make a really simple program for drawing, using GL (the program has to work for Mobile devices), but I'm having a hard time trying to make a simple "erase" option.
What happens, apart from the code below, is just another script capturing mouse/finger movement and, whenever that movement happens, that script adds a position to the "posList" variable. After that, if the user stops pressing the mouse button, or lifts his finger, the Vector (-1, 0, 0) is added instead of a position.
Here is the code for drawing the pixel matrix:
private Material mat;
private Color lineColor = Color.black;
public List<Vector2> posList = new List<Vector2>();
void Start () {
mat = Resources.Load ("Line") as Material;
}
void OnPostRender() {
GL.PushMatrix();
mat.SetPass(0);
GL.LoadPixelMatrix();
GL.Color(lineColor);
GL.Begin(GL.LINES);
if (posList.Count > 0) {
for (int i = 0; i < posList.Count-1; i++) {
if (posList[i].x != -1 && posList[i+1].x != -1) {
GL.Vertex3(posList[i].x, posList[i].y, 0);
GL.Vertex3(posList[i+1].x, posList[i+1].y, 0);
}
}
}
GL.End();
GL.PopMatrix();
}
The most obvious way to do it would be to select an "eraser", go through the entire list of positions and check for each position's distance to the current input; if it would be less that the eraser's radius, erase that vector and add a new Vector (-1, 0, 0) to the nearest position that was not erased (so that there is still a "jump" without pixels between positions).
This is also obviously too "heavy" for a mobile device (might even be for a computer, depending on the amount of positions stored...). Is there a better way of doing this? (Of course, without just adding a layer of white color on top of the positions; that's cheating... x) )
Thanks in advance
Your answer
