2 RetroRay - integrated standalone vintage modeller/renderer
3 Copyright (C) 2023 John Tsiombikas <nuclear@mutantstargoat.com>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>.
21 struct img_pixmap renderbuf;
22 struct img_pixmap dbgimg;
24 static int rx, ry, rwidth, rheight;
26 static int xstep, ystep;
33 img_load(&dbgimg, "data/foo.jpg");
34 img_convert(&dbgimg, IMG_FMT_RGBA32);
36 rx = ry = rwidth = rheight = roffs = 0;
40 void rend_destroy(void)
42 img_destroy(&renderbuf);
45 void rend_size(int xsz, int ysz)
47 if(xsz != renderbuf.width || ysz != renderbuf.height) {
48 img_set_pixels(&renderbuf, xsz, ysz, IMG_FMT_RGBA32, 0);
52 void rend_begin(int x, int y, int w, int h)
57 if(w == 0 || h == 0) {
59 rwidth = renderbuf.width;
60 rheight = renderbuf.height;
67 roffs = ry * renderbuf.width + rx;
72 ptr = (uint32_t*)renderbuf.pixels + roffs;
73 for(i=0; i<rheight; i++) {
74 memset(ptr, 0, rwidth * sizeof *ptr);
75 ptr += renderbuf.width;
79 static void fillrect(uint32_t *fb, int x, int y, int w, int h, uint32_t c)
83 fb += y * renderbuf.width + x;
88 fb += renderbuf.width;
92 int render(uint32_t *fb)
97 src = (uint32_t*)dbgimg.pixels + roffs;
98 dest = (uint32_t*)renderbuf.pixels + roffs;
101 for(i=0; i<rheight; i+=ystep) {
102 for(j=0; j<rwidth; j+=xstep) {
103 offs = i * renderbuf.width + j;
104 dest[offs] = src[offs];
106 fb[offs] = src[offs];
107 fillrect(fb, j, i, xstep, ystep, src[offs]);
115 if((xstep | ystep) >= 1) {