Advertisement

Draw a line from point a to point b

Started by June 04, 2002 09:08 PM
3 comments, last by Nukem 22 years, 8 months ago
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
--------------------------Nukemmsn: nukem996@hotmail.comaim: nukem996open source open mind
Easy way:

glBegin(GL_LINES);
glVertex3f(a.x, a.y, a.z);
glVertex3f(b.x, b.y, b.z);
glEnd();
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Advertisement
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
--------------------------Nukemmsn: nukem996@hotmail.comaim: nukem996open source open mind
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;			}		}	}  



This topic is closed to new replies.

Advertisement