/* new window size or exposure */ static int reshape(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) { Togl *togl; struct isst_s *isst; if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "pathName"); return TCL_ERROR; } if (Togl_GetToglFromObj(interp, objv[1], &togl) != TCL_OK) { return TCL_ERROR; } isst = Togl_GetClientData(togl); isst->w = Togl_Width(togl); isst->h = Togl_Height(togl); resize_isst(isst); return TCL_OK; }
static int isst_load_g(ClientData UNUSED(clientData), Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) { struct isst_s *isst; char **argv; int argc; double az, el; struct bu_vls tclstr = BU_VLS_INIT_ZERO; vect_t vec; Togl *togl; if (objc < 4) { Tcl_WrongNumArgs(interp, 1, objv, "load_g pathname object"); return TCL_ERROR; } if (Togl_GetToglFromObj(interp, objv[1], &togl) != TCL_OK) { return TCL_ERROR; } isst = (struct isst_s *) Togl_GetClientData(togl); argv = (char **)malloc(sizeof(char *) * (strlen(Tcl_GetString(objv[3])) + 1)); /* allocate way too much. */ argc = bu_argv_from_string(argv, strlen(Tcl_GetString(objv[3])), Tcl_GetString(objv[3])); load_g(isst->tie, Tcl_GetString(objv[2]), argc, (const char **)argv, &(isst->meshes)); free(argv); VSETALL(isst->camera.pos, isst->tie->radius); VMOVE(isst->camera.focus, isst->tie->mid); VMOVE(isst->camera_pos_init, isst->camera.pos); VMOVE(isst->camera_focus_init, isst->camera.focus); /* Set the initial az and el values in Tcl/Tk */ VSUB2(vec, isst->camera.pos, isst->camera.focus); VUNITIZE(vec); AZEL_FROM_V3DIR(az, el, vec); az = az * -DEG2RAD; el = el * -DEG2RAD; bu_vls_sprintf(&tclstr, "%f", az); Tcl_SetVar(interp, "az", bu_vls_addr(&tclstr), 0); bu_vls_sprintf(&tclstr, "%f", el); Tcl_SetVar(interp, "el", bu_vls_addr(&tclstr), 0); bu_vls_free(&tclstr); render_phong_init(&isst->camera.render, NULL); isst->ogl = 1; isst->w = Togl_Width(togl); isst->h = Togl_Height(togl); resize_isst(isst); isst->t1 = bu_gettime(); isst->t2 = bu_gettime(); return TCL_OK; }
static int init(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) { WHIRLYGIZMO *Wg; static GLfloat red[4] = { 0.8f, 0.1f, 0, 1 }; static GLfloat green[4] = { 0, 0.8f, 0.2f, 1 }; static GLfloat blue[4] = { 0.2f, 0.2f, 1, 1 }; static GLfloat pos[4] = { 5, 5, 10, 0 }; Togl *togl; if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "pathName"); return TCL_ERROR; } if (Togl_GetToglFromObj(interp, objv[1], &togl) != TCL_OK) { return TCL_ERROR; } glLightfv(GL_LIGHT0, GL_POSITION, pos); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); /* make the gears */ Wg = (WHIRLYGIZMO *) malloc(sizeof (WHIRLYGIZMO)); if (!Wg) { Tcl_SetResult(Togl_Interp(togl), "\"Cannot allocate client data for widget\"", TCL_STATIC); } Wg->Gear1 = glGenLists(1); glNewList(Wg->Gear1, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red); gear(1, 4, 1, 20, 0.7f); glEndList(); Wg->Gear2 = glGenLists(1); glNewList(Wg->Gear2, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green); gear(0.5f, 2, 2, 10, 0.7f); glEndList(); Wg->Gear3 = glGenLists(1); glNewList(Wg->Gear3, GL_COMPILE); glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue); gear(1.3f, 2, 0.5f, 10, 0.7f); glEndList(); glEnable(GL_NORMALIZE); Wg->Height = Togl_Height(togl); Wg->Width = Togl_Width(togl); Wg->Angle = 0; Wg->Rotx = 0; Wg->Roty = 0; Wg->Rotz = 0; Togl_SetClientData(togl, (ClientData) Wg); return TCL_OK; }
/* * Togl widget reshape callback. This is called by Tcl/Tk when the widget * has been resized. Typically, we call glViewport and perhaps setup the * projection matrix. */ void reshape_cb( struct Togl *togl ) { int width = Togl_Width( togl ); int height = Togl_Height( togl ); float aspect = (float) width / (float) height; glViewport( 0, 0, width, height ); /* Set up projection transform */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho( -aspect, aspect, -1.0, 1.0, -1.0, 1.0 ); /* Change back to model view transform for rendering */ glMatrixMode(GL_MODELVIEW); }
/* new window size or exposure */ static int reshape(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) { int width, height; Togl *togl; if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "pathName"); return TCL_ERROR; } if (Togl_GetToglFromObj(interp, objv[1], &togl) != TCL_OK) { return TCL_ERROR; } width = Togl_Width(togl); height = Togl_Height(togl); glViewport(0, 0, (GLint) width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (width > height) { GLfloat w = (GLfloat) width / (GLfloat) height; glFrustum(-w, w, -1, 1, 5, 60); } else { GLfloat h = (GLfloat) height / (GLfloat) width; glFrustum(-1, 1, -h, h, 5, 60); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, -40); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); return TCL_OK; }
/* * Togl widget reshape callback. This is called by Tcl/Tk when the widget * has been resized. Typically, we call glViewport and perhaps setup the * projection matrix. */ void reshape_cb( struct Togl *togl ) { int width = Togl_Width( togl ); int height = Togl_Height( togl ); float aspect = (float) width / (float) height; /* Set up viewing for normal plane's context */ glViewport( 0, 0, width, height ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho( -aspect, aspect, -1.0, 1.0, -1.0, 1.0 ); glMatrixMode(GL_MODELVIEW); /* Set up viewing for overlay plane's context */ if (Togl_ExistsOverlay(togl)) { Togl_UseLayer(togl, TOGL_OVERLAY); glViewport( 0, 0, width, height ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); glMatrixMode(GL_MODELVIEW); Togl_UseLayer(togl, TOGL_NORMAL); } }