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

Tagged: 

This topic contains 4 replies, has 3 voices, and was last updated by  Tobias Hector 3 years, 11 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #31552

    ChloeG
    Member

    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?

    #38236

    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

    #38237

    ChloeG
    Member

    thanks, I will try

    #38238

    Dan
    Member

    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";

    //load and decode
    std::vector image;
    unsigned width, height;
    unsigned error = lodepng::decode(image, width, height, filename);

    if(error) {
    // handle error
    }
    else {
    //the pixels are now in the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ...
    }

    Now how can I load the data to a texture? Can I use `PVRTTexture` or do I have to write my own GL code?

    Thanks for your help!

    #38239

    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

Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.