图形学的错误,求大侠指点
/***********************Bresenham画直线算法*********************/#include<graphics.h>
#include<conio.h>
#include <windows.h>
int driver,mode;
/***********************Declare Functions**********************/
void graphic_mode_init();/*初始化图形模式*/
void grahic_mode_close();/*退出图形模式*/
void Bresenhamline(int x0,int y0,int x1,int y1,int color)
{
int x,y,dx,dy;
float k,e;
dx = x1-x0;
dy = y1-y0;
k = dy/dx;
e = -0.5;
x = x0;
y = y0;
for(int i = 0;i<=dx;i++)
{
putpixel(x,y,color);
x = x+1;
e = e+k;
if(e>=0)
{
y++;
e=e-1;
}
}
//getch();
//closegraph();
}
void graphic_mode_init() /*初始化图形模式*/
{
//detectgraph(&gdriver,&gmode);
driver = DETECT;
mode = 0;
initgraph(&driver,&mode,"c:\\tc");
//setbkcolor(14);
Sleep(100);
}
void grahic_mode_close()/*退出图形模式*/
{
closegraph();
}
int main()
{
graphic_mode_init();
Bresenhamline(5,5,50,50,15);
getch();
grahic_mode_close();
return 0;
}
红颜色是我们教课书的源程序,其余是我添加的,可是就是画不出图像来。
求大虾指点指点