Sign in to follow this  

Image zoom + fading = way too slow

This topic is 4582 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

I'm trying to do a somewhat simple task in C++ with SDL and SDL_gfx. Basically I just want to take an image and have it slowly zoom while fading in over a white background. I finally got it to work, but the thing can't seem to run more than about 1 fps. I'm pretty lost on how to accomplish this task any other way, so is there a better approach or a way to clean up my code that might fix this? Removing the SetAlpha causes everything to run at a normal speed, so I know my limitation lies there. Here's the code (this is inside a loop):
int i=0;
static double zoomx=.6,zoomy = .6;
zoomx += 0.005;
zoomy += 0.003;
SDL_Surface* imageZoom = zoomSurface(image,zoomx,zoomy,1);
SDL_Surface* src = SDL_CreateRGBSurface(SDL_SWSURFACE,scrwidth,scrheight,32,RMASK,GMASK,BMASK,AMASK);
	    
//Blit a copy of the current screen.
SDL_BlitSurface(imageZoom,NULL,src,NULL);
if(i<256)
  {
  i+=32;
  SDL_BlitSurface(src,NULL,imageZoom,NULL);
  SDL_SetAlpha(screen,SDL_SRCALPHA,i);
  SDL_BlitSurface(screen,NULL,imageZoom,NULL);
  }
        
// Draw the zoomed image
SDL_Rect rect;
rect.x = scrwidth/2 - (int)(image->w * zoomx)/2;
rect.y = scrheight/2 - (int)(image->h * zoomy)/2;
SDL_BlitSurface(imageZoom, NULL, screen, &rect);

// Clear memory when finished with the zoomed image
SDL_FreeSurface(imageZoom);
SDL_Flip(screen);        // Flip the buffers

Share this post


Link to post
Share on other sites
Hi,

is your image generated by a 3D engine ? If so, then it's simpler : gradually change the viewport FOV value to have the zooming effect, and draw an alpha quad filling the whole screen, on top of your scene.

If it's 2D, then sorry I can't help :/

Share this post


Link to post
Share on other sites
Nope, it's 2D. Just a bitmap loaded in standard SDL style. I'm still learning how this whole thing works, so if there is an easy way to generate the image in 3D space and move toward it rather than using the zoomsurface, I'm interested.

Share this post


Link to post
Share on other sites
hi,

using your image as a texture on a 3D quad, then zooming into it would be simple ... if you know a little OpenGL.
All I can advice is : find a tutorial on OpenGL and SDL (I think there's an example code in the SDL files ...) and then modify it to do that. But I don't know if it's the best solution for your problem ^^

anyway, good luck with that, i can't help you more than that :/

Share this post


Link to post
Share on other sites

This topic is 4582 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