Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3D Text
#3
[Image: oghyu7d.png]

Code: (Select All)

$Color:32
Screen _NewImage(1024, 768, 32)
'font& = _LoadFont("C:\Windows\Fonts\arial.ttf", 48)
font& = _LoadFont("arial.ttf", 48)

Do
    Cls
    Line (512 - 5, 384)-(512 + 5, 384), _RGB(255, 0, 0)
    Line (512, 384 - 5)-(512, 384 + 5), _RGB(255, 0, 0)

    k = _KeyHit
    Select Case k
        Case 18432 'up
            y = y - 1
        Case 20480 'down
            y = y + 1
        Case 19200 'left
            x = x - 1
        Case 19712 'right
            x = x + 1
        Case Asc("A"), Asc("a")
            z = z - 1
        Case Asc("Z"), Asc("z")
            z = z + 1
        Case Asc("R"), Asc("r") 'reset
            x = 0: y = 0: z = 0
        Case 27, 32
            System
    End Select
    Print x, y, z
    Draw3DTextFull "Go team Steve!", font&, Yellow, 512, 384, y, x, z, 2, 10, 10, 1
    _Display
Loop
System


Sub Draw3DTextFull (text$, fontHandle&, col~&, x!, y!, rotX!, rotY!, rotZ!, scale!, depth%, dirX!, dirY!)
    Dim img&, w%, h%
    Dim i%

    ' Measure text using the chosen font
    _Font fontHandle&
    w% = 600'_PrintWidth(text$)
    h% = _FontHeight+100

    ' Render text into image using the SAME font
    img& = _NewImage(w%, h%, 32)
    _Dest img&
    _Font fontHandle& ' <<< CRITICAL FIX
    Cls , _RGBA(0, 0, 0, 0)
    Color col~&, 0

'        _PrintString (0, 0), text$

  for i=1 to len(text$)
      _PrintString (50+i*30, 20+20*sin(i*0.7)), mid$(text$,i,1)
  next

  dim as _unsigned long r,g,b,cc
  _source img&
  for yy=0 to _height(img)-1
  for xx=0 to _width(img)-1
   
        cc = point(xx, yy)
        r = _red(cc)
        g = _green(cc)
        b = _blue(cc)

        if r > 100 then
            pset (xx, yy), _rgb(r ,g - 3*yy - 50*sin(xx/20),b)
        end if

    next
    next

  _source 0

    _Dest 0

    ' Convert angles to radians
    Dim ax!, ay!, az!
    ax! = rotX! * _Pi / 180
    ay! = rotY! * _Pi / 180
    az! = rotZ! * _Pi / 180

    ' Precompute sin/cos
    Dim cx!, sx!, cy!, sy!, cz!, sz!
    cx! = Cos(ax!): sx! = Sin(ax!)
    cy! = Cos(ay!): sy! = Sin(ay!)
    cz! = Cos(az!): sz! = Sin(az!)

    ' Quad centered at origin (unscaled)
    Dim p(3, 2)
    p(0, 0) = -w% / 2: p(0, 1) = -h% / 2: p(0, 2) = 0 ' TL
    p(1, 0) = w% / 2: p(1, 1) = -h% / 2: p(1, 2) = 0 ' TR
    p(2, 0) = -w% / 2: p(2, 1) = h% / 2: p(2, 2) = 0 ' BL
    p(3, 0) = w% / 2: p(3, 1) = h% / 2: p(3, 2) = 0 ' BR

    Dim vx!, vy!, vz!
    Dim rx!, ry!, rz!
    Dim px!(3), py!(3)

    ' Rotate and scale quad
    For i% = 0 To 3
        vx! = p(i%, 0) * scale!
        vy! = p(i%, 1) * scale!
        vz! = p(i%, 2) * scale!

        ' Rotate around X
        ry! = vy! * cx! - vz! * sx!
        rz! = vy! * sx! + vz! * cx!
        vy! = ry!: vz! = rz!

        ' Rotate around Y
        rx! = vx! * cy! + vz! * sy!
        rz! = -vx! * sy! + vz! * cy!
        vx! = rx!: vz! = rz!

        ' Rotate around Z
        rx! = vx! * cz! - vy! * sz!
        ry! = vx! * sz! + vy! * cz!
        vx! = rx!: vy! = ry!

        px!(i%) = vx!
        py!(i%) = vy!
    Next

    ' Recenter quad to (x!, y!)
    Dim cx2!, cy2!
    cx2! = (px!(0) + px!(1) + px!(2) + px!(3)) / 4
    cy2! = (py!(0) + py!(1) + py!(2) + py!(3)) / 4

    Dim shiftX!, shiftY!
    shiftX! = x! - cx2!
    shiftY! = y! - cy2!

    For i% = 0 To 3
        px!(i%) = px!(i%) + shiftX!
        py!(i%) = py!(i%) + shiftY!
    Next

    ' Normalize extrusion direction
    Dim mag!
    mag! = Sqr(dirX! * dirX! + dirY! * dirY!)
    If mag! = 0 Then dirX! = 1: dirY! = 1: mag! = Sqr(2)
    dirX! = dirX! / mag!
    dirY! = dirY! / mag!

    ' Draw extrusion (per-pixel depth)

    For i% = depth% To 1 Step -1
        Dim ex!, ey!
        ex! = dirX! * i%
        ey! = dirY! * i%

        ' Triangle 1
      _MAPTRIANGLE (0, 0)-(w%, 0)-(0, h%), img& TO _
                    (px!(0) + ex!, py!(0) + ey!)- _
                    (px!(1) + ex!, py!(1) + ey!)- _
                    (px!(2) + ex!, py!(2) + ey!)

      ' Triangle 2
      _MAPTRIANGLE (0, h%)-(w%, 0)-(w%, h%), img& TO _
                    (px!(2) + ex!, py!(2) + ey!)- _
                    (px!(1) + ex!, py!(1) + ey!)- _
                    (px!(3) + ex!, py!(3) + ey!)
    Next

    ' Draw front face
    '_MAPTRIANGLE (0, 0)-(w%, 0)-(0, h%), img& TO _
    '            (px!(0), py!(0))-(px!(1), py!(1))-(px!(2), py!(2))

    '_MAPTRIANGLE (0, h%)-(w%, 0)-(w%, h%), img& TO _
    '            (px!(2), py!(2))-(px!(1), py!(1))-(px!(3), py!(3))

    _FreeImage img&
End Sub
Reply


Messages In This Thread
3D Text - by SMcNeill - 01-29-2026, 02:56 AM
RE: 3D Text - by SMcNeill - 01-29-2026, 04:23 AM
RE: 3D Text - by vince - 01-29-2026, 04:49 AM
RE: 3D Text - by SMcNeill - 01-29-2026, 01:09 PM
RE: 3D Text - by Dav - 01-29-2026, 01:23 PM
RE: 3D Text - by Petr - 01-29-2026, 04:57 PM
RE: 3D Text - by Unseen Machine - 01-29-2026, 08:14 PM
RE: 3D Text - by Petr - 01-29-2026, 08:47 PM
RE: 3D Text - by grymmjack - 01-31-2026, 04:12 PM
RE: 3D Text - by Petr - 01-31-2026, 04:33 PM
RE: 3D Text - by grymmjack - 02-01-2026, 04:47 PM
RE: 3D Text - by Petr - 02-04-2026, 06:12 PM
RE: 3D Text - by grymmjack - 02-09-2026, 10:09 PM
RE: 3D Text - by Unseen Machine - 02-10-2026, 08:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Text Previewer (windows only) SMcNeill 14 2,370 03-25-2024, 02:34 PM
Last Post: SMcNeill
  Minimal Text Animator James D Jarvis 5 1,089 09-16-2022, 07:12 PM
Last Post: James D Jarvis

Forum Jump:


Users browsing this thread: 1 Guest(s)