I'm getting started with graphics and I'm having trouble implementing the Bresenham's algorithm. Now, I know that my implementation is incomplente, but I can't see why it doesn't make horizontal lines(same height(y) values, different width(x values). I get a floating point exception. Here's the algo:
int draw_line(void *mlx_ptr, void*win_ptr, t_2dpoint *initial_p, t_2dpoint *final_p)
{
53 int delta_x;
53 int delta_x;
54 int y;
55 int delta_y;
56
57 delta_x = final_p->x - initial_p->x;
58 delta_y = final_p->y - initial_p->y;
59
60 x = initial_p->x;
61 y = initial_p->y;
62 e = (float)(delta_x / delta_y) - 1.0;
63
64 while(x < final_p->x - 1)
65 {
66 mlx_pixel_put(mlx_ptr, win_ptr, x, y, 0XFF00FF);
67 if ( e >= 0)
68 {
69 y += 1;
70 e -= 1.0;
71 }
72 x += 1;
73 e += (float)delta_x / delta_y;
74 }
75 mlx_pixel_put(mlx_ptr, win_ptr, x, y, 0XFF00FF);
76 }