X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fgaw%2Fpolyfill.c;h=15c06fb4bb12dbba18bdf5a94da1e6f41342e538;hb=5f50ec3c542ea29211591d4865bdaf1368f8c649;hp=250c152efe5e491dda7c6dceb7b842d5fca47acc;hpb=7fccf8b3543c8cdb993252f0cf9a6b9ed826408e;p=retroray diff --git a/src/gaw/polyfill.c b/src/gaw/polyfill.c index 250c152..15c06fb 100644 --- a/src/gaw/polyfill.c +++ b/src/gaw/polyfill.c @@ -1,3 +1,20 @@ +/* +RetroRay - integrated standalone vintage modeller/renderer +Copyright (C) 2023 John Tsiombikas + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ #include #include #include @@ -398,3 +415,58 @@ void polyfill_add_tex_wire(struct pvertex *verts, int nverts) #include "polytmpl.h" #undef POLYFILL + +void draw_line(struct pvertex *verts) +{ + int32_t x0, y0, x1, y1; + int i, dx, dy, x_inc, y_inc, error; + uint32_t *fb = pfill_fb.pixels; + uint32_t color = PACK_RGB(verts[0].r, verts[0].g, verts[0].b); + + x0 = verts[0].x >> 8; + y0 = verts[0].y >> 8; + x1 = verts[1].x >> 8; + y1 = verts[1].y >> 8; + + fb += y0 * pfill_fb.width + x0; + + dx = x1 - x0; + dy = y1 - y0; + + if(dx >= 0) { + x_inc = 1; + } else { + x_inc = -1; + dx = -dx; + } + if(dy >= 0) { + y_inc = pfill_fb.width; + } else { + y_inc = -pfill_fb.width; + dy = -dy; + } + + if(dx > dy) { + error = dy * 2 - dx; + for(i=0; i<=dx; i++) { + *fb = color; + if(error >= 0) { + error -= dx * 2; + fb += y_inc; + } + error += dy * 2; + fb += x_inc; + } + } else { + error = dx * 2 - dy; + for(i=0; i<=dy; i++) { + *fb = color; + if(error >= 0) { + error -= dy * 2; + fb += x_inc; + } + error += dx * 2; + fb += y_inc; + } + } +}