PDA

View Full Version : GL_LINES



01-29-2001, 04:44 PM
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();
}

mango
01-29-2001, 05:44 PM
Yes, the function drawLine seems to be OK. You can set a breakpoint and check the values.

stefkeb
01-30-2001, 05:12 AM
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);

Relic
01-30-2001, 07:01 AM
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.