OpenGl中DDA算法画直线

void DDALine(int x0,int y0,int x1,int y1)
{
	
	int dx,dy,epsl,k;
	float x,y,xIncre,yIncre;
	dx = x1 - x0;
	dy = y1 - y0;
	x = x0;
	y = y0;

	if(abs(dx)>abs(dy))
		epsl=abs(dx);
	else
		epsl=abs(dy);

	xIncre=(float)dx/(float)epsl;
	yIncre=(float)dy/(float)epsl;
	glPointSize(2);
	glBegin(GL_POINTS);
	for(k = 0;k <= epsl; k++)
	{
		glColor3f(1.0f, 0.0f, 0.0f);
		glVertex2f(int(x+0.5),int(y+0.5));
		x += xIncre;
		y += yIncre;
	}
	glEnd();

}

你可能感兴趣的:(OpenGL)