OK, I've worked it out. Proger was getting the ix,iy,jx,jy values himself in the DrawTexturedPolyOGL function, but he made them ints so they were getting rounded down to the nearest whole number, and hence not working right when you've change the scale or rotation.
Here's the fixed thing:
and an example (you'll need an image called fatgiraffe.jpg, I recommend this one)
If anyone can tell me why I need to scale everything by 1.28 to get it to match up with the rect and polygon, I'd be grateful.
Here's the fixed thing:
Function DrawTexturedPolyOGL (Driver:TGLMax2DDriver, Frame:TGLImageFrame, xy#[],handle_x#,handle_y#,origin_x#,origin_y#, vertex) Private Global TmpImage:TImage Public If xy.length<6 Return Local rot# = GetRotation() Local tform_scale_x#, tform_scale_y# GetScale tform_scale_x, tform_scale_y Local s#=Sin(rot) Local c#=Cos(rot) Const scale#=1.28 Local ix#= c*tform_scale_x*scale Local iy#= -s*tform_scale_y*scale Local jx#= s*tform_scale_x*scale Local jy#= c*tform_scale_y*scale glBindTexture GL_TEXTURE_2D, Frame.name glEnable GL_TEXTURE_2D glBegin GL_POLYGON For Local i=0 Until Len xy Step 4 If vertex > -1 And i >= vertex Then Exit Local x#=xy[i+0]+handle_x Local y#=xy[i+1]+handle_y Local u#=xy[i+2] Local v#=xy[i+3] glTexCoord2f u,v glVertex2f x*ix+y*iy+origin_x,x*jx+y*jy+origin_y Next glEnd If Not tmpImage Then tmpImage = CreateImage(1,1) DrawImage tmpImage, -100, - 100 ' Chtob zbit' flag texturi End Function
and an example (you'll need an image called fatgiraffe.jpg, I recommend this one)
Graphics 640,480,0 img:timage=LoadImage("fatgiraffe.jpg") While Not KeyHit(KEY_ESCAPE) mx=MouseX()-320 my=MouseY()-240 d#=Sqr(mx*mx+my*my)*.01 an#=ATan2(my,mx) SetScale 1,1 SetRotation 0 DrawText "scale = "+String(d),0,0 DrawText "rotation = "+String(an),0,15 SetRotation an SetScale d,d Local ix#, iy#, jx#, jy# GetTransformVars( ix, iy, jx, jy ) 'draw a rectangle SetOrigin 200,240 DrawRect 0,0,100,100 'draw a normal polygon in the shape of a rectangle SetOrigin 400,240 Local poly2#[8] poly2=[ 0.0,0.0, 100.0,0.0, 100.0,100.0, 0.0,100.0 ] DrawPoly poly2 'draw a textured polygon in the shape of a rectangle SetOrigin 320,240 Local poly#[16] poly=[ 0.0,0.0,0.0,0.0, 100.0,0.0,1.0,0.0, 100.0,100.0,1.0,1.0, 0.0,100.0,0.0,1.0 ] drawtexturedpoly( img, poly ) SetOrigin 0,0 SetScale 1,1 SetRotation 0 DrawText "ix = "+String(ix),0,60 DrawText "iy = "+String(iy),0,75 DrawText "jx = "+String(jx),0,90 DrawText "jy = "+String(jy),0,105 Flip Cls Wend
If anyone can tell me why I need to scale everything by 1.28 to get it to match up with the rect and polygon, I'd be grateful.