newpoly

view src/poly.c @ 0:224206bc554a

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 15 Dec 2017 09:24:39 +0200
parents
children
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "poly.h"
6 static uint32_t *fb_pixels;
7 static int fb_width, fb_height;
8 static unsigned int *scanoffs;
9 static int scanoffs_size;
11 int polyfill_framebuffer(void *fb, int width, int height)
12 {
13 int i;
14 unsigned int offs = 0;
16 if(height > scanoffs_size) {
17 free(scanoffs);
18 scanoffs_size = height;
19 if(!(scanoffs = malloc(scanoffs_size * sizeof *scanoffs))) {
20 perror("failed to allocate scanline offset table");
21 return -1;
22 }
23 }
25 for(i=0; i<height; i++) {
26 scanoffs[i] = offs;
27 offs += width;
28 }
30 fb_pixels = fb;
31 fb_width = width;
32 fb_height = height;
34 return 0;
35 }
37 void polyfill_flat(struct poly_vertex *varr, int vcount)
38 {
39 int i;
41 for(i=0; i<vcount; i++) {
42 int x = varr[i].x >> 16;
43 int y = varr[i].y >> 16;
45 fb_pixels[scanoffs[y] + x] = 0xff0000;
46 }
47 }