00001 /********************************************************************** 00002 * fader_texture.C 00003 **********************************************************************/ 00004 00005 00006 #include "geom/gl_view.H" 00007 #include "fader_texture.H" 00008 00009 /********************************************************************** 00010 * FaderTexture: 00011 * 00012 * Fades from one texture to another over a given time interval. 00013 **********************************************************************/ 00014 int 00015 FaderTexture::draw(CVIEWptr& v) 00016 { 00017 // get the opacity of the fading texture: 00018 double a = fade(v->frame_time()); 00019 00020 // put the base GTexture in charge of itself: 00021 _base->set_ctrl(0); 00022 00023 // are we done? 00024 if (a <= 0) { 00025 // our job is done 00026 int ret = _base->draw(v); // draw normally 00027 delete this; // kill ourselves 00028 return ret; 00029 } 00030 00031 // If the fading-out texture doesn't draw the patch 00032 // triangles in filled mode, then all parts of the 00033 // fading-in texture need to use alpha = 1 - a. 00034 // 00035 // Otherwise, the fading-in texture can draw its filled 00036 // triangles (if any) with alpha = 1. In any case, 00037 // those parts of the fading-in texture that don't 00038 // correspond to filled triangles of the patch should 00039 // use alpha = 1 - a. 00040 00041 // set GL state for blending the two 00042 glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT); 00043 glEnable(GL_BLEND); // GL_ENABLE_BIT 00044 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_COLOR_BUFFER_BIT 00045 00046 // draw the base with alpha = 1 - a (where needed): 00047 _base->draw_filled_tris(_fader->draws_filled() ? 1.0 : 1-a); 00048 _fader->draw_with_alpha(a); 00049 _base->draw_non_filled_tris(1-a); 00050 00051 // re-assert control of the base texture for next time: 00052 _base->set_ctrl(this); 00053 00054 // restore state: 00055 glPopAttrib(); 00056 00057 return _patch->num_faces(); 00058 } 00059 00060 /* end of file fader_texture.C */