Somebody probably has a better way that I do to make this happen.
But it would be nice if it were native to the 2D Drawing command, eg.
DrawText(Text$,DegreesToRotate)
I have found the need to do this routinely, but my solution is awkward at
best.
Maybe there should be a way to LoadFont rotated, and then just use it.
[Implemented] DrawText Rotated
-
- Enthusiast
- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
I had the same request ages ago.
In the meantime here some old Windows OS code I used to use with PB:
It's pretty straight forward.

In the meantime here some old Windows OS code I used to use with PB:
Code: Select all
; Rotate Font - example for text API
;
Declare WndProc (hwnd, msg, wParam, lParam)
Declare DrawCustomFontText (hDC, fontName$, pointSize, weight, italic, underline, angle, x, y, text$, lineSpace)
Procedure WndProc (hWnd, msg, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
spacing = 35
Select msg
Case #WM_PAINT
hDC = StartDrawing(WindowOutput())
; draw rotated text, angle# is degrees counterclockwise direction text should be rotated
x = 240
y = 40
angle = 300
DrawCustomFontText (hDC, "arial", 16, #FW_NORMAL, #False, #False, angle, x, y, "Arial, 16pt, 300 Degree Rotation", spacing)
StopDrawing()
EndSelect
ProcedureReturn Result
EndProcedure
Procedure DrawCustomFontText (hDC, fontName$, pointSize, weight, italic, underline, angle, x, y, text$, lineSpace)
lf.LOGFONT
DesktophDC = GetDC_(#HWND_DESKTOP)
hFont = GetStockObject_(#DEFAULT_GUI_FONT) ; get a font handle
bytes = GetObject_(hFont, SizeOf(lf), @lf) ; fill LOGFONT struct lf
PokeS (@lf\lffaceName, fontName$)
lf\lfitalic = italic ; set italic
lf\lfweight = weight ; set weight
lf\lfunderline = underline ; set underlined
lf\lfescapement = angle * 10 ; set text rotation
lf\lfheight = -1 * pointSize * GetDeviceCaps_(hDC, #LOGPIXELSY) / 72
ReleaseDC_(#HWND_DESKTOP, DesktophDC)
hCustFont = CreateFontIndirect_(@lf) ; create a new font and get handle
hOldFont = SelectObject_(hDC, hCustFont)
tm.TEXTMETRIC
GetTextMetrics_(hDC, @tm)
lineSpace = tm\tmheight + tm\tmexternalLeading
pixels = tm\tmheight
leading = tm\tmexternalLeading
Locate(x,y)
TextOut_(hDC, x, y, @text$, Len(text$))
SelectObject_(hDC, hOldFont)
DeleteObject_(hCustFont)
EndProcedure
; main
winMain = OpenWindow (0, 0, 0, 550, 350, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Font Demo")
SetWindowCallback(@WndProc ())
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End

- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Why not draw the text to an image, grab that to a 3d sprite, (you can do this without ever showing it to the user) and then you can zoom and rotate to your heart's content. You need a screen or windowed screen as opposed to a straight window is the only requirement.
Last edited by netmaestro on Wed Feb 22, 2006 6:58 am, edited 2 times in total.
BERESHEIT
fonts are vector objects but 3D sprites aren't, so if you you zoom you will lose quality...netmaestro wrote:Why not draw the text to an image, grab that to a 3d sprite, (you can do this without ever showing it to the user) and then you can zoom and rotate to your heart's content. You need a screen or windowed screen as opposed to a straight window is the only requirement.
Dri