diff options
author | rodri <rgl@antares-labs.eu> | 2024-09-11 20:58:17 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-09-11 20:58:17 +0000 |
commit | bbadf2f31be926a9755548d7a2e9e96444224ec9 (patch) | |
tree | a7aba5cdc6b609b7a163fbea66d1ec9ed4e2fa44 | |
parent | e862d6f0224de67b0a329e16b91841206feb844a (diff) | |
download | 3dee-bbadf2f31be926a9755548d7a2e9e96444224ec9.tar.gz 3dee-bbadf2f31be926a9755548d7a2e9e96444224ec9.tar.bz2 3dee-bbadf2f31be926a9755548d7a2e9e96444224ec9.zip |
adapt to new changes in libgraphics.
-rw-r--r-- | med.c | 7 | ||||
-rw-r--r-- | solar.c | 29 | ||||
-rw-r--r-- | vis.c | 34 |
3 files changed, 31 insertions, 39 deletions
@@ -130,10 +130,11 @@ materializefrustum(void) p[2] = Pt3(Dx(cam->view->r),Dy(cam->view->r),1,1); p[3] = Pt3(0,Dy(cam->view->r),1,1); memset(&l, 0, sizeof l); + l.type = PLine; + l.v[0].c = l.v[1].c = Pt3(1,1,1,1); for(i = 0; i < nelem(p); i++){ /* front frame */ - l.type = PLine; l.v[0].p = world2model(subject, viewport2world(cam, p[i])); l.v[1].p = world2model(subject, viewport2world(cam, p[(i+1)%nelem(p)])); qlock(&scenelk); @@ -496,10 +497,13 @@ redraw(void) void renderproc(void *) { + static Image *bg; uvlong t0, Δt; threadsetname("renderproc"); + bg = eallocimage(display, UR, XRGB32, 1, 0x888888FF); + t0 = nsec(); for(;;){ qlock(&scenelk); @@ -509,6 +513,7 @@ renderproc(void *) Δt = nsec() - t0; if(Δt > HZ2MS(60)*1000000ULL){ lockdisplay(display); + draw(screenb, screenb->r, bg, nil, ZP); cam->view->draw(cam->view, screenb, nil); compass.cam->view->draw(compass.cam->view, screenb, nil); unlockdisplay(display); @@ -168,28 +168,6 @@ static int showskybox; static int doprof; static int showhud; -static Point3 -minpt3(Point3 a, Point3 b) -{ - return (Point3){ - min(a.x, b.x), - min(a.y, b.y), - min(a.z, b.z), - min(a.w, b.w) - }; -} - -static Point3 -maxpt3(Point3 a, Point3 b) -{ - return (Point3){ - max(a.x, b.x), - max(a.y, b.y), - max(a.z, b.z), - max(a.w, b.w) - }; -} - static void refreshinfobox(Infobox *info) { @@ -202,7 +180,7 @@ refreshinfobox(Infobox *info) assert(info != nil && info->image != nil && info->items != nil); if(tbg == nil){ - tbg = eallocimage(display, UR, RGBA32, 1, 0x4444887F); + tbg = eallocimage(display, UR, RGBA32, 1, 0x2222447F); tfg = display->white; bg[0] = eallocimage(display, UR, RGBA32, 1, 0xEEEEEEEE); bg[1] = eallocimage(display, UR, RGBA32, 1, 0xAAAAAAAA); @@ -557,16 +535,20 @@ redraw(void) void renderproc(void *) { + static Image *bg; uvlong t0, Δt; threadsetname("renderproc"); + bg = eallocimage(display, UR, XRGB32, 1, DBlack); + t0 = nsec(); for(;;){ shootcamera(camera, &shader); Δt = nsec() - t0; if(Δt > HZ2MS(60)*1000000ULL){ lockdisplay(display); + draw(screenb, screenb->r, bg, nil, ZP); camera->view->draw(camera->view, screenb, nil); unlockdisplay(display); nbsend(drawc, nil); @@ -951,6 +933,7 @@ threadmain(int argc, char *argv[]) else cmds[i].r = rectaddpt(cmds[i].r, Pt(cmds[i-1].r.max.x+Cmdmargin,cmds[i-1].r.min.y)); } + screenb = eallocimage(display, viewr, XRGB32, 0, DNofill); camera = Cam(screenb->r, rctl, cameracfg.ptype, cameracfg.fov, cameracfg.clipn, cameracfg.clipf); placecamera(camera, scene, cameracfg.p, cameracfg.lookat, cameracfg.up); @@ -52,6 +52,7 @@ char *skyboxpaths[] = { }; char stats[Se][256]; Image *screenb; +Image *clr; Mousectl *mctl; Keyboardctl *kctl; Channel *drawc; @@ -166,6 +167,7 @@ gouraudshader(Shaderparams *sp) else tc = Pt3(1,1,1,1); + sp->v->n.w = 1; sp->toraster(sp, "normals", &sp->v->n); return modulapt3(sp->v->c, tc); @@ -266,6 +268,7 @@ phongshader(Shaderparams *sp) specular = mulpt3(lightc, spec*Ks); specular = modulapt3(specular, m.specular); + sp->v->n.w = 1; sp->toraster(sp, "normals", &sp->v->n); c = addpt3(ambient, addpt3(diffuse, specular)); @@ -340,6 +343,7 @@ blinnshader(Shaderparams *sp) specular = mulpt3(lightc, spec*Ks); specular = modulapt3(specular, m.specular); + sp->v->n.w = 1; sp->toraster(sp, "normals", &sp->v->n); c = addpt3(ambient, addpt3(diffuse, specular)); @@ -377,6 +381,7 @@ toonshader(Shaderparams *sp) intens > 0.30? 0.45: intens > 0.15? 0.30: 0.15; + sp->v->n.w = 1; sp->toraster(sp, "normals", &sp->v->n); return Pt3(intens, 0.6*intens, 0, 1); @@ -402,6 +407,7 @@ identshader(Shaderparams *sp) else tc = Pt3(1,1,1,1); + sp->v->n.w = 1; sp->toraster(sp, "normals", &sp->v->n); return modulapt3(sp->v->c, tc); @@ -605,6 +611,7 @@ renderproc(void *) Δt = nsec() - t0; if(Δt > HZ2MS(60)*1000000ULL){ lockdisplay(display); + draw(screenb, screenb->r, clr, nil, ZP); maincam->view->draw(maincam->view, screenb, shownormals? "normals": nil); unlockdisplay(display); nbsend(drawc, nil); @@ -630,18 +637,6 @@ drawproc(void *) } } -static Color -ul2col(ulong l) -{ - Color c; - - c.b = (l & 0xff)/255.0; - c.g = (l>>8 & 0xff)/255.0; - c.r = (l>>16 & 0xff)/255.0; - c.a = (l>>24 & 0xff)/255.0; - return c; -} - void lmb(void) { @@ -743,6 +738,7 @@ mmb(void) static Menu menu = { .item = items }; char buf[256], *f[3]; int nf; + ulong clrcol; lockdisplay(display); switch(menuhit(2, mctl, &menu, _screen)){ @@ -767,13 +763,18 @@ mmb(void) shownormals ^= 1; break; case SETCLRCOL: - snprint(buf, sizeof buf, "0x%08lux", maincam->clearcolor); + if(unloadimage(clr, UR, (uchar*)&clrcol, 4) != 4) + break; + clrcol = clrcol<<8 | 0xFF; /* xrgb2rgba */ + snprint(buf, sizeof buf, "0x%08lux", clrcol); if(enter("clear color", buf, sizeof buf, mctl, kctl, nil) <= 0) break; nf = tokenize(buf, f, 1); if(nf != 1) break; - maincam->clearcolor = strtoul(buf, nil, 0); + clrcol = strtoul(buf, nil, 0); + freeimage(clr); + clr = eallocimage(display, UR, XRGB32, 1, clrcol); break; case CULLFRONT: maincam->cullmode = CullFront; @@ -1108,7 +1109,10 @@ threadmain(int argc, char *argv[]) rctl->doprof = doprof; - screenb = eallocimage(display, rectsubpt(screen->r, screen->r.min), XRGB32, 0, 0x888888FF); + clr = eallocimage(display, UR, XRGB32, 1, 0x888888FF); + screenb = eallocimage(display, rectsubpt(screen->r, screen->r.min), XRGB32, 0, DNofill); +// if(nameimage(screenb, "screenb", 1) == 0) +// sysfatal("nameimage: %r"); fprint(2, "screen %R\n", screenb->r); for(i = 0; i < nelem(cams); i++){ if(fbw == 0 || fbh == 0) |