[bb] SaveTGA by skidracer [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:38

Previous topic - Next topic

BlitzBot

Title : SaveTGA
Author : skidracer
Posted : 1+ years ago

Description : This function saves a Blitz3D texture in TGA format, writing both rgb and alpha components of the texture.

Code :
Code (blitzbasic) Select
Function SaveTGA(name$,texture)
    Local f,width,height,tbuffer,x,y
    width=TextureWidth(texture)
    height=TextureHeight(texture)
    f=WriteFile(name$)
    WriteByte(f,0) ;idlength
    WriteByte(f,0) ;colormaptype
    WriteByte(f,2) ;imagetype 2=rgb
    WriteShort(f,0) ;colormapindex
    WriteShort(f,0) ;colormapnumentries
    WriteByte(f,0) ;colormapsize
    WriteShort(f,0) ;xorigin
    WriteShort(f,0) ;yorigin
    WriteShort(f,width) ;width
    WriteShort(f,height) ;height
    WriteByte(f,32) ;pixsize
    WriteByte(f,8) ;attributes
    tbuffer=TextureBuffer(texture)
    For y=height-1 To 0 Step -1
        For x=0 To width-1
            WriteInt f,ReadPixel(x,y,tbuffer)
        Next
    Next
    CloseFile f
End Function


Comments :


simonh(Posted 1+ years ago)

 Great work Skid!!