Texture database

I am making a game in delphi, and now i want to have a big file with all textures in it....

I want to load (stream) a specified texture to a TImage, with some options (that are NOT defind in TImage)

How can I make a database that hold textures ???

Greetingzz NecroDOME

(srry 4 my bad engisch)

Comments

  • : I am making a game in delphi, and now i want to have a big file with all textures in it....
    :
    : I want to load (stream) a specified texture to a TImage, with some options (that are NOT defind in TImage)
    :
    : How can I make a database that hold textures ???
    :
    : Greetingzz NecroDOME
    :
    : (srry 4 my bad engisch)
    :
    I would use the following:

    First you start with the size of the texture and all additional data
    Then comes the texture itself
    Finally the additional data

    The read part is then quite simple: the size of the size is fixed (for example 2 integers will do). Based on that you read the texture (1st integer of the size). Then follows the additional data (again you know the size). This process you can repeat for until the end of file.
    Writing is similar, since you obviously know the sizes before writing all the data.
    This is quite a flexible method of reading an entire stream of textures, although searching it will take some time, since you need to look from the beginning. If you need to quickly access the indexth texture, I would suggest that you index the entire file during the initialization of the game. Then you know the position of each texture, and can use the Position property to get it.
  • Thnxz, Buy how do I save the file...?

    It could by a JPG, BMP or a DIB image, and I don't want so change the format... :S

    I know I need to work with FileStream...

    What would the code look like for loading and saving ???

  • : Thnxz, Buy how do I save the file...?
    :
    : It could by a JPG, BMP or a DIB image, and I don't want so change the format... :S
    :
    : I know I need to work with FileStream...
    :
    : What would the code look like for loading and saving ???
    :
    :
    Then you switch the image data and the additional data, and add the image type to the additional data. That way you know the type before reading it and can use the SaveToStream/LoadFromStream of the correct graphic object. Here is a simple sample code:
    [code]
    with TextureFile do
    begin
    Read(ImageSize, SizeOf(ImageSize));
    Read(DataSize, SizeOf(DataSize));
    Read(AddData, DataSize);
    case AddData.GraphicType of
    gtBitmap: Image1.Picture.Bitmap.LoadFromSteam(TextureFile);
    ...
    end;
    end;
    [/code]
    This code loads a single texture and its data. I haven't declared any of the variables or constants, but you should be able to handle that. In this case the AddData is a record.
    Saving is similar, but instead of read/load you need to use write/save. The hardest part of this kind of structures is to keep the overview of the entire structure and at the same time keep an eye for the details.
  • THnxz again :D

    1 more question....

    can you give me a sample code of saving the file (i never done something with TFileSteam.....


    thnxz in advance :D

    : : Thnxz, Buy how do I save the file...?
    : :
    : : It could by a JPG, BMP or a DIB image, and I don't want so change the format... :S
    : :
    : : I know I need to work with FileStream...
    : :
    : : What would the code look like for loading and saving ???
    : :
    : :
    : Then you switch the image data and the additional data, and add the image type to the additional data. That way you know the type before reading it and can use the SaveToStream/LoadFromStream of the correct graphic object. Here is a simple sample code:
    : [code]
    : with TextureFile do
    : begin
    : Read(ImageSize, SizeOf(ImageSize));
    : Read(DataSize, SizeOf(DataSize));
    : Read(AddData, DataSize);
    : case AddData.GraphicType of
    : gtBitmap: Image1.Picture.Bitmap.LoadFromSteam(TextureFile);
    : ...
    : end;
    : end;
    : [/code]
    : This code loads a single texture and its data. I haven't declared any of the variables or constants, but you should be able to handle that. In this case the AddData is a record.
    : Saving is similar, but instead of read/load you need to use write/save. The hardest part of this kind of structures is to keep the overview of the entire structure and at the same time keep an eye for the details.
    :

  • : THnxz again :D
    :
    : 1 more question....
    :
    : can you give me a sample code of saving the file (i never done something with TFileSteam.....
    :
    :
    : thnxz in advance :D
    :
    : : : Thnxz, Buy how do I save the file...?
    : : :
    : : : It could by a JPG, BMP or a DIB image, and I don't want so change the format... :S
    : : :
    : : : I know I need to work with FileStream...
    : : :
    : : : What would the code look like for loading and saving ???
    : : :
    : : :
    : : Then you switch the image data and the additional data, and add the image type to the additional data. That way you know the type before reading it and can use the SaveToStream/LoadFromStream of the correct graphic object. Here is a simple sample code:
    : : [code]
    : : with TextureFile do
    : : begin
    : : Read(ImageSize, SizeOf(ImageSize));
    : : Read(DataSize, SizeOf(DataSize));
    : : Read(AddData, DataSize);
    : : case AddData.GraphicType of
    : : gtBitmap: Image1.Picture.Bitmap.LoadFromSteam(TextureFile);
    : : ...
    : : end;
    : : end;
    : : [/code]
    : : This code loads a single texture and its data. I haven't declared any of the variables or constants, but you should be able to handle that. In this case the AddData is a record.
    : : Saving is similar, but instead of read/load you need to use write/save. The hardest part of this kind of structures is to keep the overview of the entire structure and at the same time keep an eye for the details.
    : :
    :
    Here's the example:
    : : [code]
    // Fill the ImageSize, DataSize and AddData
    : : with TextureFile do
    : : begin
    : : Write(ImageSize, SizeOf(ImageSize));
    : : Write(DataSize, SizeOf(DataSize));
    : : Write(AddData, DataSize);
    : : case AddData.GraphicType of
    : : gtBitmap: Image1.Picture.Bitmap.SaveToSteam(TextureFile);
    : : ...
    : : end;
    : : end;
    : : [/code]
    I don't have Delphi here, so I cannot find how to get the size of a Graphic in bytes, but you might be able to find it in the help files (or create a test project to figure it out). The size of the AddData is quite easy to figure out, since you are the designer of that variable type.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories