void DrawStuff (void) { #ifdef IBM_GL_32 scale (1.8, 1.8, 1.8); lmcolor (material_mode); (void) extrusion (NUM_TEXAS_PTS-1, texas_xsection, texas_normal, NULL, NUMPOINTS, tspine, tcolors); (void) extrusion (NUM_TEXAS_PTS-1, texas_xsection, texas_normal, NULL, HNUM, brand_points, brand_colors); lmcolor (LMC_COLOR); #endif #define OPENGL_10 #ifdef OPENGL_10 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* set up some matrices so that the object spins with the mouse */ glPushMatrix (); glTranslatef (0.0, 0.0, -80.0); glRotatef (lastx, 0.0, 1.0, 0.0); glRotatef (lasty, 1.0, 0.0, 0.0); /* draw the brand and the handle */ gleExtrusion (NUM_TEXAS_PTS-1, texas_xsection, texas_normal, NULL, NUMPOINTS, tspine, tcolors); gleExtrusion (NUM_TEXAS_PTS-1, texas_xsection, texas_normal, NULL, HNUM, brand_points, brand_colors); glPopMatrix (); glutSwapBuffers (); }
static void _dxf_DRAW_ZOOMBOX (tdmInteractor I, void *udata, float rot[4][4], int draw) { DEFDATA(I, tdmZoomData) ; ENTRY(("_dxf_DRAW_ZOOMBOX (0x%x, 0x%x, 0x%x, %d)",I, udata, rot, draw)); if (draw) { if (_dxf_isFlagsSet(_dxf_SERVICES_FLAGS(), SF_INVALIDATE_BACKSTORE)) _dxf_captureZoomBox(I, udata, rot); /* draw the box */ lmcolor(LMC_COLOR) ; cpack(0xffffffff) ; linewidth(1) ; recti(PDATA(x1), PDATA(y1), PDATA(x2), PDATA(y2)) ; } else _dxf_restoreZoomBox(I, udata, rot); EXIT(("")); }
/* * Render the volume described by the given volume struct. * Return: 1 = ok * 0 = bad volume struct. */ static int render_volume( Context ctx, struct volume *v, unsigned int ctable[] ) { register int rows, cols, slices, i, j, s; register int rows1, cols1; register uint_1 *cp0, *cp1; register float *vp0, *vp1; int fastdraw; int stride = 1; if (!v || !v->slices) return 0; #if defined (HAVE_SGI_GL) || defined (DENALI) lmcolor( LMC_COLOR ); /* no shading */ blendfunction( BF_SA, BF_MSA ); /* enable alpha blending */ #endif #ifdef HAVE_OPENGL glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glEnable( GL_BLEND ); check_gl_error( "render_volume (glBlendFunc)" ); #endif /* put rows, cols, slices values into registers */ rows = v->rows-1; /* number of quad strips = number of data rows - 1 */ cols = v->cols; slices = v->slices; /* setup color and vertex pointers */ cp0 = v->index; cp1 = cp0 + cols; vp0 = v->vertex; vp1 = vp0 + cols * 3; /* 3 floats per vertex */ /* MJK 12.15.98 */ #ifdef HAVE_PEX rows++; j = rows * cols; for (s = 0; s < slices; s++) { draw_volume_quadmesh (rows, cols, vp0, cp0, ctable); vp0 += j * 3; cp0 += j; } return 1; #endif vis5d_check_fastdraw(ctx->dpy_ctx->dpy_context_index, &fastdraw); if (fastdraw) { stride = ctx->dpy_ctx->VStride; } /* sanity check */ if(stride<=0) stride = 1; /* ** adjust rows and cols based on stride. N.B. appears to be one more ** row than we actually use */ rows1 = (rows + 1 - 1) / stride; cols1 = ((cols - 1) / stride) + 1; /* loop over slices */ for (s=0;s<slices;s+=stride) { cp0 = v->index + (s * rows * cols) + (s * cols); /* skip a row after each slice */ vp0 = v->vertex + (s * rows * cols * 3) + (s * cols * 3); /* skip a row after each slice */ cp1 = cp0 + (cols * stride); vp1 = vp0 + (cols * stride * 3); /* 3 floats per vertex */ /* draw 'rows' quadrilateral strips */ for (i=0;i<rows1;i++) { #if defined(SGI_GL) || defined(DENALI) bgnqstrip(); for (j=0;j<cols1;j++) { cpack( ctable[cp0[i*stride*cols+j*stride]] ); v3f( &vp0[i*stride*cols+j*stride] ); cpack( ctable[cp1[i*stride*cols+j*stride]] ); v3f( &vp1[i*stride*cols+j*stride] ); } endqstrip(); #endif #ifdef HAVE_OPENGL glBegin( GL_QUAD_STRIP ); for (j=0;j<cols1;j++) { glColor4ubv( (GLubyte *) &ctable[cp0[i*stride*cols+j*stride]] ); glVertex3fv( &vp0[(i*stride*cols+j*stride)*3] ); glColor4ubv( (GLubyte *) &ctable[cp1[i*stride*cols+j*stride]] ); glVertex3fv( &vp1[(i*stride*cols+j*stride)*3] ); } glEnd(); #endif } } #if defined(HAVE_SGI_GL) || defined(DENALI) blendfunction( BF_ONE, BF_ZERO ); /* disable alpha blending */ #endif #ifdef HAVE_OPENGL glDisable( GL_BLEND ); check_gl_error( "render_volume (glDisable)" ); #endif return 1; }
static void _dxf_DRAW_GNOMON (tdmInteractor I, void *udata, float rot[4][4], int draw) { /* * draw == 1 to draw gnomon, draw == 0 to undraw. This is done with * two separate calls in order to support explicit erasure of edges for * some implementations. A draw is always preceded by an undraw and * the pair of invocations is atomic. * * Computations are done in normalized screen coordinates in order to * render arrow heads correctly. */ DEFDATA(I,tdmRotateData) ; DEFPORT(I_PORT_HANDLE) ; int dummy = 0 ; float origin[2] ; float xaxis[2], yaxis[2], zaxis[2] ; float xlabel[2], ylabel[2], zlabel[2] ; ENTRY(("_dxf_DRAW_GNOMON (0x%x, 0x%x, 0x%x, %d)",I, udata, rot, draw)); if (PDATA(font) == -1) { /* font width for axes labels in normalized coordinates */ font(0) ; PDATA(font) = 0 ; PDATA(swidth) = (float)strwidth("Z")/(float)GNOMONRADIUS ; /* 1 pixel in normalized coordinates */ PDATA(nudge) = 1.0/(float)GNOMONRADIUS ; } else font(PDATA(font)) ; if (draw) { lmcolor(LMC_COLOR) ; cpack(0xffffffff) ; linewidth(1) ; } else { if (PDATA(redrawmode) != tdmViewEchoMode) { /* * In tdmViewEchoMode (DX's Execute On Change), we are drawing * the gnomon echo on top of a background image that is redrawn * with every frame of a direct interaction. * * If we're not in that mode, the background image is static * while the gnomon echo rotates in front of it, so erasing the * gnomon means we have to repair damage to the background. We * do this by blitting a portion of the static image to the * back buffer, drawing the gnomon over that, then blitting the * combined results back to the front buffer. */ /* force graphics output into back buffer */ frontbuffer(FALSE) ; backbuffer(TRUE) ; /* erase gnomon background */ lrectwrite (PDATA(illx), PDATA(illy), PDATA(iurx), PDATA(iury), PDATA(background)) ; } #ifndef NOSHADOW /* draw wide black lines to ensure visibility against background */ lmcolor(LMC_COLOR) ; cpack(0x0) ; linewidth(2) ; #else EXIT(("No shadow")); return ; #endif } origin[0] = 0 ; origin[1] = 0 ; xaxis[0] = 0.7 * rot[0][0] ; xaxis[1] = 0.7 * rot[0][1] ; yaxis[0] = 0.7 * rot[1][0] ; yaxis[1] = 0.7 * rot[1][1] ; zaxis[0] = 0.7 * rot[2][0] ; zaxis[1] = 0.7 * rot[2][1] ; xlabel[0] = 0.8 * rot[0][0] ; xlabel[1] = 0.8 * rot[0][1] ; ylabel[0] = 0.8 * rot[1][0] ; ylabel[1] = 0.8 * rot[1][1] ; zlabel[0] = 0.8 * rot[2][0] ; zlabel[1] = 0.8 * rot[2][1] ; pushmatrix() ; loadmatrix(identity) ; bgnline() ; v2f(origin) ; v2f(xaxis) ; endline() ; _dxf_DRAW_ARROWHEAD(PORT_CTX, xaxis[0], xaxis[1]) ; bgnline() ; v2f(origin) ; v2f(yaxis) ; endline() ; _dxf_DRAW_ARROWHEAD(PORT_CTX, yaxis[0], yaxis[1]) ; bgnline() ; v2f(origin) ; v2f(zaxis) ; endline() ; _dxf_DRAW_ARROWHEAD(PORT_CTX, zaxis[0], zaxis[1]) ; if (xlabel[0] <= 0) xlabel[0] -= PDATA(swidth) ; if (xlabel[1] <= 0) xlabel[1] -= PDATA(swidth) ; if (ylabel[0] <= 0) ylabel[0] -= PDATA(swidth) ; if (ylabel[1] <= 0) ylabel[1] -= PDATA(swidth) ; if (zlabel[0] <= 0) zlabel[0] -= PDATA(swidth) ; if (zlabel[1] <= 0) zlabel[1] -= PDATA(swidth) ; #ifndef NOSHADOW if (!draw) { /* offset text slightly for shadow */ xlabel[0] += PDATA(nudge) ; xlabel[1] -= PDATA(nudge) ; ylabel[0] += PDATA(nudge) ; ylabel[1] -= PDATA(nudge) ; zlabel[0] += PDATA(nudge) ; zlabel[1] -= PDATA(nudge) ; } #endif font(0) ; cmov2 (xlabel[0], xlabel[1]) ; charstr ("X") ; cmov2 (ylabel[0], ylabel[1]) ; charstr ("Y") ; cmov2 (zlabel[0], zlabel[1]) ; charstr ("Z") ; popmatrix() ; if (draw && PDATA(redrawmode) != tdmViewEchoMode) { /* copy rendered gnomon from back buffer to front buffer */ readsource(SRC_BACK) ; frontbuffer(TRUE) ; backbuffer(FALSE) ; rectcopy (PDATA(illx), PDATA(illy), PDATA(iurx), PDATA(iury), PDATA(illx), PDATA(illy)) ; /* restore original buffer config from current tdmFrontBufferDraw */ _dxf_BUFFER_RESTORE_CONFIG (PORT_CTX, dummy, PDATA(buffermode), tdmFrontBufferDraw) ; } EXIT(("")); }
static void _dxf_DRAW_GLOBE (tdmInteractor I, void *udata, float rot[4][4], int draw) { /* * draw == 1 to draw globe, draw == 0 to undraw. This is done with two * separate calls in order to support explicit erasure of edges for * some implementations. A draw is always preceded by an undraw and * the pair of invocations is atomic. */ DEFDATA(I,tdmRotateData) ; DEFPORT(I_PORT_HANDLE) ; int u, v, on, dummy = 0 ; /* globe edge visibility flags. all globe instance share this data. */ static struct { int latvis, longvis ; } edges[LATS][LONGS] ; /* globe and globeface defined in tdmGlobeEchoDef.h */ register const float (*Globe)[LONGS][3] = globe ; register const struct Face (*Globeface)[LONGS] = globeface ; /* view normal */ register float z0, z1, z2 ; z0 = rot[0][2] ; z1 = rot[1][2] ; z2 = rot[2][2] ; #define FACEVISIBLE(u,v,z0,z1,z2) \ (Globeface[u][v].norm[0] * z0 + \ Globeface[u][v].norm[1] * z1 + \ Globeface[u][v].norm[2] * z2 > 0.0) ENTRY(("_dxf_DRAW_GLOBE (0x%x, 0x%x, 0x%x, %d)",I, udata, rot, draw)); if (draw) { lmcolor(LMC_COLOR) ; cpack(0xffffffff) ; linewidth(1) ; } else { if (PDATA(redrawmode) != tdmViewEchoMode) { /* * In tdmViewEchoMode (DX's Execute On Change), we are drawing * the globe echo on top of a background image that is redrawn * with every frame of a direct interaction. * * If we're not in that mode, the background image is static * while the globe echo rotates in front of it, so erasing the * globe means we have to repair damage to the background. We * do this by blitting a portion of the static image to the * back buffer, drawing the globe over that, then blitting the * combined results back to the front buffer. */ /* force graphics output into back (draw) buffer */ frontbuffer(FALSE) ; backbuffer(TRUE) ; /* erase globe background */ lrectwrite (PDATA(illx), PDATA(illy), PDATA(iurx), PDATA(iury), PDATA(background)) ; } #ifndef NOSHADOW /* draw wide black lines to ensure visibility against background */ lmcolor(LMC_COLOR) ; cpack(0x0) ; linewidth(2) ; #else EXIT(("No shadow")); return ; #endif } #ifndef FACEVIS /* * Compute visible edges explicitly. This method might be faster and * works in XOR mode but as implemented here is applicable only for a * globe-type object rendered with latitude and longitude lines. */ #ifndef NOSHADOW if (!draw) #endif for (u=0 ; u<LATS-1 ; u++) { if (FACEVISIBLE(u, 0, z0, z1, z2)) { edges[u][LONGS-1].latvis++ ; edges[u+1][LONGS-1].latvis++ ; edges[u][0].longvis++ ; edges[u][LONGS-1].longvis++ ; } for (v=1 ; v<LONGS ; v++) if (FACEVISIBLE(u, v, z0, z1, z2)) { edges[u][v-1].latvis++ ; edges[u+1][v-1].latvis++ ; edges[u][v].longvis++ ; edges[u][v-1].longvis++ ; } } /* north pole */ if (z1 > 0.0) for (v=0 ; v<LONGS ; v++) edges[LATS-1][v].latvis++ ; /* south pole */ if (z1 < 0.0) for (v=0 ; v<LONGS ; v++) edges[0][v].latvis++ ; /* * Draw each visible edge exactly once. */ for (u=0 ; u<LATS ; u++) { for (v=0, on=0 ; v<LONGS-1 ; v++) if (edges[u][v].latvis) { if (!on) { on = 1 ; bgnline() ; v3f(Globe[u][v]) ; } v3f (Globe[u][v+1]) ; #ifndef NOSHADOW if (draw) #endif edges[u][v].latvis = 0 ; } else if (on) { on = 0 ; endline() ; } /* close latitude line if necessary */ if (edges[u][LONGS-1].latvis) { if (!on) { bgnline() ; v3f(Globe[u][LONGS-1]) ; } v3f (Globe[u][0]) ; endline() ; #ifndef NOSHADOW if (draw) #endif edges[u][LONGS-1].latvis = 0 ; } else if (on) endline() ; } /* longitude lines */ for (v=0 ; v<LONGS ; v++) { for (u=0, on=0 ; u<LATS-1 ; u++) if (edges[u][v].longvis) { if (!on) { on = 1 ; bgnline() ; v3f(Globe[u][v]) ; } v3f(Globe[u+1][v]) ; #ifndef NOSHADOW if (draw) #endif edges[u][v].longvis = 0 ; } else if (on) { on = 0 ; endline() ; } if (on) endline() ; } #else /* * Do it the easy way: draw all visible faces regardless of shared * edges. Most edges are drawn twice, so this is slower and not * compatible with XOR rendering. */ for (u=0 ; u<LATS-1 ; u++) for (v=0 ; v<LONGS ; v++) if (FACEVISIBLE(u, v, z0, z1, z2)) poly (4, Globeface[u][v].face) ; /* north pole */ if (z1 > 0.0) poly (LONGS, Globe[LATS-1]) ; /* south pole */ if (z1 < 0.0) poly (LONGS, Globe[0]) ; #endif /* ifndef FACEVIS */ if (draw && PDATA(redrawmode) != tdmViewEchoMode) { /* copy rendered globe from back buffer to front buffer */ readsource(SRC_BACK) ; frontbuffer(TRUE) ; backbuffer(FALSE) ; rectcopy (PDATA(illx), PDATA(illy), PDATA(iurx), PDATA(iury), PDATA(illx), PDATA(illy)) ; /* restore original buffer config from current tdmFrontBufferDraw */ _dxf_BUFFER_RESTORE_CONFIG (PORT_CTX, dummy, PDATA(buffermode), tdmFrontBufferDraw) ; } EXIT(("")); }