November 24, 2020, 06:45:10 AM

Author Topic: [bb] SaveTGA by skidracer [ 1+ years ago ]  (Read 744 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] SaveTGA by skidracer [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
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
  1. Function SaveTGA(name$,texture)
  2.     Local f,width,height,tbuffer,x,y
  3.     width=TextureWidth(texture)
  4.     height=TextureHeight(texture)
  5.     f=WriteFile(name$)
  6.     WriteByte(f,0) ;idlength
  7.     WriteByte(f,0) ;colormaptype
  8.     WriteByte(f,2) ;imagetype 2=rgb
  9.     WriteShort(f,0) ;colormapindex
  10.     WriteShort(f,0) ;colormapnumentries
  11.     WriteByte(f,0) ;colormapsize
  12.     WriteShort(f,0) ;xorigin
  13.     WriteShort(f,0) ;yorigin
  14.     WriteShort(f,width) ;width
  15.     WriteShort(f,height) ;height
  16.     WriteByte(f,32) ;pixsize
  17.     WriteByte(f,8) ;attributes
  18.     tbuffer=TextureBuffer(texture)
  19.     For y=height-1 To 0 Step -1
  20.         For x=0 To width-1
  21.             WriteInt f,ReadPixel(x,y,tbuffer)
  22.         Next
  23.     Next
  24.     CloseFile f
  25. End Function
  26.  


Comments :


simonh(Posted 1+ years ago)

 Great work Skid!!


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal