c++ - OpenGL fade issue -


this i'm doing:

  • render first image using color of: glcolor4f(1.0, 1.0, 1.0, 1.0);
  • render second image, using color of: glcolor4f(1.0, 1.0, 1.0, calc);. calc number goes 0.0 1.0 within second, , can verify this.

what expect fade 1 image other, , this, halfway through, goes kind of shade of grey (black background color, btw). can see issue here: http://www.youtube.com/watch?v=8dzxiyim43s&feature=youtu.be .

i want basic fade, without greyish tone when in middle of fading (which strongest @ 0.5 opacity). i've tried doing gimp, bottom layer opaque, top layer variable opacity, , works fine, exactly want do, don't know why code (or opengl) won't same. video demonstrating mean: http://www.youtube.com/watch?v=ym-vpu9hhjq&feature=youtu.be

edit: after bit of experimentation (changing background color red), @ 0.5, becomes translucent, effect wanted, except both texture translucent (not 1 on top). why happen??

here code:

void sprite::render_single(image* image, pos2d pos, angle angle) {         int cx = image->width / 2;         int cy = image->height / 2;         glpushmatrix();         gltranslatef(pos.x + cx, pos.y + cy, 0);         glrotatef(angle.to_degrees(), 0.0, 0.0, 1.0);         gltranslatef(-cx, -cy, 0);         image->bind();         glbegin(gl_quads);                 gltexcoord2f(0.0, 0.0);                 glvertex2f(0.0, 0.0);                 gltexcoord2f(1.0, 0.0);                 glvertex2f(image->width, 0.0);                 gltexcoord2f(1.0, 1.0);                 glvertex2f(image->width, image->height);                 gltexcoord2f(0.0, 1.0);                 glvertex2f(0.0, image->height);         glend();         image->unbind();         glpopmatrix(); }  void sprite::render(pos2d pos, angle angle) {         image* img = this->get_current_frame();         if (this->images.size() == 1) {                 this->render_single(img, pos, angle);                 return;         }         double calc = (((double)this->current_frame_overflow) / this->frame_length);         std::cout << calc << std::endl;         glpushmatrix();         glcolor4f(1.0f, 1.0f, 1.0f, 1.0f);         this->render_single(img, pos, angle);         img = this->get_next_frame();         glcolor4f(1.0f, 1.0f, 1.0f, calc);         this->render_single(img, pos, angle);         glcolor4f(1.0f, 1.0f, 1.0f, 1.0f);         glpopmatrix(); } 

blend function used: glblendfunc(gl_src_alpha, gl_one_minus_src_alpha);

opengl initialization function:

/**  * @brief initializes opengl  */ void game::init_gl() {         float width = this->display->w;         float height = this->display->h;         glmatrixmode(gl_projection);         glloadidentity();         gluortho2d(0.0, width, height, 0.0);         glmatrixmode(gl_modelview);         glloadidentity();         gldisable(gl_depth_test);         glenable(gl_blend);         glblendfunc(gl_src_alpha, gl_one_minus_src_alpha); } 

also, here whole source code main loop (which contains of opengl stuff): https://github.com/mijyn/dbab/blob/master/src/game.cpp . , sprite: https://github.com/mijyn/dbab/blob/master/src/sprite.cpp .

when use glblendfunc function (with blending enabled) same factors used calculate alpha value of destination fragment.

this matters if rendering texture has alpha channel , subsequently using texture blending enabled. in case, alpha channel of rendered texture ends values between 0 , one. causes of background bleed through when texture drawn buffer.

the solution disable blending when drawing full-screen quad. also, might remove channel texture if you're not using (use gl_rgb instead of gl_rgba internal texture format).


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -