devIL to SDL_Surface

Hello,

I want to load an image into SDL_Surface using devIL. I’ve tried this:

Code:

ILuint texid;
ilGenImages(1, &texid);
ilBindImage(texid);

ilLoadImage("image.png");

SDL_Surface *  SDLImage = SDL_CreateRGBSurface(SDL_HWSURFACE, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_BPP), 0, 0, 0, 255);

success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
if (!success)
    // do error stuff

SDLImage->pixels = ilGetData();

ilDeleteImages(1, &texid);

It’s not working, what’s the way to achieve this?
Thank you

You’re creating a hardware surface. Typically, surface->pixels is NULL for
hardware surfaces. SDL doesn’t know there is anything there, nor will it
look for data there.

Try SDL_LockSurface() it, copy the data to surface->pixels (e.g. memcpy())
and then SDL_UnlockSurface(). The last 4 parameters to
SDL_CreateRGBSurface() look like they are probably wrong.On 7 October 2010 08:35, Force wrote:

It’s not working, what’s the way to achieve this?
Thank you

Got the image on the screen, but as you said the last 4 parameters are wrong. If I put all to 255, it gives me a black/white version of the image. I don’t know how to put these 4 values. I checked this (http://www-f9.ijs.si/~matevz/docs/DevIL/il/f00027.htm) but I don’t see anything there other than format.

Any idea?

The values I’ve most commonly seen are the ones in the documentation:
http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurface

I’ve never used devIL so I don’t know if you can obtain this
information from it or whether it assumes a reasonable default.On 7 October 2010 11:08, Force wrote:

Got the image on the screen, but as you said the last 4 parameters are
wrong. If I put all to 255, it gives me a black/white version of the image.
I don’t know how to put these 4 values. I checked this but I don’t see
anything there other than format.

Any idea?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Oops, forgot to give you the working code:

ILuint texid;
ilGenImages(1, &texid);
ilBindImage(texid);

ilLoadImage(“image.png”);
SDL_Surface * SDLImage = SDL_CreateRGBSurface(SDL_SWSURFACE,
ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),
ilGetInteger(IL_IMAGE_BPP), 0, 0, 0, 0);
SDL_LockSurface( SDLImage );
ilCopyPixels( 0, 0, 0, SDLImage->w, SDLImage->h, 1, IL_RGB, SDLImage->pixels
);
SDL_UnlockSurface( SDLImage );

ilDeleteImages(1, &texid);

Take care,
-OzOn Thu, Oct 7, 2010 at 7:41 AM, Alex Barry <@Alex_Barry> wrote:

Looks like you want to use ilCopyPixels( ILuint XOff, ILuint YOff, ILuint
ZOff, ILuint Width, ILuint Height, ILuint Depth, ILenum Format, ILenum Type,
ILvoid *Data);
-Oz

On Thu, Oct 7, 2010 at 6:15 AM, Brian Barrett <brian.ripoff at gmail.com>wrote:

The values I’ve most commonly seen are the ones in the documentation:
http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurface

I’ve never used devIL so I don’t know if you can obtain this
information from it or whether it assumes a reasonable default.

On 7 October 2010 11:08, Force wrote:

Got the image on the screen, but as you said the last 4 parameters are
wrong. If I put all to 255, it gives me a black/white version of the
image.
I don’t know how to put these 4 values. I checked this but I don’t see
anything there other than format.

Any idea?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Looks like you want to use ilCopyPixels( ILuint XOff, ILuint YOff, ILuint
ZOff, ILuint Width, ILuint Height, ILuint Depth, ILenum Format, ILenum Type,
ILvoid *Data);
-OzOn Thu, Oct 7, 2010 at 6:15 AM, Brian Barrett <brian.ripoff at gmail.com>wrote:

The values I’ve most commonly seen are the ones in the documentation:
http://sdl.beuc.net/sdl.wiki/SDL_CreateRGBSurface

I’ve never used devIL so I don’t know if you can obtain this
information from it or whether it assumes a reasonable default.

On 7 October 2010 11:08, Force wrote:

Got the image on the screen, but as you said the last 4 parameters are
wrong. If I put all to 255, it gives me a black/white version of the
image.
I don’t know how to put these 4 values. I checked this but I don’t see
anything there other than format.

Any idea?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You’re creating surface with zero-sized color channels.

SDL_Surface * SDLImage = SDL_CreateRGBSurface(SDL_SWSURFACE,
ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),
ilGetInteger(IL_IMAGE_BPP), 0, 0, 0, 0);

should be for example

SDL_Surface * SDLImage = SDL_CreateRGBSurface(SDL_SWSURFACE,
ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),
ilGetInteger(IL_IMAGE_BPP), 0xff, 0xff00, 0xff0000, 0xff000000);

Still not working. This is my last code:

Code:
ILuint texid;
ilGenImages(1, &texid);
ilBindImage(texid);

ilLoadImage("image.png");

ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

SDL_Surface *  SDLImage = SDL_CreateRGBSurface(SDL_SWSURFACE, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_BPP), 0xff, 0xff00, 0xff0000, 0xff000000);    // or  (4, 0, 0, 0)

SDL_LockSurface( SDLImage );
ilCopyPixels( 0, 0, 0, SDLImage->w, SDLImage->h, 1, IL_RGBA, IL_RGBA, SDLImage->pixels );
SDL_UnlockSurface( SDLImage );
ilDeleteImages(1, &texid);

What’s type in ilCopyPixels()? I got too fre arguments for ilCopyPixels(), and I just repeated IL_RGBA there.

Setting the mask values or rgba to zero will force SDL to automatically fill
in those values, while zero’ing the alpha channel (you can re-add that if
you need to). The new documentation doesn’t note that, but it’s still the
case in SDL 1.3

for your copy code:
ilCopyPixels( 0, 0, 0, SDLImage->w, SDLImage->h, 1, IL_RGBA,
SDLImage->pixels );

You had one too many IL_RGBA in there.

Take care,
-AlexOn Thu, Oct 7, 2010 at 10:47 AM, Force wrote:

Still not working. This is my last code:

Code:

ILuint texid;
ilGenImages(1, &texid);
ilBindImage(texid);

ilLoadImage("image.png");

ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

SDL_Surface *  SDLImage = SDL_CreateRGBSurface(SDL_SWSURFACE,

ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),
ilGetInteger(IL_IMAGE_BPP), 0xff, 0xff00, 0xff0000, 0xff000000); // or
(4, 0, 0, 0)

SDL_LockSurface( SDLImage );
ilCopyPixels( 0, 0, 0, SDLImage->w, SDLImage->h, 1, IL_RGBA, IL_RGBA,
SDLImage->pixels );

SDL_UnlockSurface( SDLImage );
ilDeleteImages(1, &texid);

What’s type in ilCopyPixels()? I got too fre arguments for ilCopyPixels(),
and I just repeated IL_RGBA there.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

for your copy code:
ilCopyPixels( 0, 0, 0, SDLImage->w, SDLImage->h, 1, IL_RGBA, SDLImage->pixels );

You had one too many IL_RGBA in there.

Yes, because I got the “too few arguments” error. You had missed format or type parameter in that function. I just duplicated IL_RGBA to pass that error. So that function still doesn’t work. :)[/quote]

ilCopyPixels( 0, 0, 0, SDLImage->w, SDLImage->h, 1, IL_RGBA,
IL_UNSIGNED_BYTE, SDLImage->pixels );

Oops, sorry, I forgot a param - it happens, I guess.
I hope that fixes things,
-AlexOn Thu, Oct 7, 2010 at 11:49 PM, Force wrote:

Quote:

for your copy code:
ilCopyPixels( 0, 0, 0, SDLImage->w, SDLImage->h, 1, IL_RGBA,
SDLImage->pixels );

You had one too many IL_RGBA in there.

Yes, because I got the “too few arguments” error. You had missed format or
type parameter in that function. I just duplicated IL_RGBA to pass that
error. So that function still doesn’t work. [image: Smile][/quote]


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org