DDS question

Blitz3D Forums/Blitz3D Programming/DDS question

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.

i remembered this post by fredborg so went to find it. The thread is here:
http://www.blitzbasic.com/Community/posts.php?topic=61874

I think the SwitchToDDS function changes all extension names in a file to ".dds".

Also, cfx is old and unsupported i think.
ultimateunwrap3d supports dds, maybe fragmotion too not sure.

;SwitchToDDS, by fredborg

SwitchToDDS("RomanBath.b3d")
Print "Finito!"
WaitKey()
End

Function SwitchToDDS(file$)

	Local extmatch$[3]
	
	extmatch[0] = ".png"
	extmatch[1] = ".jpg"
	extmatch[2] = ".bmp"
	extmatch[3] = ".tga"

	dds = Asc(".") + (Asc("d") Shl 8) + (Asc("d") Shl 16) + (Asc("s") Shl 24)
	dot = Asc(".")

	count = 0
	
	f = ReadFile(file)
	If f
		
		ms = MilliSecs()
				
		bank = CreateBank(FileSize(file))
		ReadBytes(bank,f,0,BankSize(bank))
		CloseFile f

		For i = 0 To BankSize(bank)-5
			If PeekByte(bank,i) = dot
				a$ = Lower(Chr(PeekByte(bank,i)) + Chr(PeekByte(bank,i+1)) + Chr(PeekByte(bank,i+2)) + Chr(PeekByte(bank,i+3)))
				For j = 0 To 3
					If a = extmatch[j]
						PokeInt bank,i,dds
						count = count + 1
					EndIf
				Next
			EndIf
		Next

		DebugLog "SwitchToDDS("+Chr(34)+file+Chr(34)+")"
		If count = 0
			DebugLog "  No matches found"
		Else
			ext$ = Right(file,Len(file)-Instr(file,"."))
		
			f = WriteFile( Left(file$,Instr(file,".")-1)+"_dds."+ext )
			If f
				WriteBytes(bank,f,0,BankSize(bank))
				CloseFile f
			EndIf
		
			DebugLog "  Replaced "+count+" texture extensions"
		EndIf

		ms = MilliSecs() - ms
		DebugLog "  Finished in "+ms+"ms" 

	EndIf

End Function