Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Draw a TTF font on it's side?

This thread is locked; no one can reply to it. rss feed Print
Draw a TTF font on it's side?
nshade
Member #4,372
February 2004

I'm not seeing a function for this, but is there a easy way to draw text sideways, (rotated 90 degrees) is there a trick to doing it?

Elias
Member #358
May 2000

Something like this should work:

--
"Either help out or stop whining" - Evert

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

nshade
Member #4,372
February 2004

Turn it on it's side. I would use the example above, but what on earth is t pointing at?

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

EDIT
Oh I get you. t is an ALLEGRO_TRANSFORM*.

T doesn't point at anything, it's a transform, not a vector. He sets up the transform to rotate around the origin by 90 degrees clockwise and then uses the transform before drawing the text. You'll probably want to center your text before you rotate it though.

ALLEGRO_TRANSFORM t;
al_identity_transform(&t);
al_translate_transform(&t , -xpos , -ypos);
al_rotate_transform(&t , M_PI/2.0f);
al_translate_transform(&t , xpos , ypos);
al_use_transform(&t);
al_draw_text(font , al_map_rgb(255,255,255) , xpos , ypos , ALLEGRO_ALIGN_CENTER , my_string);

nshade
Member #4,372
February 2004

I'm not at my main system right now, but does that transform the whole drawing surface. As in, if I was to paste bitmaps or draw primitives, they will also be transformed as well until I reset the use_transform();

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

The transforms that you 'use' affect the current bitmap target only. But if that is the backbuffer, then it affects all drawing.

nshade
Member #4,372
February 2004

I guess the question is, how do you set it back to normal after the text print. There doesn't seem to be a "clear" command and I have other non-rotated things being drawn to my target bitmap. (I admit my matrix math is a little weak so I don't know what an "identity" is)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I think its in the manual.

http://liballeg.org/a5docs/trunk/transformations.html#al_use_transform

Quote:

Call this function with an identity transformation to return to the default behaviour.

However, to reset the projection transform is a little different. But you didn't alter that, so no worries.

jmasterx
Member #11,410
October 2009

  int GraphicsContext::drawRotatedText( const std::string& text,agui::Font* font,const agui::Color& color, int x, int y, float deg, int flags )
  {
    int fx = font->getTextWidth(text) / 2;
    int fy = font->getLineHeight() / 2;
    m_transform.identity();
    m_transform.translate(-fx,-fy);
    m_transform.rotate(deg);
    m_transform.translate(x,y);
    useTransform(m_transform);
    drawText(text,font,color,0,0,flags);
    resetTransform();
    return fx * 2;
  }

https://github.com/jmasterx/StemwaterSpades/blob/master/Spades%20Game/Game/Engine/GraphicsContext.cpp

Go to: