PNG to PVR

From http://iphonedevelopment.blogspot.com/2008/12/preparations-for-porting-nehe-lesson-06.html


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.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值