Sign in to follow this  

Fading two surfaces

This topic is 4685 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here's my attempt to fade two surfaces.My display mode is set to 1024 x 768 x 16 (565).The width and height of the two surfaces are identical to the ones of the primary surface. void alphaBlend(void) { WORD src_pixel; WORD dst_pixel; BYTE src_b, src_g, src_r, // variables holding the color components of dst_b, dst_g, dst_r, // the source and destination pixels new_b, new_g, new_r; // blend_result is the surface filled with a color (1024x768) blend_result->Lock(NULL, &srf_desc, DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT, NULL); // bmp_stretch is the surface containing the 1024 x 768 bitmap bmp_stretch->Lock(NULL, &bmp_desc, DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT, NULL); srf_data = (WORD*)srf_desc.lpSurface; bmp_data = (WORD*)bmp_desc.lpSurface; for(int y = 0; y < SCREEN_HEIGHT; y++) for(int x = 0; x < srf_desc.lPitch/2; x++) { // retrieve pixels dst_pixel = srf_data[y * srf_desc.lPitch/2 + x]; src_pixel = bmp_data[y * bmp_desc.lPitch/2 + x]; // extract color components src_r = src_pixel & 0x1f; src_g = (src_pixel << 5) & 0x3f; src_b = (src_pixel << 11) & 0x1f; dst_r = dst_pixel & 0x1f; dst_g = (dst_pixel << 5) & 0x3f; dst_b = (dst_pixel << 11) & 0x1f; // blending formula new_b = (0.5 * (src_b - dst_b) ) + dst_b; new_g = (0.5 * (src_g - dst_g) ) + dst_g; new_r = (0.5 * (src_r - dst_r) ) + dst_r; // remplace the old value of the destination surface with the blended one dst_pixel = new_r | (new_g >> 5) | (new_b >> 11); } // when everything's done, unlock the used surfaces blend_result->Unlock(NULL); bmp_stretch->Unlock(NULL); }

Share this post


Link to post
Share on other sites

This topic is 4685 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this