• Advertisement
Sign in to follow this  

Unity The Game Texture Loader

This topic is 4390 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

On the license thing, well you could use the LGPL like that, I think a couple of libs have done and some dont care if you statically link anyways, however using zlib (which isnt really unknown, PHP uses it for example) makes it clear and the license text is about 10 lines at least, heh

So, I'll be sticking with zlib myself, but the fact that it is 'free free' means you dont have any restrictions on its usage.

The image format things will be basically as you say, it'll require a recompile to add/remove image loader code and #ifdef seem like the most likely way to handle it.

As for the SDL surface, well I could add it as part of the whole C-layer (remember, this is natively going to be a C++ library) so again consider it on the 'todo' list, as to if I do it or someone else will be another matter, but everything will be well documented so it shouldnt be a bother [smile]

Share this post


Link to post
Share on other sites
Advertisement
How about using a FreeImage Open Source project (http://freeimage.sourceforge.net)? It has more than enough texture formats as well as being portable to Linux, Windows and MacOS.

I use it and still have no complains.

Share this post


Link to post
Share on other sites
Aside from the interface the fact it decompressed DDS and appears to have no support for mipmaps and/or cubmap'd DDS images rules it out of the equation

*waves hand in the general direction of his journal for a slightly fleshed out version of the above*

Share this post


Link to post
Share on other sites
Looks pretty good. I'd like to check it out when you get it working. I am sure I could throw out what I have now and use yours. [grin]

Share this post


Link to post
Share on other sites
Ok, about one month ago i finished my texture manager for my projects
this piece of software loads bmp,pcx,tga,raw(sgi), jpeg nad png ( this 2 with the use of third part library ), its more than a loader , it handels everything a texture needs to have , and puts into a pool , where you can address the single textures with some invoking functions .
My deal is this i can give you the entire code for it for two reasons , first it would be a strong test 'rally ' for this library, second , software give waway for the community , to learn ( no pun intended ) , and to use without reinveniting the wheel , only enhance it.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 License

using 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
}

}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By 3dmodelerguy
      So I am building a turn based rogue-like (think CDDA). The game is going to have a very large map (up to 1000's x 1000's) however to alleviate most of that I obviously can't render everything so there will just be render a certain radius around the player and just load in and out data as the player moves.
      The next major system I am prototyping is making interactive tiles destructible and pretty much everything will be destructible besides basic landscape (cars, doors, windows, structures, etc. will be destructible)
      While I am only rendering a certain amount of tiles around the player, I want to keep the amount of colliders active at one time to be as small as possible for performance and currently the tilemap tool I use automatically merges colliders together.
      So instead of creating a separate colliders for each of these tiles and having the destructible behavior tied to that object (which my tilemap tool would allow me to do) I was thinking that I would store an array of all the X and Y locations for the interactive tilemap layer and let the tilemap manage the colliders. 
      Then when I hit a collider on the interactive tilemap layer, instead of of getting the behavior for how to deal with the destruction for that tile from that game object, I would pull it from the array I mentioned earlier based on the tile I attempt to interact with which I already have.
      Does this sound like a good approach? Any other recommendations would be welcomed.
    • By NDraskovic
      Hey guys,
      I have a really weird problem. I'm trying to get some data from a REST service. I'm using the following code:
       
      private void GetTheScores() { UnityWebRequest GetCommand = UnityWebRequest.Get(url); UnityWebRequestAsyncOperation operation = GetCommand.SendWebRequest(); if (!operation.webRequest.isNetworkError) { ResultsContainer rez = JsonUtility.FromJson<ResultsContainer>(operation.webRequest.downloadHandler.text); Debug.Log("Text: " + operation.webRequest.downloadHandler.text); } } The problem is that when I'm in Unity's editor, the request doesn't return anything (operation.webRequest.downloadHandler.text is empty, the Debug.Log command just prints "Text: "), but when I enter the debug mode and insert a breakpoint on that line, then it returns the text properly. Does anyone have an idea why is this happening?
      The real problem I'm trying to solve is that when I receive the text, I can't get the data from the JSON. The markup is really simple:
      [{"id":1,"name":"Player1"},{"id":2,"name":"Player2"}] and I have an object that should accept that data:
      [System.Serializable] public class ResultScript { public int id; public string name; } There is also a class that should accept the array of these objects (which the JSON is returning):
      [System.Serializable] public class ResultsContainer { public ResultScript[] results; } But when I run the code (in the debug mode, to get any result) I get an error: ArgumentException: JSON must represent an object type. I've googled it but none of the proposed solutions work for me.
      Also (regardless if I'm in the debug mode or not) when I try to do some string operations like removing or adding characters to the GET result, the functions return an empty string as a result
      Can you help me with any of these problems?
      Thank you
    • By nihitori
      The Emotional Music Vol. I pack focuses on beautiful and esoteric orchestral music, capable of creating truly emotive and intimate moods. It features detailed chamber strings, cello and piano as the main instruments, resulting in a subtle and elegant sound never before heard in video game royalty-free music assets.

      The pack includes 5 original tracks, as well as a total of 47 loops based on these tracks (long loops for simple use and short loops for custom / complex music layering).

      Unity Asset Store link: https://www.assetstore.unity3d.com/en/#!/content/107032
      Unreal Engine Marketplace link: https://www.unrealengine.com/marketplace/emotional-music-vol-i

      A 15 seconds preview of each main track is available on Soundcloud:
       
    • By RoKabium Games
      Another one of our new UI for #screenshotsaturday. This is the inventory screen for showing what animal fossils you have collected so far. #gamedev #indiedev #sama
    • By eldwin11929
      We're looking for programmers for our project.
      Our project is being made in Unity
      Requirements:
      -Skills in Unity
      -C#
      -Javascript
      -Node.js
      We're looking for programmers who can perform a variety of functions on our project.
      Project is a top-down hack-and-slash pvp dungeon-crawler like game. Game is entirely multiplayer based, using randomized dungeons, and a unique combat system with emphasis on gameplay.
      We have a GDD to work off of, and a Lead Programmer you would work under.
      Assignments may include:
      -Creating new scripts of varying degrees specific to the project (mostly server-side, but sometimes client-side)
      -Assembling already created monsters/characters with existing or non-existing code.
      -Creating VFX
      -Assembling already created environment models
      If interested, please contact: eldwin11929@yahoo.com
      This project is unpaid, but with royalties.
       
      ---
      Additional Project Info:
      Summary:
      Bassetune Reapers is a Player-verus-Player, competitive dungeon crawler. This basically takes on aspects of dungeon crawling, but with a more aggressive setting. Players will have the option to play as the "dungeon-crawlers" (called the 'Knights', or "Knight Class", in-game) or as the "dungeon" itself (literally called the 'Bosses', or "Boss Class", in-game). What this means is that players can choose to play as the people invading the dungeon, or as the dungeon-holders themselves.
      Key Features:
      -Intense, fast-paced combat
      -Multiple skills, weapons, and ways to play the game
      -Tons of different Bosses, Minibosses, creatures and traps to utilize throughout the dungeon
      -Multiple unique environments
      -Interesting, detailed lore behind both the game and world
      -Intricate RPG system
      -Ladder and ranking system
      -Lots of customization for both classes s of customization for both classes
  • Advertisement