• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
REspawn

Best way to convert or load custom texture format

11 posts in this topic

Hi,

 

I'm writing a texture loader for game files for my own education and fun.

The game has some texture formats that are not standard for DirectX. I'm wondering what's the best way to load them for rendering as a texture?

 

Any advice or help would be great. Thanks,

Dave

0

Share this post


Link to post
Share on other sites
Use an open-source library such as leptonica (I guess? Never used an open-source image library so someone else would better at suggesting which one you should use) and save it as a format that Direct3D can use, which maybe easily be your own custom format that you have designed so that it can be sent to Direct3D as-is once you load it to memory.


L. Spiro
0

Share this post


Link to post
Share on other sites

When you say 'not standard for DirectX', what exactly do you mean?  Have you check all of the formats that are listed in the DXGI_FORMAT enumeration?  If your texture doesn't map to one of those types in a fairly intuitive way, then you will have trouble trying to render with them - these are the only formats that are available!

0

Share this post


Link to post
Share on other sites

When you say "texture format" do you mean "image file format" (as in JPEG, PNG, etc.) or just a file format for storing texture data (as in your own version of DDS)?

0

Share this post


Link to post
Share on other sites

Thanks for the replies.

 

When I say non standard I mean that it's not in the D3DFORMAT enum, so I can create a texture in that format and then memcpy the data in.

 

So for example one of the formats the game stores it's files in is ABGR8888. In the D3DFORMAT enum there is D3DFMT_A8R8G8B8. 

So would the best way to read this texture in be to create a D3DFMT_A8R8G8B8 texture, lock the texture and manually copy in each pixel of data? Or is there a better / faster way to go from one format to another?

 

Hope that makes it easier to understand my question. 

 

Thanks,

Dave

0

Share this post


Link to post
Share on other sites

You could always copy the data into the texture resource as is, and then simply perform swizzling on the channels when you look it up.  However, I suspect that would get old pretty fast, and I would recommend just writing a small program to do the conversion for you before runtime.  Depending on how often the texture data changes, you could even run your tool as a part of your build process to make everything integrated.

 

I haven't come across an easy to use tool for channel swapping...

2

Share this post


Link to post
Share on other sites

I would recommend just writing a small program to do the conversion for you before runtime.

This.
100000000x this.

Your game/engine/runtime should NOT be dicking about converting image (or any other data) at run time; your texture payload should match the D3D supported ones so that you can simply load the data in and hand it off directly.

Doing the conversion every time you load and run the program is just wasteful...
1

Share this post


Link to post
Share on other sites

FYI, there is a D3DFMT_A8B8G8R8 format. So you shouldn't actually need to convert in this particular case.

0

Share this post


Link to post
Share on other sites

Thanks for the replies. Yep, this is just for a tool / my own education, so I don't mind the extra processing step.

 

@MJP - Yea that's what I thought too, but the channels are switched. So I'll need to switch them.

 

So from doing some reading and testing, looks like the best option is read the data from the file into a buffer, create my texture, lock the rect and then switch the channels as needed. I can't seem to find anything here or on Google that suggests a better way. 

It produces the correct texture data and it's not too slow. Is there a better way?

 

Thanks,

Dave

0

Share this post


Link to post
Share on other sites

Yes, the better way is do not do it at run time.

 

This operation you've just done; file -> buffer -> transcode -> buffer

 

Well it's the same regardless of if you do it in memory every time you load the data or if you do it once before hand, save the result and then load that.

 

The latter being the method that should be used.

0

Share this post


Link to post
Share on other sites

So from doing some reading and testing, looks like the best option is read the data from the file into a buffer, create my texture, lock the rect and then switch the channels as needed. I can't seem to find anything here or on Google that suggests a better way. 

It produces the correct texture data and it's not too slow. Is there a better way?

 

Not really - this is really the minimum amount of work that you could possibly do, so I doubt there will be any faster way to convert them (at compile time or runtime).  As I mentioned above, you could just swizzle the channels in your shaders (which is supposedly free in GPU hardware) so that technically would be faster, but then you will be modifying your shader code based on the external formats, which isn't a good thing.

 

I would say that especially if this project is just for education, then build a standalone tool that will do the conversion for you.  This will give you some additional experience, plus some reusable code to boot.  And since nobody knows of a good program to do this already, you could throw the results up on GitHub or CodePlex and let everyone know how to do it :)

0

Share this post


Link to post
Share on other sites

Stand alone conversion tool seems like the best and most fun way to do this. I'll update this thread when I put the code up somewhere.

Thanks for all the help.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0