Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Rotating the screen 90°... possible?

This thread is locked; no one can reply to it. rss feed Print
Rotating the screen 90°... possible?
Marton
Member #7,173
April 2006

I'd like to be able in my game at some point rotate the screen 90°... Is this possible without having to use rotated fonts/objects so they display correctly rotated???

Thanks!!

brigham toskin
Member #2,213
April 2002

instead of drawing directly to the screen when displaying your code, write it to an offscreen bitmap. You can then transfer that to the screen with rotate_sprite() or related function. You'll take a performance hit, but it might not really be noticeable on modern hardware.

---
I now submit to your flogging.

TeamTerradactyl
Member #7,733
September 2006
avatar

Do you mean simplyp drawing your "completely rendered" BITMAP to your screen, flipped 90-degrees? If so, you can probably very simply employ the rotate() function (see forum thread http://www.allegro.cc/forums/thread/323382 for others trying to do something similar...).

Marton
Member #7,173
April 2006

Will check the thread, thanks!
What I need to do is have a textprintf() call that would write text rotated 90°... Can I do the printf to a bitmap buffer and then rotate it?

brigham toskin
Member #2,213
April 2002

yes

---
I now submit to your flogging.

Marton
Member #7,173
April 2006

How am I supposed to do it? It doesn't rotate and the bitmap appears one pixel to the left and one down... I know this may be bad code but hey I'm learning :)

DATAFILE *datafile;
BITMAP *bitmap, *temp;

bitmap = create_bitmap(320,200);
temp = create_bitmap(320,200);
text_mode(-1);
set_color_depth(16);
set_color_conversion(COLORCONV_TOTAL);

datafile = load_datafile("test.dat");
blit(datafile[1].dat, bitmap, 0, 0, 0, 0, 320, 200);
textprintf_centre(bitmap, datafile[0].dat, 160, 165, makecol(255, 0, 0), "Please wait... ");
rect(bitmap, 50, 195, 267, 175, makecol(255, 255, 255));
rect(bitmap, 0, 199, 319, 0, makecol(255, 255, 255));
rotate_sprite(temp, bitmap, 0, 0, 90);
blit(temp, screen, 0, 0, 0, 0, 320, 200);
destroy_bitmap(bitmap);
destroy_bitmap(temp);
unload_datafile(datafile);

kazzmir
Member #1,786
December 2001
avatar

A) you have to used 'fix' numbers
B) the angle is really 0-255, not 0-360.

rotate_sprite( temp, bitmap, 0, 0, itofix( 64 ) );

In general to convert 0-360 into 0-255 use this

angle * 256 / 360

Marton
Member #7,173
April 2006

Thanks!!! That was the trick!

Fladimir da Gorf
Member #1,565
October 2001
avatar

If you want performance, there's more efficient ways to rotate a bitmap 90 decrees (as it's a special case of rotation). However, you'll need to write your own drawing function for that.

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

miran
Member #2,407
June 2002

I think roatate_sprite already does multiples of 90 degrees with specialized more efficient code.

--
sig used to be here

Tobias Dammers
Member #2,604
August 2002
avatar

Yes it does. At least the C version of the code contains a comment somewhere about the trivial cases (i.e. multiples of 90 degrees).

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Arthur Kalliokoski
Second in Command
February 2005
avatar

Does this game use matrices to set screen positions? If so, you could alter a few members of the matrix and it'll get rotated automagically.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Marton
Member #7,173
April 2006

Nope, no matrices. Anyway with rotate_sprite it works like a charm :)

Thanks!!

Go to: