PDA

View Full Version : How to add images to VTD ?



Nightmare_82
26-09-2004, 08:35 PM
I want to add all images I use in my game to a VTD-File.
In PowerDraw3 I used the folloing:
m_oImageList.Image[strShortName].GetAGFData(p, iSize);
m_oVTD.WriteRecordEx(strShortName, p, iSize, recAGFImage);

In the new version I didnt find a funtion to do this. Can someone tell me a way how I can save the images ?
The problem is I use more than 50 images and it's too much work to add them manually with the VTD-Tool because I often change them.

LP
26-09-2004, 11:21 PM
I actually didn't think that this function was of any use - that's why it's missing in the new version (I'll try to add it though - final release is coming soon, only Asphyre manual is incomplete and is under development right now).

Meanwhile, here's a rough example of adding gfx to VTDb manually:


procedure AddNewImageToVTDb();
var
PatternSize,
InPSize, OutPSize,
TextureSize: TPoint;
PInRow, PInCol,
ImgInRow, ImgInCol, ImgInTex,
TextureCount, PatternCount,
Res, i: Integer;

Bitmap,
FinalBmp: TBitmapEx;

Stream: TStream;
Data: Pointer;
DataSize: Cardinal;
OutFormat: TColorBits;
begin
// 1. load graphics files
Bitmap:= TBitmapEx.Create();
FinalBmp:= TBItmapEx.Create();
FinalBmp.PixelFormat:= pf32bit;
try
Bitmap.LoadFromFile('Source Bitmap.bmp', btAuto);
except
Bitmap.Free();
MessageDlg('Error loading gfx files!', mtError, [mbOk], 0);
Exit;
end;

// 2. calculate pattern count and patterns per line
PInRow:= Bitmap.Width div InPSize.X;
PInCol:= Bitmap.Height div InPSize.Y;
PatternCount:= PInRow * PInCol;

// 3. calculate image counts in destionation
ImgInRow:= TextureSize.X div OutPSize.X;
ImgInCol:= TextureSize.Y div OutPSize.Y;
ImgInTex:= ImgInRow * ImgInCol;
TextureCount:= Ceil(PatternCount / ImgInTex);

// 4. create destination memory stream
Stream:= TMemoryStream.Create();

// 5. write gfx info
Stream.Write(OutFormat, SizeOf(TColorBits));
Stream.Write(OutPSize, SizeOf(TPoint));
Stream.Write(PatternSize, SizeOf(TPoint));
Stream.Write(PatternCount, SizeOf(Integer));
Stream.Write(TextureSize, SizeOf(TPoint));
Stream.Write(TextureCount, SizeOf(Integer));

// 6. tile patterns
Bitmap.TileOnBmp(FinalBmp, nil, TextureSize, InPSize, OutPSize, PatternSize, taSource, 0, 0);

// 7. allocate memory for stream write
DataSize:= TextureSize.X * ColorFmtBytes(OutFormat);
Data:= AllocMem(DataSize);

// 8. stream data
for i:= 0 to FinalBmp.Height - 1 do
begin
AsphyreSys.LineConv(FinalBmp.ScanLine[i], Data, TextureSize.X, COLOR_A8R8G8B8, OutFormat);
Stream.Write(Data^, DataSize);
end;

// 9. release the memory and the bitmaps
FreeMem(Data);
Bitmap.Free();
FinalBmp.Free();

// 10. write encoded data to VTDb
Stream.Seek(0, soFromBeginning);
Res:= VTDb.WriteStream('VTDb Record Key', Stream, recGraphics);
if (Res <> errNone) then
MessageDlg('VTDb error: ' + ErrorString(Res), mtError, [mbOk], 0);

// 11. release the stream
Stream.Free();
end;


This code contains few parts from VTDbTool sources. It basically shows the structure "recGraphics" record uses to illustrate how to add images to VTDb manually.

Nightmare_82
27-09-2004, 06:26 AM
Thank you very much !
Now the whole engine works and it's very fast! Good work, Lifepower!