dvm
06-16-2004, 05:28 AM
Hello to everyone. Today I came across a small problem in my opengl app. My program needs to draw a trace line of the mouse (record the actions and replay later, in real-time). Because the program is going to be used with a touch screen I needed a different way to represent the trace line when the left mouse button was down and when it was up. So I thought I'd represent the mouse move with a line_strip when the button is down and with points when the button is up.
After a lot of thinking I finally came up with the algorithm to do this (the trace line is drawn in real time):
for (i = 0; i < g_cTraceLine.size(); i+=2) {
// if ButtonTrace[i / 2] is true the mouse button is down.
if (ButtonTrace[i / 2]) {
//draw line strip
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
// if the ButtonTrace changes then end line_strip mode
for (int j = i; ButtonTrace[i / 2] == ButtonTrace[j / 2]; j+=2) {
glVertex2i(g_cTraceLine[j], g_cTraceLine[j + 1]);
}
glEnd();
}
else {
//draw points
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_POINTS);
for (int j = i; ButtonTrace[i / 2] == ButtonTrace[j / 2]; j+=2) {
glVertex2i(g_cTraceLine[j], g_cTraceLine[j + 1]);
}
glEnd();
}
}g_cTraceLine is a c++ vector, as is ButtonTrace.
What I do is have two vectors, g_cTraceLine which holds the mouse coordinates and ButtonTrace which is half the size of g_cTraceLine and for each mouse move holds the button's state at the moment. But when I use the code, after a few seconds it starts to get really slow (a 15 second trace file, takes over a minute to complete). If I decide to draw only in points or only in line_strip then the speed is ok. Does anyone have any idea what might be causing this? I should mention that the g_cTraceLine and ButtonTrace vectors increase with each frame (I don't read the whole trace before hand, but again if I switch to only one type of drawing there's no speed problem).
Also a smaller problem, why when painting the GL_POINTS they seem to be black? I tried changing the color before but they're always black. Thank you for your patience and your time.
After a lot of thinking I finally came up with the algorithm to do this (the trace line is drawn in real time):
for (i = 0; i < g_cTraceLine.size(); i+=2) {
// if ButtonTrace[i / 2] is true the mouse button is down.
if (ButtonTrace[i / 2]) {
//draw line strip
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
// if the ButtonTrace changes then end line_strip mode
for (int j = i; ButtonTrace[i / 2] == ButtonTrace[j / 2]; j+=2) {
glVertex2i(g_cTraceLine[j], g_cTraceLine[j + 1]);
}
glEnd();
}
else {
//draw points
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_POINTS);
for (int j = i; ButtonTrace[i / 2] == ButtonTrace[j / 2]; j+=2) {
glVertex2i(g_cTraceLine[j], g_cTraceLine[j + 1]);
}
glEnd();
}
}g_cTraceLine is a c++ vector, as is ButtonTrace.
What I do is have two vectors, g_cTraceLine which holds the mouse coordinates and ButtonTrace which is half the size of g_cTraceLine and for each mouse move holds the button's state at the moment. But when I use the code, after a few seconds it starts to get really slow (a 15 second trace file, takes over a minute to complete). If I decide to draw only in points or only in line_strip then the speed is ok. Does anyone have any idea what might be causing this? I should mention that the g_cTraceLine and ButtonTrace vectors increase with each frame (I don't read the whole trace before hand, but again if I switch to only one type of drawing there's no speed problem).
Also a smaller problem, why when painting the GL_POINTS they seem to be black? I tried changing the color before but they're always black. Thank you for your patience and your time.