Drawimage with vertex colours

BlitzMax Forums/BlitzMax Programming/Drawimage with vertex colours

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Thanks again for your help Michael. I`ve almost completed the function but there's still a couple of issues that are puzzling me.

When I set the U or V coordinate I assumed a value of 1.0 would give me the furthest right & bottom edges of the loaded image. Instead, after a lot of blind number changes, I`m having to put in 0.72 for U and 0.585 for V? Any idea what this magic numbers relate to?

Second problem is the rotation of the image. If you run the below code you'll notice my coloured image is rotated the same as the DrawImage version except it's offset? Any idea why this is happening?

Strict
Graphics 640,480
SetClsColor 100,100,100
Cls

Local Image:TImage = LoadImage("Dizzy.png", MASKEDIMAGE)

Local ColA:Int[] = [255,255,192,0]
Local ColB:Int[] = [255,255,0,0]
Local ColC:Int[] = [255,0,0,128]
Local ColD:Int[] = [255,0,0,128]
Local XPos#=100
Local YPos#=50


SetRotation 45
SetBlend AlphaBlend
SetScale 2,2
SetAlpha 1.0

DrawImage Image,XPos,YPos
DrawColImage Image, XPos, YPos, ColA, ColB, ColC, ColD

Flip
WaitKey


'----------------------------------------------------------------------------------------------------
' DrawColImage <IMG>, XPos#, YPos#, ColA[], ColB[], ColC[], ColD[], Frame%
'----------------------------------------------------------------------------------------------------

Function DrawColImage( image:TImage,Xp, Yp, ClrA[], ClrB[], ClrC[], ClrD[], frame=0)

Local handle_x#, handle_y#
GetHandle handle_x#, handle_y#
Local tx#, ty#
GetOrigin tx#, ty#

Local Alph#=GetAlpha()
ClrA[0]=ClrA[0]*Alph
ClrB[0]=ClrB[0]*Alph
ClrC[0]=ClrC[0]*Alph
ClrD[0]=ClrD[0]*Alph

Local Driver:TD3D7Max2DDriver = TD3D7Max2DDriver(_max2dDriver)

Assert Image, "Image not found"

Local uv#[24]
Local ImgWidth#=Image.width
Local ImgHeight#=Image.Height
Local x#=Xp+Handle_X#
Local Y#=Yp+Handle_Y#

Local LeftX#=x
Local RightX#=x+ImgWidth#
Local UpY#=y
Local DownY#=y+ImgHeight#

Local c:Int Ptr=Int Ptr(Float Ptr(uv))

uv[0]=LeftX#*Driver.ix+UpY*Driver.iy+tx '--X POS
uv[1]=LeftX#*Driver.jx+UpY*Driver.jy+ty '--Y POS
uv[2]=0 '--Z POS
c[3]= ClrA[0] Shl 24 | ClrA[1] Shl 16 | ClrA[2] Shl 8 | ClrA[3] '--ARGB COLORS
uv[4]= 0.0 ; uv[5]= 0.0 '--UV COORDS

uv[6]=RightX#*Driver.ix+UpY*Driver.iy+tx
uv[7]=RightX#*Driver.jx+UpY*Driver.jy+ty
uv[8]=0
c[9]= ClrB[0] Shl 24 | ClrB[1] Shl 16 | ClrB[2] Shl 8 | ClrB[3]
uv[10]= .72 ; uv[11]= 0.0

uv[12]=RightX#*Driver.ix+DownY*Driver.iy+tx
uv[13]=RightX#*Driver.jx+DownY*Driver.jy+ty
uv[14]=0
c[15]= ClrC[0] Shl 24 | ClrC[1] Shl 16 | ClrC[2] Shl 8 | ClrC[3]
uv[16]= .72 ; uv[17]= .585

uv[18]=LeftX#*Driver.ix+DownY*Driver.iy+tx
uv[19]=LeftX#*Driver.jx+DownY*Driver.jy+ty
uv[20]=0
c[21]= ClrD[0] Shl 24 | ClrD[1] Shl 16 | ClrD[2] Shl 8 | ClrD[3]
uv[22]= 0.0 ; uv[23]= .585

Driver.SetActiveFrame TD3D7ImageFrame(image.Frame(frame))
Driver.device.DrawPrimitive(D3DPT_TRIANGLEFAN,D3DFVF_XYZ| D3DFVF_DIFFUSE | D3DFVF_TEX1,uv,4,0)

End Function



Thanks for your help,
andy

p.s. how do you embed code into a code box?