Writing appl. generated graphics on hard disk

Developers
2009-05-18
2013-05-02
  • Dear DevIL users,

    I am trying to export application generated graphics into a file and browsed
    the corresponding DeVIL tutorial on http://openil.sourceforge.net/tuts/tut_5/index.htm :

    <code>

    ILubyte *Lump;
    ILuint Size;
    FILE *File;

    File = fopen("monkey.tga", "rb");
    fseek(File, 0, SEEK_END);
    Size = ftell(File);

    Lump = (ILubyte*)malloc(Size);
    fseek(File, 0, SEEK_SET);
    fread(Lump, 1, Size, File);
    fclose(File);

    ilLoadL(IL_TGA, Lump, Size);
    free(Lump);

    </code>

    The above example loads graphics (+ file header) from a file into memory.
    A subsequent ilSaveImage(..) will of course write the whole lump into a new file.

    As one is typically not interested in setting up an image header for every supported
    format though, we wanted to know whether there is a possibility to use a built in DevIL image
    encoder and marshaller that sets up the corresponding image headers for a disired
    image type automatically (or based on few parameters passed).

    This is what we are willing to do (in code):

       ilInit();
       iluInit();
       ilutRenderer(ILUT_OPENGL);

       pluginImageID = 0;
       ilGenImages(1, &pluginImageID);
       ilBindImage(pluginImageID); 

       const unsigned char bufferWidth = 64;
       const unsigned char bufferHeight = 64;
       GLubyte buffer[bufferWidth][bufferHeight][4];
       int i, j, c;
       for (i = 0; i < bufferHeight; i++) {
          for (j = 0; j < bufferWidth; j++) {
             c = (((i & 0x8) == 0) ^((j & 0x8) == 0)) * 255;
             buffer[i][j][0] = (unsigned char) c;
             buffer[i][j][1] = (unsigned char) c;
             buffer[i][j][2] = (unsigned char) c;
             buffer[i][j][3] = (unsigned char) 128;
          }
       }

       ILboolean loadingSucceeded = ilLoadL(IL_WHATEVER_??, buffer, 64*64*4);
       ILenum errorType = ilGetError();
       const wchar_t* errorString = iluErrorString(errorType);

       const wchar_t* outputFilename = L"D:\\home\\babak\\DevIL_TestExport.png";
       ILboolean savingSuccedded = ilSaveImage(outputFilename);    
       

    Thanks,

    Babak Sayyid Hosseini

     
    • Denton Woods
      Denton Woods
      2009-05-19

      You probably want to look at using ilTexImage for what you are trying instead of ilLoadL.

       
      • Thank you Denton,
        the function does the job.

        Regards,

        Babak Sayyid Hosseini