Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Draw to second screen to ZOOM 2X

Credits go to Edgar Reynaldo, kazzmir, Luiji99, and SiegeLord for helping out!
This thread is locked; no one can reply to it. rss feed Print
Draw to second screen to ZOOM 2X
No God Mode Required
Member #7,195
May 2006

I want to draw everything to a non-screen ALLEGRO_BITMAP, then blit it to the screen at twice the size (stretched). How?

ALLEGRO_DISPLAY *dpy;
dpy = al_create_display(800, 480);  /* Doen't always actually make it this size... weird bug*/
ALLEGRO_DISPLAY *zoom;
zoom = al_create_display(400, 240);

//...
/* blit(source, dest,0,0,0,0,w,h); */
al_draw_bitmap(source,/*NO DEST ,*/ w, h,0);
//...

al_flip_display();

Luiji99
Member #12,254
September 2010

ALLEGRO_BITMAP *source = /* get the bitmap */;
ALLEGRO_BITMAP *target = /* create the bitmap */;

/* blit source to target */
al_set_target_bitmap(target);
al_draw_bitmap(source, pointOnTargetX, pointOnTargetY, 0);
al_set_target_bitmap(NULL);

/* blit target to screen, stretched */
al_draw_scaled_bitmap(target, 0, 0, al_get_bitmap_width(target), al_get_bitmap_height(target), pointOnScreenX, pointOnScreenY, stretchedWidth, stretchedHeight, 0);

Programming should be fun. That's why I hate Java.
http://www.entertainingsoftware.com/

Edgar Reynaldo
Member #8,592
May 2007
avatar

kazzmir
Member #1,786
December 2001
avatar

Do you really need to draw to the non-screen bitmap first? Its easier (and better) to set up a transformation on the screen and just do normal drawing. If you draw to a different bitmap you will be using FBO's which is not always the best idea.

ALLEGRO_TRANSFORM transform;
al_identity_transform(&transform);
al_scale_transform(&transform, 2, 2); // scale x and y by 2
al_use_transform(&transform);
.. do normal drawing ..

<edit> Ok I see you want to draw to two screens. It might be simpler just to draw with the identity transform on screen 1 and with a scaled transform on screen 2.

No God Mode Required
Member #7,195
May 2006

I want to do two things:

(1) Make everything 2X as big (16x16 pixel blocks should be 32x32)
(2) Have resolution independence (Additional zooming as needed)

Program LOTS of BITMAPS and zero primitives. I tried the second part of http://wiki.allegro.cc/index.php?title=Achieving_Resolution_Independence but it just turns the full screen black.

I thought transforming was bad if not a lot of primitives were used.

Luiji99's original code doesn't work, I will try re-putting it in with Edgar Reynaldo's addition.

kazzmir
Member #1,786
December 2001
avatar

From talking with other people I think that transformations are the way to go. They are not slower for bitmaps. I recommend it.

No God Mode Required
Member #7,195
May 2006

Ok, I will use transforms then, they seem to be working.

How do you get the transformed Screen dimensions from Allegro, or must I have some global variables?

kazzmir
Member #1,786
December 2001
avatar

You can get the screen dimensions by calling al_get_bitmap_width/height on the current backbuffer.

SiegeLord
Member #7,827
October 2006
avatar

There are some advantages to using an explicit secondary buffer instead of transformations. Firstly, primitives will use the correct size pixels. Secondly, if you use fractional positions for bitmaps and other stuff they'll also be placed correctly. Also a buffer allows you to use a shader to perform the final scaling.

There's no question that transforms are faster though.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

No God Mode Required
Member #7,195
May 2006

ALLEGRO_BITMAP * backbuffer = al_get_backbuffer(al_get_current_display());
How is that different from checking the screensize? It gives me the same values (1280x1024) regardless of the transforms I apply, even though I request the screen to be 800x480 on initialization. ???

And what about comparing the difference between two different transforms, say the current transform and the identity (I think that's the right term for the transform at initialization)?

Luiji99
Member #12,254
September 2010

Edgar: whoops. I was thinking of a different function...

Programming should be fun. That's why I hate Java.
http://www.entertainingsoftware.com/

No God Mode Required
Member #7,195
May 2006

Other than getting the difference between two transforms (which wasn't the original question anyway) I think I got it.

Thanks everyone.

kazzmir
Member #1,786
December 2001
avatar

Well I'm not a linear algebra expert but a transform is just a 4x4 matrix so in theory you could use some linear algebra operations to compare two matrices.

What exactly do you want to know about two transformations?

No God Mode Required
Member #7,195
May 2006

The scaling difference between the two of them - their ratios to each other.

kazzmir
Member #1,786
December 2001
avatar

In general I'm not sure but if you only ever apply a scaling factor to transformations starting from the identity transformation then you can transform a coordinate and use the output to do comparisons.

ALLEGRO_TRANSFORM t1, t2;
al_identity_transform(&t1);
al_scale_transform(&t1, 2, 2);
al_identity_transform(&t2);
al_scale_transform(&t2, 1.4, 1.4);

float x1, y1, x2, y2;
x1 = y1 = x2 = y2 = 1;
al_transform_coordinates(&t1, &x1, &y1);
al_transform_coordinates(&t2, &x2, &y2);

printf("scaling factor of t1 is %f\n", x1);
printf("scaling factor of t2 is %f\n", x2);
printf("scaling ratio between t1 and t2 is %f\n", x1 / x2);

You can tell what the scaling factor is by how much the initial coordinate, x1 or x2, changes after transforming it with the given transformation.

If you apply any translations or rototations then you can't use this simple method and things get much more complicated.

No God Mode Required
Member #7,195
May 2006

Thanks~!

Go to: