The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL RWops and png
mandarx


Joined: 19 Dec 2009
Posts: 61
Location: Inside Volcano Etna
Hello

does SDL RWops work with png files?

I,ve read this tutorial.

http://gpwiki.org/index.php/C:Displaying_a_Bitmap_from_a_Custom_Resource_File_using_SDL_RWops


It works if you load bmps...

Code:
//Load the buffer into a surface using RWops
SDL_RWops *rw = SDL_RWFromMem(buffer, filesize);
SDL_Surface *temp = SDL_LoadBMP_RW(rw, 1);


...but how to load a png or a jpg from memory?

MandarX
nfries88


Joined: 24 Oct 2009
Posts: 100
With SDL_image, yes.
But core SDL package only provides facilities for bitmaps.

Look here: http://www.libsdl.org/projects/SDL_image/docs/SDL_image_12.html
mandarx


Joined: 19 Dec 2009
Posts: 61
Location: Inside Volcano Etna
nfries88 wrote:
With SDL_image, yes.
But core SDL package only provides facilities for bitmaps.

Look here: http://www.libsdl.org/projects/SDL_image/docs/SDL_image_12.html


thanks!!
mandarx


Joined: 19 Dec 2009
Posts: 61
Location: Inside Volcano Etna


if I use this code
Code:
SDL_Surface *image;
image=IMG_Load_RW(SDL_RWFromFile("sample.png", "rb"), 1);

I get the png correctly blitted on the screen when I blit it

if I load it in this way:

Code:
fseek(FileInWhichThePNGIsStored, OffsetOfMyPNG, SEEK_SET);
fread(pBuffer, sizeof(char), PNGFileLenght, FileInWhichThePNGIsStored);
SDL_RWops *rw = SDL_RWFromMem(pBuffer, PNGFileLenght);
SDL_Surface *temp = IMG_Load_RW(rw, 1);


the png seems to lose the alpha channel

Is there a way to preserve the alpha channel using SDL_RWFromMem ??

MandarX
nfries88


Joined: 24 Oct 2009
Posts: 100
SDL 1.2 does not support alpha channels, it at most supports color keys (a color that represents full transparency).
SDL RWops and png
Jeremiah
Guest

Then what is SDL_SRCALPHA for?

On Tue, Mar 2, 2010 at 12:40 PM, nfries88 wrote:
Quote:
SDL 1.2 does not support alpha channels, it at most supports color keys (a
color that represents full transparency).
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Re: SDL RWops and png
nfries88


Joined: 24 Oct 2009
Posts: 100
Jeremiah wrote:
Then what is SDL_SRCALPHA for?

On Tue, Mar 2, 2010 at 12:40 PM, nfries88 wrote:
Quote:
SDL 1.2 does not support alpha channels, it at most supports color keys (a
color that represents full transparency).


Per-surface alpha. SDL 1.2 does not support per-pixel alpha channels (or, at the very least, appears to ignore them when rendering).
SDL RWops and png
Jonny D


Joined: 12 Sep 2009
Posts: 932
It does support per-pixel alpha.  It does not support much in the way of blending modes.  Destination alpha is preserved, so if you alpha blend to a transparent region on an RGBA surface, then you can't see the result.  Maybe this has happened to you?

Jonny D


On Tue, Mar 2, 2010 at 2:26 PM, nfries88 wrote:
Quote:



Jeremiah wrote:

Then what is SDL_SRCALPHA for?


On Tue, Mar 2, 2010 at 12:40 PM, nfries88 <> wrote:




Quote:

SDL 1.2 does not support alpha channels, it at most supports color keys (a
color that represents full transparency).








Per-surface alpha. SDL 1.2 does not support per-pixel alpha channels (or, at the very least, appears to ignore them when rendering).


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL RWops and png
nfries88


Joined: 24 Oct 2009
Posts: 100
Jonny D wrote:
It does support per-pixel alpha.  It does not support much in the way of blending modes.  Destination alpha is preserved, so if you alpha blend to a transparent region on an RGBA surface, then you can't see the result.  Maybe this has happened to you?

Jonny D

No. maybe I just did something wrong. I didn't really need it and ended up just using the colorkey anyway.
mandarx


Joined: 19 Dec 2009
Posts: 61
Location: Inside Volcano Etna
mandarx wrote:


if I load it in this way:

Code:
fseek(FileInWhichThePNGIsStored, OffsetOfMyPNG, SEEK_SET);
fread(pBuffer, sizeof(char), PNGFileLenght, FileInWhichThePNGIsStored);
SDL_RWops *rw = SDL_RWFromMem(pBuffer, PNGFileLenght);
SDL_Surface *temp = IMG_Load_RW(rw, 1);


the png seems to lose the alpha channel


YES!!!!! because I used image = SDL_DisplayFormat(temp); instead of image = SDL_DisplayFormatAlpha(temp);

it works now !!