Learn More

Saturday, September 17, 2011

Rotate Image Using SDL

barrel rotated 30 degrees from the original position
Hello dear visitor, this time we discussed how to rotate the image with SDL, but before you are required to read the topic about how to install SDL_gfx in CodeBlocks (we provide the video).

Many people who struggle to rotate an image with the SDL, required some additional scripts that we can rotate the picture. However, with SDL_gfx we can finish it. We can simply add a library of SDL_rotozoom.h and use the command rotozoomSurface (SDL_Surface * source, double angle, double zoom, int smooth).

Let us apply SDL_gfx, re-read our post earlier about making a sprite sheet. As is known the above, rotozoomSurface require source pointer, while drawfiles is void. Maybe we put rotozoomSurface inside drawfiles function, but we need some additional code which is quite complicated. There are other alternatives, ie we include a new file, called cannon, whose contents is a picture of the barrel of the bazooka. We call this file, then we optimization, and then we rotate. In this way, then we only need a simple new function.


The function above is actually a continuation of the function load_image. So after cannon.png is optimization, then we turn the rotate function. Since we are using file connan, then we need to initialize. In addition, because we also will rotate connan, then we need to initialize as well.


Remember, we have used the surface for connan and rotate_connan, then we need to improve the function clean_up.


In this example, we display a barrel that rotated 30 degrees from the starting position. To get the source code of this tutorial, please download the source code of rotate image here.