src/dos/mouse.obj src/dos/vbe.obj src/dos/vga.obj src/dos/watdpmi.obj
appobj = src/app.obj src/cmesh.obj src/darray.obj src/font.obj src/logger.obj &
src/meshgen.obj src/meshload.obj src/options.obj src/rbtree.obj src/rt.obj &
- src/rtk.obj src/scene.obj src/scr_mod.obj src/scr_rend.obj src/util.obj &
- src/util_s.obj src/cpuid.obj src/cpuid_s.obj
+ src/rend.obj src/rtk.obj src/scene.obj src/scr_mod.obj src/scr_rend.obj &
+ src/util.obj src/util_s.obj src/cpuid.obj src/cpuid_s.obj
gawobj = src/gaw/gaw_sw.obj src/gaw/gawswtnl.obj src/gaw/polyclip.obj src/gaw/polyfill.obj
incpath = -Isrc -Isrc/dos -Ilibs -Ilibs/imago/src -Ilibs/treestor/include -Ilibs/drawtext
src\dos\mouse.obj src\dos\vbe.obj src\dos\vga.obj src\dos\watdpmi.obj
appobj = src\app.obj src\cmesh.obj src\darray.obj src\font.obj src\logger.obj &
src\meshgen.obj src\meshload.obj src\options.obj src\rbtree.obj src\rt.obj &
- src\rtk.obj src\scene.obj src\scr_mod.obj src\scr_rend.obj src\util.obj &
- src\util_s.obj src\cpuid.obj src\cpuid_s.obj
+ src\rend.obj src\rtk.obj src\scene.obj src\scr_mod.obj src\scr_rend.obj &
+ src\util.obj src\util_s.obj src\cpuid.obj src\cpuid_s.obj
gawobj = src\gaw\gaw_sw.obj src\gaw\gawswtnl.obj src\gaw\polyclip.obj src\gaw\polyfill.obj
incpath = -Isrc -Isrc\dos -Ilibs -Ilibs\imago\src -Ilibs\treestor\include -Ilibs\drawtext
#include <time.h>
#include "gaw/gaw.h"
#include "app.h"
+#include "rend.h"
#include "options.h"
#include "font.h"
#include "util.h"
static void gui_blit(int x, int y, rtk_icon *icon);
static void gui_drawtext(int x, int y, const char *str);
static void gui_textrect(const char *str, rtk_rect *rect);
-static void txdraw(struct dtx_vertex *v, int vcount, struct dtx_pixmap *pixmap, void *cls);
int mouse_x, mouse_y, mouse_state[3];
unsigned int modkeys;
#ifdef GFX_SW
gaw_sw_init();
#endif
+ rend_init();
load_options("retroray.cfg");
app_resize(opt.xres, opt.yres);
rect->width = 20;
rect->height = 10;/* TODO */
}
-
-static void txdraw(struct dtx_vertex *v, int vcount, struct dtx_pixmap *pixmap, void *cls)
-{
-}
#include "sizeint.h"
#include "logger.h"
#include "scene.h"
-#include "font.h"
enum {
KEY_BACKSP = 8,
struct font;
extern struct font *uifont;
-extern uint32_t *framebuf;
+extern uint32_t *framebuf, *rendbuf;
extern struct scene *scn;
--- /dev/null
+/*
+RetroRay - integrated standalone vintage modeller/renderer
+Copyright (C) 2023 John Tsiombikas <nuclear@mutantstargoat.com>
+
+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 <https://www.gnu.org/licenses/>.
+*/
+#include "rend.h"
+#include "rt.h"
+
+struct img_pixmap renderbuf;
+struct img_pixmap dbgimg;
+
+static int rx, ry, rwidth, rheight;
+static int roffs;
+static int xstep, ystep;
+
+int rend_init(void)
+{
+ img_init(&renderbuf);
+
+ img_init(&dbgimg);
+ img_load(&dbgimg, "data/foo.jpg");
+ img_convert(&dbgimg, IMG_FMT_RGBA32);
+
+ rx = ry = rwidth = rheight = roffs = 0;
+ return 0;
+}
+
+void rend_destroy(void)
+{
+ img_destroy(&renderbuf);
+}
+
+void rend_size(int xsz, int ysz)
+{
+ if(xsz != renderbuf.width || ysz != renderbuf.height) {
+ img_set_pixels(&renderbuf, xsz, ysz, IMG_FMT_RGBA32, 0);
+ }
+}
+
+void rend_begin(int x, int y, int w, int h)
+{
+ int i;
+ uint32_t *ptr;
+
+ if(w == 0 || h == 0) {
+ rx = ry = 0;
+ rwidth = renderbuf.width;
+ rheight = renderbuf.height;
+ } else {
+ rx = x;
+ ry = y;
+ rwidth = w;
+ rheight = h;
+ }
+ roffs = ry * renderbuf.width + rx;
+
+ xstep = rwidth;
+ ystep = rheight;
+
+ ptr = (uint32_t*)renderbuf.pixels + roffs;
+ for(i=0; i<rheight; i++) {
+ memset(ptr, 0, rwidth * sizeof *ptr);
+ ptr += renderbuf.width;
+ }
+}
+
+static void fillrect(uint32_t *fb, int x, int y, int w, int h, uint32_t c)
+{
+ int i, j;
+
+ fb += y * renderbuf.width + x;
+ for(i=0; i<h; i++) {
+ for(j=0; j<w; j++) {
+ fb[j] = c;
+ }
+ fb += renderbuf.width;
+ }
+}
+
+int render(uint32_t *fb)
+{
+ int i, j, offs;
+ uint32_t *src, *dest;
+
+ src = (uint32_t*)dbgimg.pixels + roffs;
+ dest = (uint32_t*)renderbuf.pixels + roffs;
+ if(fb) fb += roffs;
+
+ for(i=0; i<rheight; i+=ystep) {
+ for(j=0; j<rwidth; j+=xstep) {
+ offs = i * renderbuf.width + j;
+ dest[offs] = src[offs];
+ if(fb) {
+ fb[offs] = src[offs];
+ fillrect(fb, j, i, xstep, ystep, src[offs]);
+ }
+ }
+ }
+
+ xstep >>= 1;
+ ystep >>= 1;
+
+ if((xstep | ystep) >= 1) {
+ return 1;
+ }
+ return 0;
+}
--- /dev/null
+/*
+RetroRay - integrated standalone vintage modeller/renderer
+Copyright (C) 2023 John Tsiombikas <nuclear@mutantstargoat.com>
+
+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 <https://www.gnu.org/licenses/>.
+*/
+#ifndef REND_H_
+#define REND_H_
+
+#include "sizeint.h"
+#include "imago2.h"
+
+extern struct img_pixmap renderbuf;
+
+int rend_init(void);
+void rend_size(int xsz, int ysz);
+void rend_begin(int x, int y, int w, int h);
+int render(uint32_t *fb);
+
+#endif /* REND_H_ */
#include "rt.h"
#include "cmesh.h"
#include "meshgen.h"
+#include "font.h"
+#include "rend.h"
enum {
TBN_NEW, TBN_OPEN, TBN_SAVE, TBN_SEP1,
TBN_SEL, TBN_MOVE, TBN_ROT, TBN_SCALE, TBN_SEP2,
TBN_ADD, TBN_RM, TBN_SEP3,
TBN_UNION, TBN_ISECT, TBN_DIFF, TBN_SEP4,
- TBN_MTL, TBN_REND, TBN_VIEWREND, TBN_SEP5, TBN_CFG,
+ TBN_MTL, TBN_REND, TBN_REND_AREA, TBN_VIEWREND, TBN_SEP5, TBN_CFG,
NUM_TOOL_BUTTONS
};
"sel", "move", "rot", "scale", 0,
"add", "remove", 0,
"union", "isect", "diff", 0,
- "mtl", "rend", "viewrend", 0, "cfg"
+ "mtl", "rend", "rend-area", "viewrend", 0, "cfg"
};
static int tbn_icon_pos[][2] = {
{0,0}, {16,0}, {32,0}, {-1,-1},
{48,0}, {64,0}, {80,0}, {96,0}, {-1,-1},
{112,0}, {112,16}, {-1,-1},
{0,16}, {16,16}, {32,16}, {-1,-1},
- {48,16}, {64,16}, {80,16}, {-1,-1}, {96,16}
+ {48,16}, {64,16}, {64, 32}, {80,16}, {-1,-1}, {96,16}
};
static int tbn_istool[] = {
0, 0, 0, 0,
1, 1, 1, 1, 0,
0, 0, 0,
1, 1, 1, 0,
- 0, 0, 0, 0, 0
+ 0, 0, 1, 0, 0, 0
};
static rtk_icon *tbn_icons[NUM_TOOL_BUTTONS];
static rtk_widget *tbn_buttons[NUM_TOOL_BUTTONS];
enum {
TOOL_SEL, TOOL_MOVE, TOOL_ROT, TOOL_SCALE,
- TOOL_UNION, TOOL_ISECT, TOOL_DIFF,
+ TOOL_UNION, TOOL_ISECT, TOOL_DIFF, TOOL_REND_AREA,
NUM_TOOLS
};
static rtk_widget *tools[NUM_TOOLS];
static int viewport[4];
static cgm_ray pickray;
-static int cur_tool;
+static int cur_tool, prev_tool = -1;
static int selobj = -1;
static rtk_rect rband;
static int rband_valid;
+static int rendering;
+
static int mdl_init(void)
{
}
}
+ if(rendering) {
+ if(render(framebuf)) {
+ app_redisplay();
+ } else {
+ rendering = 0;
+ }
+ }
+
use_font(uifont);
- dtx_position(560, 475);
- dtx_color(1, 1, 0, 1);
- dtx_printf("frame: %ld", frameno++);
+ dtx_position(550, 475);
+ dtx_color(0.3, 0.3, 0.1, 1);
+ dtx_printf("update: %ld", frameno++);
if(rband_valid) {
draw_rband();
}
if(press) {
+ rband_valid = 0;
rband.x = x;
rband.y = y;
vpdrag |= (1 << bn);
if(rband_valid) {
rband_valid = 0;
+ if(cur_tool == TOOL_REND_AREA) {
+ if(prev_tool >= 0) {
+ act_settool(prev_tool);
+ }
+ rendering = 1;
+ rend_size(win_width, win_height);
+ rend_begin(rband.x, rband.y, rband.width, rband.height);
+ }
+
} else if(bn == 0 && x == rband.x && y == rband.y) {
primray(&pickray, x, y);
if(scn_intersect(scn, &pickray, &hit)) {
if(mouse_state[0]) {
switch(cur_tool) {
case TOOL_SEL:
+ case TOOL_REND_AREA:
if(rband.x != x || rband.y != y) {
rband.width = x - rband.x;
rband.height = y - rband.y;
static void tbn_callback(rtk_widget *w, void *cls)
{
int id = (intptr_t)cls;
- int idx;
switch(id) {
case TBN_SEL:
case TBN_MOVE:
case TBN_ROT:
case TBN_SCALE:
- idx = id - TBN_SEL;
- if(0) {
+ act_settool(id - TBN_SEL);
+ break;
case TBN_UNION:
case TBN_ISECT:
case TBN_DIFF:
- idx = id - TBN_UNION + TOOL_UNION;
- }
- act_settool(idx);
+ act_settool(id - TBN_UNION + TOOL_UNION);
+ break;
+ case TBN_REND_AREA:
+ act_settool(TOOL_REND_AREA);
break;
case TBN_ADD:
static void act_settool(int tidx)
{
int i;
+ prev_tool = cur_tool;
cur_tool = tidx;
for(i=0; i<NUM_TOOLS; i++) {
if(i == cur_tool) {
font2glyphmap -size $3 -padding 5 -range $4 -o $2 $1
}
-genglyphmap data/src/sans.ttf data/uifont12.gmp 12 32-128
genglyphmap data/src/sans.ttf data/uifont14.gmp 14 32-128
exit 0