Scaling images

Started by
2 comments, last by BeerNutts 11 years, 1 month ago

Hello, I am working on a game and I have a 16x16 image that I want to make 64x64, is there a way to do this in code that does not use anything but c++ and the SDL library(no extensions)? I don't want to use OpenGL because I am still learning and I do not want to over complicate things with openGL. Thanks.

Advertisement

You probably want to look into using the SDL_SoftStretch function. If you have a source 16x16 SDL_Surface* called (for example) image_16square and a destination 64x64 SDL_Surface* called (for example) image_64square you would call it like this:

SDL_SoftStretch(image_16square, NULL, image_64square, NULL);

Untested. This uses SDL 2.0. If you're using SDL 1.2 you should specify. Basically you'd lock both the 16x16 source surface and the 64x64 destination surface. Then you'd go through every pixel in the 16x16 surface and set the equivalent 4 pixels in the destination surface to the same value as that pixel.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

http://www.sdltutorials.com/sdl-scale-surface enjoy ;p

If you are doing scaling, or rotating, I would suggest not do anything in SDL as it is all done in software, and will slow down your PC terribly (at least using the released SDL 1.2). I would suggest looking at SFML as it does all scaling and rotating natively for you in HW.

In the long run, you'll be happy you switched IMO (not just for graphics, but for the other interfaces it provides).

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

This topic is closed to new replies.

Advertisement