static void drawbutton(gl_button *bt) { Int32 lw = getlwidth(); Int32 cl = getcolor(); Int32 oriwin = winget(); int cfg, bg; winset(bt->win); linewidth(1); locate_button(bt); cfg = *(bt->state)?bt->bg:bt->fg; bg = *(bt->state)?((bt->type == BUTTON)?bt->fg:bt->active_c):bt->bg; color(bg); rectf(bt->x, bt->y, bt->x + bt->width, bt->y + bt->height); color(bt->fg); rect (bt->x, bt->y, bt->x + bt->width, bt->y + bt->height); if (bt->label != NULL) { color(cfg); cmov2(bt->x, bt->y + 0.05 * bt->height); charstr(bt->label); } winset(oriwin); color(cl); linewidth(lw); sleep(0); }
// render ecef geometry void miniview::render_ecef_geometry(double) { // render plain globe for z-values: static miniglobe globe; static const int gltess = 32; static const double glscale = 0.999; static const double glzscale = 1.05; globe.settess(gltess); globe.setscale(1.0); globe.setdynscale(glscale); globe.setZscale(glzscale); disableRGBAwriting(); globe.render(); enableRGBAwriting(); initstate(); // render ecef z-axis: linewidth(2); enablelinesmooth(); static const miniv3d zacolor(0.25, 0.25, 0.5); color(zacolor); renderline(miniv3d(0.0, 0.0, -1.1*getorbradius()), miniv3d(0.0, 0.0, -getorbradius())); renderline(miniv3d(0.0, 0.0, getorbradius()), miniv3d(0.0, 0.0, 1.1*getorbradius())); // render equator: linewidth(1); disableZwriting(); static const int eqlines = 100; static const miniv3d eqcolor(0.25, 0.25, 0.25); color(eqcolor); for (int i=0; i<=eqlines; i++) { minicoord c(miniv3d((double)i/eqlines*360*3600, 0.0, 0.0),minicoord::MINICOORD_LLH); c.convert2(minicoord::MINICOORD_ECEF); static minicoord c0; if (i>0) renderline(c0.vec, c.vec); c0 = c; } enableZwriting(); disablelinesmooth(); exitstate(); }
static void drawslider(gl_slider *sl) { Int32 lw = getlwidth(); Int32 cl = getcolor(); Int32 oriwin = winget(); long co; int i; Screencoord x, y; Int32 xo, yo; winset(sl->win); linewidth(1); update_slider_value(sl); locate_slider(sl); if (sl->txbg == -1) { /* first time, get bg color */ cmov2(sl->x + sl->len + sl->thick, sl->y); getcpos(&x, &y); getorigin(&xo, &yo); x -= xo; y -= yo; i = lrectread(x, y, x, y, &co); sl->txbg = co; #ifdef DEBUG printf("textbg = %d, bytes = %d x %d (soll %g) y %d (soll %g)\n", co,i,x,sl->x + sl->len + sl->thick, y,sl->y); #endif } color(sl->bg); rectf(sl->x, sl->y, sl->x+sl->thick+sl->len, sl->y+sl->height); color(sl->fg); rect (sl->x, sl->y, sl->x+sl->thick+sl->len, sl->y+sl->height); rectf(sl->x + sl->len * (sl->value - sl->min)/(sl->max - sl->min), sl->y, sl->x + sl->len * (sl->value - sl->min)/(sl->max - sl->min) + sl->thick, sl->y + sl->height); if (sl->buf != NULL) { color(sl->txbg); cmov2(sl->x + sl->len + sl->thick, sl->y); charstr(sl->buf); color(sl->fg); sprintf(sl->buf + 1, sl->format, sl->value); cmov2(sl->x + sl->len + sl->thick, sl->y); charstr(sl->buf); } winset(oriwin); color(cl); linewidth(lw); sleep(0); }
void WarpPerspective::draw( bool controls ) { // only draw grid while editing if( isEditModeEnabled() ) { gl::pushModelMatrix(); gl::multModelMatrix( getTransform() ); gl::ScopedGlslProg shader( gl::getStockShader( gl::ShaderDef().color() ) ); gl::ScopedLineWidth linewidth( 1.0f ); glHint( GL_LINE_SMOOTH_HINT, GL_NICEST ); gl::ScopedColor color( Color::white() ); for( int i = 0; i <= 1; i++ ) { float s = i / 1.0f; gl::drawLine( vec2( s * (float)mWidth, 0.0f ), vec2( s * (float)mWidth, (float)mHeight ) ); gl::drawLine( vec2( 0.0f, s * (float)mHeight ), vec2( (float)mWidth, s * (float)mHeight ) ); } gl::drawLine( vec2( 0.0f, 0.0f ), vec2( (float)mWidth, (float)mHeight ) ); gl::drawLine( vec2( (float)mWidth, 0.0f ), vec2( 0.0f, (float)mHeight ) ); gl::popModelMatrix(); if( controls && mSelected < mPoints.size() ) { // draw control points for( int i = 0; i < 4; i++ ) queueControlPoint( mDestination[i], i == mSelected ); drawControlPoints(); } } }
// signpost post-render method void minipointrndr_signpost::post(int pass) { if (pass==1) linewidth(1); else if (pass==2) disablelinesmooth(); }
// signpost pre-render method void minipointrndr_signpost::pre(int pass) { if (pass==1) { linewidth(2); enablelinesmooth(); color(0.25f,0.25f,0.5f); } else if (pass==2) minitext::configure_zfight(0.975f); }
Material::Material(Material_t tag) : tag(tag), vertexShader(this), fragmentShader(this), index0AttributeName(this) { mId = Material::MaterialIdCount++; mUuid = Math::generateUUID(); mName = ""; side() = kFrontSide; opacity() = 1.0f; transparent() = false; blending() = kNormalBlending; blendSrc() = kSrcAlphaFactor; blendDst() = kOneMinusSrcAlphaFactor; blendEquation() = kAddEquation; depthTest() = true; depthWrite() = true; polygonOffset() = false; polygonOffsetFactor() = 0; polygonOffsetUnits() = 0; // mAlphaTest = 0; overdraw() = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer visible() = true; needsUpdate() = true; // By default, bind position to attribute index 0. In WebGL, attribute 0 // should always be used to avoid potentially expensive emulation. index0AttributeName("position"); linewidth() = 1.0f; metal() = false; perPixel() = true; shading() = kNoShading; vertexColors() = kNoColors; wireframe() = false; wireframeLinewidth() = 1.0f; }
void DrawLines::process() { utilgl::activateTargetAndCopySource(outport_, inport_, ImageType::ColorOnly); { utilgl::GlBoolState linesmooth(GL_LINE_SMOOTH, false); utilgl::LineWidthState linewidth(lineSize_); lineShader_.activate(); lineShader_.setUniform("color", lineColor_); lineDrawer_.draw(); lineShader_.deactivate(); } utilgl::deactivateCurrentTarget(); compositor_.composite(inport_, outport_, ImageType::ColorOnly); }
setup_lcube() { window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0); lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0); linewidth(3); /* * Start with a very ordinary filled cube like the old demo.. */ makecube(filledthing); makecube(outlinething); backbuffer(1); }
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(("")); }
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(("")); }