The Game Texture Loader

Started by
31 comments, last by Rob Loach 18 years, 3 months ago
I've made one image library too; it loads BMP, CEL, RGB (SGI), TGA, JPG, PPM, PSD, DDS (Direct X) and some more (JPG is supported through jpeglib); called Biturn bitmap library, and it was programmed for easy use with OpenGl and such ... can convert image to different pixel depths too. Called Biturn Bitmap lib, only bad thing is that its not tested much and currently its compiled only for win32. Here: http://mirex.mypage.sk/FILES/bbl_041117.rar
Advertisement
Hi all,

I've read all the replies to phantom's post. I guess the question of re-inventing the wheel is pretty generic. Sometimes I'll just wanna write some coz I simply want to learn the ups and downs of writing it, gaining the maximum experience compared to pure reading and learning.

I initially intended to write my own image loader as well (not to reinvent the wheel, but to do it as an exercise). But seeing all the juice that different free sources can provide, I'm rather tempted to just pick one and use it.

Even if i should pick one... I'll pick the one with a straight-forward, understandable methods and easy-to-use method calls. I guess this is where GTL could be useful..

:P

Back to the point of reinventing the wheel ... I guess it's all up to individual desires and its limits. For eg, I may be willing to write a game engine's event handlers but I'll leave the loading of bitmaps to GDI's LoadImage() ... I guess it's a different focus for everyone :P

You'll never see heaven if you haven't been through hell.
I just checked out the GTL CVS and it seems that you didn't include GameTextureLoader.cpp in /src. Might be missing some other stuff in /src/internals as well.

Although I have no way to test it out, here is the beginnings to Game Texture Loader bindings for .NET:

#region License/* Copyright (c)2006  Rob Loach  All rights reserved.  This software is provided 'as-is', without any express or implied warranty.  In no event will the authors be held liable for any damages arising from the use of this software.  Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:  1. The origin of this software must not be misrepresented; you must not    claim that you wrote the original software. If you use this software    in a product, an acknowledgment in the product documentation would be    a ppreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be    misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution.*/#endregion Licenseusing System;using System.Runtime.InteropServices;using System.Security;namespace GtlDotNet{	/// <summary>	/// The Game Texture Loader bindings for .NET, implementing GTL Beta 1-1 (Dec 05)	/// </summary>	/// <remarks>The Game Texture Loader is very much just as it says, a library for loading texture formats commonly used in games.</remarks>	[SuppressUnmanagedCodeSecurityAttribute()]	public sealed class Gtl	{		#region Constants		/// <summary>		/// GTL's native library archive.		/// </summary>		private const string GTL_NATIVE_LIBRARY = "gametextureloader";		/// <summary>		/// Specifies the calling convention.		/// </summary>		private const CallingConvention CALLING_CONVENTION = CallingConvention.Cdecl;		#endregion Constants		#region Constructors		/// <summary>		/// Private constructor - disallows instantiation		/// </summary>		private Gtl()		{		}		#endregion Constructors		#region Public Functions		/// <summary>		/// Loads a texture from the given filename. The GTL will use the file extension (everything after the final . (dot) in the file name) to select the loader.		/// </summary>		/// <param name="filename"></param>		/// <returns>A struct which contains read online formation about the image and a pointer to the image data.</returns>		[DllImport(GTL_NATIVE_LIBRARY, CallingConvention=CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]		public static extern Image LoadTexture(string filename);		/// <summary>		/// Loads a texture from the given filename. The GTL will use the given FileType value to select the loader to use.		/// </summary>		/// <param name="filename"></param>		/// <param name="val"></param>		/// <returns>A struct which contains read online formation about the image and a pointer to the image data.</returns>		[DllImport(GTL_NATIVE_LIBRARY, CallingConvention=CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]		public static extern Image LoadTexture(string filename, FileTypes val);		/// <summary>		/// Loads a texture from the given PhysFS file handle using the specified type to select the loader to use.		/// </summary>		/// <param name="file"></param>		/// <param name="val"></param>		/// <returns>A struct which contains read online formation about the image and a pointer to the image data.</returns>		[DllImport(GTL_NATIVE_LIBRARY, CallingConvention=CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]		public static extern Image LoadTexture(IntPtr file, FileTypes val);		/// <summary>		/// Loads a texture from the given PhysFS file handle using the filename provided to work out what type the image is to select the loader to use.		/// </summary>		/// <param name="file"></param>		/// <param name="filename"></param>		/// <returns>A struct which contains read online formation about the image and a pointer to the image data.</returns>		[DllImport(GTL_NATIVE_LIBRARY, CallingConvention=CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]		public static extern Image LoadTexture(IntPtr file, string filename);		/// <summary>		/// Returns the width of the image at the given mipmap level		/// </summary>		/// <remarks>The image number isnt required as the library assumes all images have the same dimensions (true of DDS images)</remarks>		/// <param name="img"></param>		/// <param name="mipmaplvl"></param>		/// <returns>Width of the imageat the requested mipmap level</returns>		[DllImport(GTL_NATIVE_LIBRARY, CallingConvention=CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]		public static extern int getWidth(ref Image img, int mipmaplvl);		/// <summary>		/// Returns the height of the image at the given mipmap level		/// </summary>		/// <remarks>The image number isnt required as the library assumes all images have the same dimensions (true of DDS images)</remarks>		/// <param name="img"></param>		/// <param name="mipmaplvl"></param>		/// <returns>Height of the image at the requested mipmap level</returns>		[DllImport(GTL_NATIVE_LIBRARY, CallingConvention=CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]		public static extern int getHeight(ref Image img, int mipmaplvl);		/// <summary>		/// Retieves the depth of the image at the given mipmap level		/// </summary>		/// <remarks>The image number isnt required as the library assumes all images have the same dimensions (true of DDS images)		/// <p>2D images will return a depth of 1</p></remarks>		/// <param name="img"></param>		/// <param name="mipmaplvl"></param>		/// <returns>depth of the image at the requested mipmap level</returns>		[DllImport(GTL_NATIVE_LIBRARY, CallingConvention=CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]		public static extern int getDepth(ref Image img, int mipmaplvl);		/// <summary>		/// Retieves the size in bytes of the image at the given mipmap level		/// </summary>		/// <remarks>The image number isnt required as the library assumes all images have the same dimensions (true of DDS images)		/// <p>The function correctly works out the size for DXTn compressed data</p></remarks>		/// <param name="img"></param>		/// <param name="mipmaplvl"></param>		/// <returns>The size in bytes of the image at the given mipmap level</returns>		[DllImport(GTL_NATIVE_LIBRARY, CallingConvention=CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]		public static extern int getSize(ref Image img, int mipmaplvl);		/// <summary>		/// Returns a pointer to the start of the image data for the requested image and mipmap level of a given Image object.		/// </summary>		/// <remarks>This function doesnt to any checking as to the validity of the image number nor the mipmap level, this is left to the user</remarks>		/// <param name="img"></param>		/// <param name="imgnumber"></param>		/// <param name="mipmaplvl"></param>		/// <returns>A pointer to the start of the image data</returns>		[DllImport(GTL_NATIVE_LIBRARY, CallingConvention=CALLING_CONVENTION), SuppressUnmanagedCodeSecurity]		public static extern string getData(ref Image img, int imgnumber, int mipmaplvl);		#endregion Public Functions		#region Public Enums		#region ImgFormat		/// <summary>		/// Enums for image and file type identification		/// </summary>		public enum ImgFormat		{			FORMAT_NONE = 0,			FORMAT_RGB,			FORMAT_BGR,			FORMAT_RGBA,			FORMAT_BGRA,			FORMAT_ABGR,			FORMAT_DXT1,			FORMAT_DXT2,			FORMAT_DXT3,			FORMAT_DXT4,			FORMAT_DXT5,			FORMAT_3DC,		}		#endregion ImgFormat		#region FileTypes		/// <summary>		/// Used to tell the loader which file type you want to use. Also used internally in the registering of loaders on start up.		/// </summary>		public enum FileTypes		{			TYPE_BMP = 1,			TYPE_JPG,			TYPE_TGA,			TYPE_PNG,			TYPE_DDS,		}		#endregion FileTypes		#endregion Public Enums		#region Public Structs		#region Image		/// <summary>		/// This struct provides a way of wrapping all of the image infomation into one place		/// </summary>		[StructLayout(LayoutKind.Sequential, Pack=4)]		private struct Image		{			int height_;			int width_;			int depth_;			int colourdepth_;			ImgFormat format_;			int numImages_;			int numMipMaps_;			IntPtr imgdata_;		}		#endregion Image		#endregion Public Structs	}}
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement