#### Archived

This topic is now archived and is closed to further replies.

# Draw a line from point a to point b

This topic is 5977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How would I tell OpenGL to start draw at point a(x, y, z) and end the line at point b(x, y, z). So for example the line would start at (1, 0, 0) and end at (0, 2, -3) thx nuke

##### Share on other sites
Easy way:

glBegin(GL_LINES);
glVertex3f(a.x, a.y, a.z);
glVertex3f(b.x, b.y, b.z);
glEnd();

##### Share on other sites
yep... and you can change it's thickness by going:
glLineWidth(width); //1.0f is defalt
-PmanC
lol... i've been programming too much... i just commented instead of writing a sentence.

[edited by - PmanC on June 4, 2002 10:23:24 PM]

heh me 2 thx

##### Share on other sites
and if you didnt know you can also use simple bresenham to draw lines (no 3d you requested sorry this time pal)

  	dx=x1-x0;	dy=y1-y0;	if (dx>0) { sx=1; }	else	if (dx<0) { sx=-1; dx=-dx; }	else {		sx =0;	}	if (dy>0) { sy=1; }	else	if (dy<0) { sy=-1; dy=-dy; }	else {		sy =0;	}	int ax =2*dx;	int ay =2*dy;	if (dy<=dx) {		for (int decy=ay-dx; /**/;x +=sx, decy+=ay) 		{			draw pixel (x, y)						/* take bresenham step */			if (x==x1) {				break;			}			if (decy>=0) {							decy -=ax;				y +=sy;			}		}	}	else {		for (int decx=ax-dy; /**/; y+=sy, decx +=ax)		{draw pixel (x, y)		    			/* take bresenham step */			if (y==y1) {				break;			}			if (decx>=0) {							decx -=ay;				x +=sx;			}		}	}

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 13
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632927
• Total Posts
3009242
• ### Who's Online (See full list)

There are no registered users currently online

×