# Image zoom + fading = way too slow

## Recommended Posts

TheDingo    122
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);

//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 on other sites
paic    645
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 on other sites
TheDingo    122
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 on other sites
paic    645
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 on other sites
TheDingo    122
Well, things just got a lot worse. I found an OpenGL tut and set everything up to render with OpenGL. Now my program just displays garbage at all times.

##### Share on other sites
TheDingo    122
Got it to work pretty well by turning my image into a particle sprite in Kyra and scaling it while changing the alpha.