Zalo DS Blog

Tuesday, September 16, 2008

Texture Converter

Time for a new update :D Hey, I have been in the UK for 3 and a half months so my english is suppose to be better now (right? XD). Well, today I am going to post about something I did a couple of moths ago, just when I released Rokoban.

I don't know if you have realized but in Rokoban there is no use of channel alpha at all, I mean, by that time I wasn't able to load textures with transparent colors. Not even a simple bit for transparency. That's why all the texts in the game appear over a black background. Ok, if you didn't realize then I have showed every artist in this world that channel alpha is not required anymore! ... not even me can believe that

And why didn`t I give a little support for alpha channel? Because my textures were in bmp format. Bmps doesn't suppot alpha channel. Well, I am not sure at all about this... I think there are some programs that allows you to save 32 bits bmps. The problem is that you don't need your textures to be that large. 32 bits bmps has 8 bits for each channel (Red, green, blue, alpha). The DS doesn't suppor that format so you have to conver it in execution time and that is a waste of time (for the conversion) and size (your textures are taking more space that they really need)

So, basically, what are the texture formats supported by the DS? Those here:
GL_RGB32_A3 = 1, /*!< 32 color palette, 3 bits of alpha */
GL_RGB4 = 2, /*!< 4 color palette */
GL_RGB16 = 3, /*!< 16 color palette */
GL_RGB256 = 4, /*!< 256 color palette */
GL_COMPRESSED = 5, /*!< compressed texture */
GL_RGB8_A5 = 6, /*!< 8 color palette, 5 bits of alpha */
GL_RGBA = 7, /*!< 15 bit direct color, 1 bit of alpha */
GL_RGB = 8 /*!< 15 bit direct color, manually sets alpha bit to 1 */
Maybe for those of you with more experience in console development those formats are familiar, but for me, I have never used something like that. Which program allows you to save into one of these formats? Well, the last two ones (with no palette) can be more or less a 16 bits BMP and you can do some tricks like reserving one of the colors for alpha, and make that conversion when reading. That seems to be what most of the people are doing.

Problem with that? Well, you only have support for 1 bit of alpha (wich means, no gradient) and it is using 2 bytes for each color, and it is not bad... but when you want to load the more textures as posible into memory (and you always are going to need that if you are working whit artist that always want more and more AND MORE!!!... sorry) that is not good at all.

Some people in the homebrew are using PCX. I don't know that format very well. But I know it doesn't give you suppor for any of those weird formats. So I imagine that they are converting the textures when loading then. I was doing something similar for my textures. I was reading paletted bmps and the converting then into 16 bits bmps in execution time. For the alpha channel I was plannig to load another texture in grayscale as I have seen in some games...

Ok. All of those solutions work. But are not the best. Wouldn't it be great to have a program that allows you to save in one of those formats so that you don't have to do anything in execution time? Some people in the homebrew has released programs to do that. But It's been a while and I haven't been able to download one of them. There is also de DDS format for directX, but the pixel formats supported are not compatible either (take a loook... mmmmmm,google,tacata.... here: http://www.imageconverterplus.com/help-center/about-icp/supported-formats/dds/). And there is also a program that people from ID made for quake models but I can't remember the name... so it doesn't matter XD

So... I dediced to write my own converter XDDD Yes, if you spent more time looking for something than the time that you really need to do it then you are wasting your time. The converter I have developed is better than just one specific for the DS (My engine has to be multiplatform :P) So it supports a big variety of formats. You can select how many bits you want for each channel, and in case of palettes, you can select how many bits you need for palette index. It is designed at this momento so that alpha channel in paletted textures is not stored in the palette, but in the index. So, the palette has only 3 channels (RGB) for each color and then in the index there are n-bits for the index and n-bits for the alpha channel. That't the way DS works and it is ok for the moment.

For the first time and without meaning a precedent (I think you can't say that in english) I am going to release not only the tool, but also the source code, so that you can improve it if you want ^_^. Format specification is very simple (and it is included in a .txt) and loading textures is quite straightforward for the DS. To use the program just drag and drop the files you want to convert. I decided to use C++ and MFC this time instead of Java, which is the language in wich I usually code my tools




Download it from here Any comments, suggestions are always welcome ;)


PD: by the way, Capcom... What is the meaning of MEGAMAN 9!!!! You must be thinking we are stupid
PD2: square... WHAT THE HELL ARE YOU DOING RELEASING A PORT OF CHRONO TRIGGER FOR THE DS INSTEAD OF A REMAKE!!! DO YOU THINK WE ARE SO STUPID TO BUY THE SAME GAME TWICE????