SDL (SDL_surface importing pixel data)

Help
Alfrik
2009-12-09
2013-05-02
  • Alfrik
    Alfrik
    2009-12-09

    Hi,

    I was wondering, it is possible to load pixel data from image and make a sdl surface from it?
    (result.png works fine, but SDL bmp have only w, h and black background)

        ilCopyPixels(0, 0, 0,w, h,
         1, IL_RGB, IL_UNSIGNED_BYTE, data);
         ilSetPixels(0, 0, 0, w, h, 1, IL_RGB, IL_UNSIGNED_BYTE, data);
        /* and dump them to the disc… */
        ilSaveImage("result.png");
       
        Image = SDL_CreateRGBSurfaceFrom(data,
                                                                w,
                                                                h ,
                                                                ilGetInteger(IL_IMAGE_BPP),
                                                                w* (ilGetInteger(IL_IMAGE_BPP) / 8),
                                                                0x000000FF,
                                                                0x0000FF00,
                                                                0x00FF0000,
                                                                0);
        CrapImage = SDL_DisplayFormat( Image );

    if ( SDL_SaveBMP(CrapImage, "screen.bmp") < 0 )
    printf("Couldn't save screen: %s\n", SDL_GetError());

     
  • Alfrik
    Alfrik
    2009-12-09

    Ups, forgot. Maybe there something with the data value?

        int memory_needed = w *  h * 3 * sizeof(unsigned char);
        ILubyte * data = (ILubyte *)malloc(memory_needed);

     
  • Matěj Týč
    Matěj Týč
    2009-12-13

    Hello,

    I can't tell you much about SDL since I don't work with it.However, we have a ILUT SDL example that could interest you (it is supposed to be in the 'examples' section of the .tar.gz distribution of DevIL)
    Although the DevIL stuff seems to be a little bit broken to me ATM, the SDL one is the more robust of them…

    Regards,<br>
    Matej