void init_render(void) { mclip = m4_m4prod(s->view->C, s->view->V); mdpy = m4_m4prod(s->view->S, s->view->P); z = new_list(); g = NEWSTRUCT(GouraudData); rc_sset(rc = NEWSTRUCT(RContext), s->view, s->lights, s->img); }
Prim *cylin_instance(PrimFuncs *f) { Vector3 ll = {-1,-1,-1}, ur = {1,1,1}; Prim *p = NEWSTRUCT(Prim); Cylin *s = NEWSTRUCT(Cylin); p->f = f; p->b.ll = ll; p->b.ur = ur; p->ti = p->td = m4_ident(); s->bc = v3_make(0,0,0); s->h = 1; s->r = 1; p->d = s; return p; }
Prim *torus_instance(PrimFuncs *f) { Vector3 ll = {-3,-3,-1}, ur = {3,3,1}; Prim *p = NEWSTRUCT(Prim); Torus *t = NEWSTRUCT(Torus); p->f = f; p->b.ll = ll; p->b.ur = ur; p->ti = p->td = m4_ident(); t->c = v3_make(0,0,0); t->r = 1; t->R = 2; p->d = t; return p; }
void init_render(void) { mclip = m4_m4prod(s->view->Vinv, s->view->Cinv); mdpy = m4_m4prod(s->view->Pinv, s->view->Sinv); rc_sset(rc = NEWSTRUCT(RContext), s->view, s->lights, s->img); }
CsgNode *csg_prim(Prim *p) { CsgNode *n = NEWSTRUCT(CsgNode); n->type = CSG_PRIM; n->u.p = p; return n; }
Val obj_parse(int c, Pval *pl) { Val v = {V_NULL, 0}; if (c == T_EXEC) { Pval *p; Object *o = NEWSTRUCT(Object); o->mat = NULL; for (p = pl; p !=NULL; p = p->next) { if (p->name == NULL) { error("(object) syntax error"); } else if (strcmp(p->name, "material") == 0 && p->val.type == V_MATERIAL) { o->mat = p->val.u.v; } else if (strcmp(p->name, "shape") == 0 && p->val.type == V_PRIM) { o->type = V_PRIM; o->u.prim = p->val.u.v; } else if (strcmp(p->name, "shape") == 0 && p->val.type == V_POLYLIST) { o->type = V_POLYLIST; o->u.pols = p->val.u.v; } else if (strcmp(p->name, "shape") == 0 && p->val.type == V_CSG_NODE) { o->type = V_CSG_NODE; o->u.tcsg = p->val.u.v; } else error("(object) syntax error"); } if (o->mat == NULL) SET_MAT_DEFAULT(o); v.type = V_OBJECT; v.u.v = o; } return v; }
Hpoly *hpoly_alloc(int n) { Hpoly *p = NEWSTRUCT(Hpoly); p->n = n; p->v = NEWARRAY(n, Vector4); return p; }
void z_store(Poly *l) { Zdatum *d = NEWSTRUCT(Zdatum); d->zmax = MIN(l->v[0].z, MIN(l->v[1].z, l->v[2].z)); d->l = l; d->o = o; append_item(z, new_item(d)); }
CsgNode *csg_link(int op, CsgNode *lft, CsgNode *rgt) { CsgNode *n = NEWSTRUCT(CsgNode); n->type = CSG_COMP; n->u.c.op = op; n->u.c.lft = lft; n->u.c.rgt = rgt; return n; }
View* initview(void) { setview(NEWSTRUCT(View)); setviewdefaults(); makeviewV(); makeviewC(); makeviewP(); makeviewS(); return getview(); }
Material *mat_default() { Material *m = NEWSTRUCT(Material); m->c = C_WHITE; m->ka = .1; m->kd = .9; m->luminance = matte; m->tinfo = NULL; return m; }
Light *light_ambient(Real amb) { Light *l = NEWSTRUCT(Light); l->type = LIGHT_AMBIENT; l->color = C_WHITE; l->ambient = amb; l->transport = ambientlight; l->tinfo = NULL; return l; }
Widget* widget_new(int type, real x, real y, real s, int (*f)()) { Widget *w = NEWSTRUCT(Widget); w->id = -1; w->type = type; w->xo = x; w->yo = y; w->xs = w->ys = s; w->f = f; w->d = NULL; return w; }
Object *obj_new(int type, void *v) { Object *o = NEWSTRUCT(Object); o->next = NULL; SET_MAT_DEFAULT(o); switch (o->type = type) { case V_CSG_NODE: o->u.tcsg = v; break; case V_PRIM: o->u.prim = v; break; case V_POLYLIST: o->u.pols = v; break; default: error("(newobj) wrong type"); } return o; }
Stack4 *s4_initstack(int size) { int i; Matrix4 *m; Stack4 *s = NEWSTRUCT(Stack4); s->size = size; s->mbot = NEWARRAY(size, Matrix4); s->ibot = NEWARRAY(size, Matrix4); for (m = s->mbot, i = 0; i < s->size; i++) *m++ = m4_ident(); for (m = s->ibot, i = 0; i < s->size; i++) *m++ = m4_ident(); s->mtop = s->mbot; s->itop = s->ibot; return s; }
void vbo_store_mesh_gl(Object *o, iMesh *m) { int nv, ni, i; GLsizei vsiz, nsiz, tsiz, dusiz, dvsiz; GLfloat *verts = NULL; GLfloat *norms = NULL; GLfloat *texc = NULL; GLfloat *du = NULL; GLfloat *dv = NULL; GLuint *inds = NULL; GLenum glerror; unsigned char *dest = NULL; iTri *t; if (sh_vb_(o) == NULL) sh_vb_(o) = NEWSTRUCT(GLvbuf); ResetError_GL(); // set vertices and attributes sh_vb_(o)->nvert = nv = m->n; verts = alloc_set_buffer(nv, m->p); vsiz = nv*3*sizeof(GLfloat); nsiz = tsiz = dusiz = dvsiz = 0; if (m->nv) { nsiz = nv*3*sizeof(GLfloat); norms = alloc_set_buffer(nv, m->nv); } sh_vb_(o)->ntex = 0; if (m->tx || TRUE) { sh_vb_(o)->ntex++; tsiz = nv*3*sizeof(GLfloat); texc = alloc_set_buffer(nv, m->tx); } if (m->du || TRUE) { sh_vb_(o)->ntex++; dusiz = nv*3*sizeof(GLfloat); du = alloc_set_buffer(nv, m->du); } if (m->dv || TRUE) { sh_vb_(o)->ntex++; dvsiz = nv*3*sizeof(GLfloat); dv = alloc_set_buffer(nv, m->dv); } // set triangles for (ni = 0, t = m->t; t != NULL; t = t->next) ni+=3; sh_vb_(o)->nind = ni; inds = NEWTARRAY(ni, GLuint); for (ni = 0, t = m->t; t != NULL; t = t->next, ni+=3) { inds[ni] = t->v[0]; inds[ni+1] = t->v[1]; inds[ni+2] = t->v[2]; } glGenBuffers(1, &(sh_vb_(o)->buffer)); glBindBuffer(GL_ARRAY_BUFFER, sh_vb_(o)->buffer); CheckError_GL("vbo verts", sh_vb_(o)->buffer, 0); glBufferData(GL_ARRAY_BUFFER, vsiz+nsiz+tsiz+dusiz+dvsiz, NULL, GL_STATIC_DRAW); glerror = glGetError(); dest = (unsigned char *) glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); if (glerror == GL_NO_ERROR && dest) { memcpy(dest, (void *)verts, vsiz); memcpy(dest+vsiz, (void *)norms, nsiz); memcpy(dest+vsiz+nsiz, (void *)texc, tsiz); memcpy(dest+vsiz+nsiz+tsiz, (void *)du, dusiz); memcpy(dest+vsiz+nsiz+tsiz+dusiz, (void *)dv, dvsiz); glUnmapBuffer(GL_ARRAY_BUFFER); } else error("vbo data alloc"); glBindBuffer(GL_ARRAY_BUFFER, 0); glGenBuffers(1, &(sh_vb_(o)->indices)); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, sh_vb_(o)->indices); CheckError_GL("vbo inds", 0, 0); glBufferData(GL_ELEMENT_ARRAY_BUFFER, ni*sizeof(GLuint), NULL, GL_STATIC_DRAW); glerror = glGetError(); dest = (unsigned char *) glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); if (glerror == GL_NO_ERROR && dest) { memcpy(dest, (void *)inds, ni*sizeof(GLuint)); glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); } else error("vbo ind alloc"); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); efree(verts); efree(norms); efree(inds); efree(texc); efree(du); efree(dv); }