Saturday, December 13, 2008

Preparations for Porting NeHe Lesson 06

The next lesson has to do with texture mapping. The NeHe lessons load a bitmap image and then maps that image to quads. Because the iPhone has less memory than desktop computers, we're going to use a different image type In order to conserve memory. This is a special image format used specifically for texture mapping called PVRTC.

Before we can move ahead with this, there are two things you need. The first, is a source image that will be mapped onto. You can pull the one from the NeHe Lesson 6 C++ project, or you can use your own image. If you use your own image, it must be sized so that both directions are equal and are a power of 2, which means the image should be 2x2, 4x4, 8x8, 16x16, 32x32, 64x64, 128x128, 256x256, 512x512, or 1024x1024 pixels (which is the largest size texture supported on the iPhone).

There's a command-line tool that will create PVRTC images for you from source PNG files. That tool is located at the following location:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool

To make life easier, you might want to add /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ to your path variable. I use tcsh as my shell, so adding that to my path was just a matter of adding /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ to my .cshrc file (~/.cshrc). Here's what that line in my .cshrc file looks like:
set path= ( /usr/X11/bin /opt/local /opt/local/bin ~/bin /usr/local/bin /usr/bin /bin  /usr/sbin /sbin /Users/jeff/bin /Developer/Tools /opt/local/bin /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ )
If you're a bash person, then you would do this in your bash profile, located at ~/.bash_profile, and the syntax is a touch different:
export PATH="/opt/local:/opt/local/bin/:Users/jeff/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/Users/jeff/bin:/Developer/Tools:/opt/local/bin:/usr/local/pgsql/bin:/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/"
What that will do is allow you to use texturetool from the command line without having to type the full path, just as if texturetool were sitting in your /bin directory.

Now, in Terminal, navigate to where your source PNG image file is using the cd command, then generate your PVRTC file with the texture tool, like so (in my case, the source file is NeHe.png:
texturetool -e PVRTC -o NeHe.pvr4 NeHe.png
Running this will generate a file with a .pvr4 extension. You will not be able to view this image file in Preview.app, or the vast majority of other image editing or viewing programs (so make sure this conversion is the last step), but trust me, it's an image file. Save this file for the next lesson, lesson 06.

It may take a few days before I get Lesson 06 ported, though. The fact that our cube is made up of triangles, rather than quads is going to mean some trial and error with the texture coordinates.



7 comments:

papillon68 said...

Hi Jeff, did you ever try to load a PVRTC texture with alpha channel ? I couldn't find much info, so I just tried (unsuccessfully) the following:

glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 256.0, 256.0, 0, (256.0 * 256.0) / 2, [texData bytes]);

Raktim said...

Hi...
i am using the commend in my mac machine to convert a .pmg file in PVR format.
bt after setting the file paht and when i am giving the command
"texturetool -e PVRTC -o character.pvr4 character.png " (character.png is my .png file)
it says that texturetool command not found

Uriah said...

texturetool is under /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool

Uriah said...

Lets try that again...

/Developer/Platforms/iPhoneOS.platform/Developer
/usr/bin/texturetool

Nom DePlume said...

Thank you so much for all your tutorial materials!

Readers who use csh based shells (csh, tcsh) may want to to append the original path data to the new path instead of having one enormous set path entry:

set path = (/my/home/directory/bin $path)
set path = (/my/new/path/bin $path)

If nothing else, it makes editing & maintenance easier.

Edwin said...

scrub m65 kamagra attorney lawyer body scrub field jacket lovegra marijuana attorney injury lawyer

h4ns said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say.

Arsenal vs Huddersfield Town live streaming
Arsenal vs Huddersfield Town live streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Wolverhampton Wanderers vs Stoke City Live Streaming
Notts County vs Manchester City Live Streaming
Notts County vs Manchester City Live Streaming
Bologna vs AS Roma Live Streaming
Bologna vs AS Roma Live Streaming
Juventus vs Udinese Live Streaming
Juventus vs Udinese Live Streaming
Napoli vs Sampdoria Live Streaming
Napoli vs Sampdoria Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
Fulham vs Tottenham Hotspur Live Streaming
AS Monaco vs Marseille Live Streaming
AS Monaco vs Marseille Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Alajuelense vs Perez Zeledon Live Streaming
Technology News | News Today | Live Streaming TV Channels