Esempio n. 1
0
void main()
{
	int gm=DETECT,gd;
	initgraph(&gm,&gd,"C:\\TC\\BGI");
	DDA(100,100,200,100);
	DDA(200,100,200,200);
	DDA(200,200,100,200);
	DDA(100,200,1000,100);
	BresenhamLine(100,100,150,10);
	BresenhamLine(133,133,150,10);
	BresenhamLine(200,100,150,10);
	BresenhamLine(233,133,150,10);
	DDA(133,133,233,133);
	DDA(233,133,233,233);
	DDA(233,233,133,233);
	DDA(133,233,133,133);
	BresenhamLine(100,100,133,133);
	BresenhamLine(100,200,133,233);
	BresenhamLine(200,100,233,133);
	BresenhamLine(200,200,233,233);
	getch();
	closegraph();
}
Esempio n. 2
0
void SwglLine(GLdouble x1, GLdouble y1, GLdouble z1, GLdouble x2, GLdouble y2, GLdouble z2)
{
	//copy to homogenous coordinate
	GLdouble h1[4]={x1, y1, z1, 1.0};
	GLdouble h2[4]={x2, y2, z2, 1.0};

	GLdouble w1[4]={x1, y1, 0, 1.0}; //window coordinate
	GLdouble w2[4]={x2, y2, 0, 1.0};

	//implement the opengl pipeline here
	swTransformation(h1, w1);
	swTransformation(h2, w2);

	////draw the 2D line
	//glBegin(GL_LINES);
	//	//glColor3fv(colors[index1]);
	//	glVertex2f(w1[0], w1[1]);
	//	//glColor3fv(colors[index2]);
	//	glVertex2f(w2[0], w2[1]);
	//glEnd();

	//implement
	switch(DRAWTYPE) {
		case 0:
		{
			writepixel(w1[0], w1[1], 0, 1, 0, 0); //writepixel(w1[0], w1[1], 1, 0, 0);
			writepixel(w2[0], w2[1], 0, 0, 1, 0); //writepixel(w1[0], w1[1], 1, 0, 0);
		}
		break;

		case 1: case 2: case 3:
		{
			GLdouble col[4];
			glGetDoublev(GL_CURRENT_COLOR, col);
			BresenhamLine(w1[0], w1[1], w1[2], w2[0], w2[1], w2[2], col[0], col[1], col[2]);
		}
		break;
	}
}