Here have this one on the house. It's based on code by Yan so I can't take all the credit and it isn't perfect, but it should be enough to get you started.
SuperStrict
Function FourPointRender(image:TImage, srcx:Float, srcy:Float, srcwidth:Float, srcheight:Float, dx1:Float, dy1:Float, dx2:Float, dy2:Float, dx3:Float, dy3:Float, dx4:Float, dy4:Float )
Local frame:Int=0, fan:Int=1
Local textureWidthRatio! = Double(image.width) / Pow2Size(image.width)
Local textureHeightRatio! = Double(image.height) / Pow2Size(image.height)
Local hx#, hy#, ox#, oy#
srcx:/Double(image.width)
srcy:/Double(image.height)
srcwidth:/Double(image.width)
srcheight:/Double(image.height)
Local xyuv:Float[]=[(dx1+dx2+dx3+dx4)*.25,(dy1+dy2+dy3+dy4)*.25,.5,.5,dx1,dy1,srcx,srcy,dx2,dy2,srcx+srcwidth,srcy,dx4,dy4,srcx+srcwidth,srcy+srcheight,dx3,dy3,srcx,srcy+srcheight,dx1,dy1,srcx,srcy]
GetHandle(hx#, hy#)
GetOrigin(ox#, oy#)
?Win32
Local DXDriver:TD3D7Max2DDriver = TD3D7Max2DDriver(_max2dDriver)
If DXDriver
'DX
Local verts#[(xyuv#.length / 4) * 6]
Local vCount:Int
For Local c:Int=0 Until xyuv#.length Step 4
verts#[vCount] = ((xyuv#[c] - hx#) * DXDriver.ix#) + ((xyuv#[c + 1] - hy#) * DXDriver.iy#) + ox#
verts#[vCount + 1] = ((xyuv#[c] - hx#) * DXDriver.jx#) + ((xyuv#[c + 1] - hy#) * DXDriver.jy#) + oy#
verts#[vCount + 2] = 0
(Int Ptr(Float Ptr(verts#)))[vCount + 3] = DXDriver.drawcolor
verts#[vCount + 4] = xyuv#[c + 2] * textureWidthRatio!
verts#[vCount + 5] = xyuv#[c + 3] * textureHeightRatio!
vCount :+ 6
Next
DXDriver.SetActiveFrame(TD3D7ImageFrame(image.Frame(frame)))
If fan
DXDriver.device.DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1, verts#, xyuv#.length / 4, 0)
Else
DXDriver.device.DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1, verts#, xyuv#.length / 4, 0)
EndIf
Else
?
'GL
'Can't get at GLMax2D's transform info, so...
Local sx#, sy#
GetScale(sx#, sy#)
glPushMatrix()
glBindTexture(GL_TEXTURE_2D, TGLImageFrame(image.Frame(frame)).name)
glEnable(GL_TEXTURE_2D)
glTranslatef(ox#, oy#, 0.0)
glRotatef(GetRotation(), 0.0, 0.0, 1.0)
glScalef(sx#, sy#, 1.0)
If fan Then glBegin(GL_POLYGON) Else glBegin(GL_TRIANGLE_STRIP)
For Local c:Int=0 Until xyuv#.length Step 4
glTexCoord2f(xyuv#[c + 2] * textureWidthRatio!, xyuv#[c + 3] * textureHeightRatio!)
glVertex2f(xyuv#[c] - hx#, xyuv#[c + 1] - hy#)
Next
glEnd
glDisable(GL_TEXTURE_2D)
glPopMatrix()
?Win32
EndIf
?
Function Pow2Size:Int(n:Int)
Local t:Int = 1
While t < n
t :* 2
Wend
Return t
End Function
End Function
Graphics 800,600
Global img:TImage=LoadImage("bmax128.png")
Global x:Double[]=[Rnd(200,400),Rnd(400,600),Rnd(200,400),Rnd(400,600)]
Global y:Double[]=[Rnd(200,400),Rnd(200,400),Rnd(400,600),Rnd(400,600)]
Repeat
Local mx:Int=MouseX()
Local my:Int=MouseY()
Local near:Float=800*800
Local marker:Int=0
For Local count:Int=0 To 3
Local dist:Float=(mx-x[count])*(mx-x[count])+(my-y[count])*(my-y[count])
If dist<near
near=dist
marker=count
EndIf
Next
If MouseDown(1)
x[marker]=mx
y[marker]=my
EndIf
Cls
DrawText "Source image",0,0
DrawImage img,15,15
DrawText "Result image: Use LMB to move vertices",200,0
FourPointRender img,0,0,128,128,x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]
For Local count:Int=0 To 3
DrawRect x[count]-2,y[count]-2,5,5
Next
Flip
Until KeyHit(KEY_ESCAPE)
You need to supply your own image. I used the one that is in the help docs.
Personally though I'd just use Yan's code out-of-the-box as it's more versatile.
'DrawTexturedPoly code by Yan
Function DrawTexturedPoly(xyuv:Float[], image:TImage, frame:Int=0, fan:Int=1)
Local textureWidthRatio! = Double(image.width) / Pow2Size(image.width)
Local textureHeightRatio! = Double(image.height) / Pow2Size(image.height)
Local hx#, hy#, ox#, oy#
GetHandle(hx#, hy#)
GetOrigin(ox#, oy#)
?Win32
Local DXDriver:TD3D7Max2DDriver = TD3D7Max2DDriver(_max2dDriver)
If DXDriver
'DX
Local verts#[(xyuv#.length / 4) * 6]
Local vCount:Int
For Local c:Int=0 Until xyuv#.length Step 4
verts#[vCount] = ((xyuv#[c] - hx#) * DXDriver.ix#) + ((xyuv#[c + 1] - hy#) * DXDriver.iy#) + ox#
verts#[vCount + 1] = ((xyuv#[c] - hx#) * DXDriver.jx#) + ((xyuv#[c + 1] - hy#) * DXDriver.jy#) + oy#
verts#[vCount + 2] = 0
(Int Ptr(Float Ptr(verts#)))[vCount + 3] = DXDriver.drawcolor
verts#[vCount + 4] = xyuv#[c + 2] * textureWidthRatio!
verts#[vCount + 5] = xyuv#[c + 3] * textureHeightRatio!
vCount :+ 6
Next
DXDriver.SetActiveFrame(TD3D7ImageFrame(image.Frame(frame)))
If fan
DXDriver.device.DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1, verts#, xyuv#.length / 4, 0)
Else
DXDriver.device.DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1, verts#, xyuv#.length / 4, 0)
EndIf
Else
?
'GL
'Can't get at GLMax2D's transform info, so...
Local sx#, sy#
GetScale(sx#, sy#)
glPushMatrix()
glBindTexture(GL_TEXTURE_2D, TGLImageFrame(image.Frame(frame)).name)
glEnable(GL_TEXTURE_2D)
glTranslatef(ox#, oy#, 0.0)
glRotatef(GetRotation(), 0.0, 0.0, 1.0)
glScalef(sx#, sy#, 1.0)
If fan Then glBegin(GL_POLYGON) Else glBegin(GL_TRIANGLE_STRIP)
For Local c:Int=0 Until xyuv#.length Step 4
glTexCoord2f(xyuv#[c + 2] * textureWidthRatio!, xyuv#[c + 3] * textureHeightRatio!)
glVertex2f(xyuv#[c] - hx#, xyuv#[c + 1] - hy#)
Next
glEnd
glDisable(GL_TEXTURE_2D)
glPopMatrix()
?Win32
EndIf
?
Function Pow2Size:Int(n:Int)
Local t:Int = 1
While t < n
t :* 2
Wend
Return t
End Function
End Function