How can I read png files and transcode them to pvrtc by using c/c++ code?

HI, as the title said, I want to find a way to transcode png to pvrtc,



and I found PVRTexLib.lib, but it can only read pvr file.



how can I read png files and use PVRTexLib.lib to transcode it to pvrtc?

Hi Chloe,



PVRTexLib doesn’t have any way to natively handle image file formats. If you need to turn images into textures, you need to use a separate image processing library to do this. For png you can either use a low level library to do it, such as libpng, or something a bit more multipurpose like tinyimageloader. There’s a lot of image loading libraries out there if you don’t like the looks of either of those however!



Once you’ve loaded it into a raw bitmap, you can then put that data into a CPVRTexture by defining the header and passing in the raw data. If you have any questions about this step when you get there, let us know :)!



Thanks,

Tobias

thanks, I will try

I have loaded a png image using http://lodev.org/lodepng/ .

Now I have got a pointer ready to the raw data. From the loading code:


  const char* filename = "test.png";<br />
<br />
//load and decode<br />
std::vector image;<br />
unsigned width, height;<br />
unsigned error = lodepng::decode(image, width, height, filename);<br />
<br />
if(error) {<br />
// handle error<br />
}<br />
else {<br />
//the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ...<br />
}
```<br />
<br />
Now how can I load the data to a texture? Can I use `PVRTTexture` or do I have to write my own GL code?<br />
<br />
Thanks for your help!

Hi Dan,



Are you talking about loading into a CPVRTexture for manipulation with PVRTexLib, or are you wanting to load it directly into OpenGL (ES) as a texture?



If you are looking to use it in OpenGL, you should load it directly with the OpenGL texture loading functions.



Regards,

Tobias