GL_LINES

I’m having trouble figuring out how to use this command. I’m not even sure it’s the right one, though the book appears to say it is. I was to draw disconnected line segments, but it keeps starting at 0,0 and drawing to wherever I click, instead of waiting for the mouse button to be depressed, and drawing the line to wherever the button is released, which is what I want. Actually, it does that also, it just continues to connect it to the last point where the mouse button was clicked. Am I using the wrong command? This is my code.

void drawLine(int x1, int y1, int x2, int y2){
glColor3ub(1.0, .0,0.0);
glBegin(GL_LINES);
glVertex2f(x1, y1);
glVertex2f(x2, y2);
// glPushAttrib(GL_ALL_ATTRIB_BITS);
// glPushMatrix();
glEnd();
// glEndList();
glFlush();
}

Yes, the function drawLine seems to be OK. You can set a breakpoint and check the values.

void drawLine(int x1, int y1, int x2, int y2){
glColor3ub(1.0, .0,0.0);
glBegin(GL_LINES);
glVertex2f(x1, y1);
glVertex2f(x2, y2);
glEnd();
glFlush();
}[/b][/QUOTE]

Shouldn’t you cast the int’s to floats?
glVertex2f((float)x1, (float)x2);
or glVertex2i(x1,x2);

This behaviour does not come from the drawing routine, but from the faulty event handler around this.
Check what you’re doing with the mousecoordinates on for the different events (WM_LBUTTONDOWN, -UP, etc.)

One thing which looks wrong in the line routine is glColor3ub(1.0, .0,0.0).
This is almost black but it looks as if you’d like to have red. Use glColor3f(1.0f, 0.0f, 0.0f) or glColor3ub(255, 0, 0) instead.