Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Zoom in/out

This thread is locked; no one can reply to it. rss feed Print
Zoom in/out
AlexKidd
Member #7,222
May 2006

Could anybody please tell me the best way to zoom in and out of a background with sprites please. I know you can increase the size of a bitmap, but you cant dump the contents of a screen to a bitmap can you?

zer0
Member #6,501
October 2005
avatar

You'd have to do it a different way than you're thinking. Yes, you can dump the contents of video memory into a bitmap object, but accessing it is a lot slower than accessing normal ram.

So you have two choices:
1) the easy way, which is to draw all the objects you want "zoomed in" to a buffer, then resize a portion of that to the entire size of the buffer.

2) Use your skills to figure out the position of all the sprites and the background size after zooming in and draw them. If done right this may be faster.

Felipe Maia
Member #6,190
September 2005
avatar

Just stretch the image to the size you want.

AlexKidd
Member #7,222
May 2006

Im not sure i follow the buffer idea. Im quite new to Allegro, so im sure im missing the command needed. I only know how to resize a bitmap image.

Paladin
Member #6,645
December 2005
avatar

stretch_blit(); should do the trick for you. If you actually wanted to resize the image, you could stretch blit the image to another bitmap, and use the other bitmap as the resized image, although I'm sure there are better methods. I was wondering how to zoom in myself so that you could utilize it for an image creation program. So the pixels are like actually 10X10. Ehh, whatever.

AlexKidd
Member #7,222
May 2006

I know about the strech_blit() command. But you can only use this on a bitmap cant you? I need to zoom in and out of a screen which is randomly created at runtime. Can anyone tell me how i can do this please.

miran
Member #2,407
June 2002

Like this:

// World coordinates:
float x_world;

// Zoom factor:
float zoom;

// Screen coordinates:
float x_screen = x_world * zoom;

--
sig used to be here

AlexKidd
Member #7,222
May 2006

I understand that. But what command would zoom into a screen with sprites/background. Do i have to somehow dump the contents of the screen to a bitmap?

Felipe Maia
Member #6,190
September 2005
avatar

You can have a dblbuffer with all the things, and then stretch_blit to the screen, or you can draw all items one by one already stretched. I don't know which method is best because I never did it.

miran
Member #2,407
June 2002

Quote:

I understand that. But what command would zoom into a screen with sprites/background. Do i have to somehow dump the contents of the screen to a bitmap?

Use this:
masked_stretch_blit(sprite, buffer, 0, 0, sprite->w, sprite->h, screen_x, screen_y, sprite->w*zoom, sprite->h*zoom)
for each sprite that you have including tiles. Also you should add a pan variable into the formula for adjusting the position of the zoomed-in area: screen_x = (world_x + pan)*zoom;.

And btw, screen IS a bitmap. Your questions sound very confused.

--
sig used to be here

A J
Member #3,025
December 2002
avatar

are you trying to zoom the background, yet not change the size of the sprites?

___________________________
The more you talk, the more AJ is right. - ML

Go to: