Thread: Custom File Types

  1. #1
    Registered User Misled Hacker's Avatar
    Join Date
    Oct 2002
    Posts
    6

    Custom File Types

    How do I create custom file types (eg: **.tpw)

  2. #2
    TOO LITTLE INFORMATION, problem is unsolvable.....

    neeeeeed more info........
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  3. #3
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    I get what you mean. Basically, you can use any format in your file, and then give it an extension, finally register the extension with your program.

  4. #4
    Registered User Misled Hacker's Avatar
    Join Date
    Oct 2002
    Posts
    6
    How would I create the file format and register it with my program.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Lets say you wanted to make a graphics file format for use in your game. You want to call it *.fmt. So all you do is make the file like normal ( using file streams ) then just write to it in a pre-determined format. For instance you might have your format like this. ( kind of like bitmap )

    --------------------
    IDENTIFIER ( First 2 bytes special so you can tell if this is your file format! )
    INFO HEADER ( description about image )
    PALETTE ( if applicable )
    PIXEL DATA ( all the pixel info )
    --------------------

    Your identifier can be any length. 2 Bytes is usually good though. Just pick any 2 characters you want to associate with your type. Bitmap uses BM. That way if you read a file and it doesn't have your 2 byte identifier you know it is NOT valid.

    Your header keeps information about the image. You want to store height, width, bits per pixel, compression schemes, number of bytes until pixel data, etc. Look up BITMAPFILEHEADER and BITMAPINFOHEADER for my ideas.

    The palette is for low color count images. You can read more about them later or diregard them entirely if you want to use 16, 24, 32bpp.

    Finally comes the actual pixel data. Remember this is stored in Little Endian format on Intel processors so it would be BGR instead of RGB for the component colors.


    This is just an arbitrary file format based off of bitmap. You can easily see how you could write your own format for levels, scripts or anything! Have Fun!
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  6. #6
    Registered User Misled Hacker's Avatar
    Join Date
    Oct 2002
    Posts
    6
    ok i got that but lets say i wanted my own save file for the players that stores their sava data how would i do that.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You would just need to write out their information to the file. Just remember in what order you write them to and then read them in when loading. If you understand C/C++ like you claim, file I/O should be no match for you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM