SDL_CreateRGBSurface

In the SDL documentation you only describe how to use this function in
32 bit mode, but how do I create the masks in 16 or 24? Is this the
right way?
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xf000;
gmask = 0x0f00;
bmask = 0x00f0;
amask = 0x000f;
#else
rmask = 0x000f;
gmask = 0x00f0;
bmask = 0x0f00;
amask = 0xf000;
#endif

surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
                               rmask, gmask, bmask, amask);

— Tomas Bjerre <92tobj at utb.ronneby.se> wrote:

In the SDL documentation you only describe how to
use this function in
32 bit mode, but how do I create the masks in 16 or
24? Is this the
right way?

Traditionally 24 and 16 bit formats are alpha-less, so
in the case of using a ‘standard’ format, no. However,
I believe that the bellow, if creating a 16 bit
surface, should give 4 bits for each of red, green,
blue, and alpha. That’s 16 tones for each component.

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xf000;
gmask = 0x0f00;
bmask = 0x00f0;
amask = 0x000f;
#else
rmask = 0x000f;
gmask = 0x00f0;
bmask = 0x0f00;
amask = 0xf000;
#endif

surface = SDL_CreateRGBSurface(SDL_SWSURFACE,

width, height, 16,
rmask, gmask,
bmask, amask);

Note: replaced the 32 with a 16 ;).

Okay, now if you wanted to create a more standard 16
bit surface, you’d use something like (for 5-5-5):

rmask = 31 << 10;
gmask = 31 << 5;
bmask = 31;
amask = 0;

surface = SDL_CreateRGBSurface(SDL_SWSURFACE,

width, height, 16,
rmask, gmask,
bmask, amask);

Note that for 16 bit I excluded the endian code.
Reason?

Since the green component straddles multiple bytes, it
really dosn’t make sense to access them via bytes. The
way you WANT to access them is via words. Having edian
dependant masks will make the value of the word
different on different edians… totally un-necessary.

Let me explain:

32 bit pixel of color R:FF G:EE B:DD A:00

With the extra edian code, when we read the pixel a
byte at a time, we’ll allways get:
byte[0]=0xFF
byte[1]=0xEE
byte[2]=0xDD
byte[3]=0x00

whereas reading a dword at a time (aka an unsigned
int) we’ll get either:
0xFFEEDD00
or
0x00DDEEFF

depending on the endian.

Without the endian code, given the same scenario, if
we read a dword at a time, the value would allways be
0xFFEEDD00. However, if we read a byte at a time, we’d
either get:

byte[0]=0xFF
byte[1]=0xEE
byte[2]=0xDD
byte[3]=0x00
or:

byte[0]=0x00
byte[1]=0xDD
byte[2]=0xEE
byte[3]=0xFF

depending on which edian the system was using. Thus,
I’m assuming that in 32 bit mode, you want to access
via bytes, but in 16 bit mode, you want to access via
words, as the green component straddles bytes.

for a 24-bit, read-by-byte surface:

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff0000;
gmask = 0xff00;
bmask = 0xff;
amask = 0;
#else
rmask = 0xff;
gmask = 0xff00;
bmask = 0xff0000;
amask = 0;
#endif

surface = SDL_CreateRGBSurface(SDL_SWSURFACE,

width, height, 24,
rmask, gmask,
bmask, amask);

Hope this long-winded reply helps :).__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

Traditionally 24 and 16 bit formats are alpha-less, so

16-bit formats with alpha, eg 4444 and 5551, are commonplace; I use them
on a daily basis with OpenGL (GL_UNSIGNED_SHORT_4_4_4_4,
GL_UNSIGNED_SHORT_5_5_5_1) and D3D (D3DFMT_A4R4G4B4, D3DFMT_A1R5G5B5).
They’re extremely useful.

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xf000;
gmask = 0x0f00;
bmask = 0x00f0;
amask = 0x000f;
#else
rmask = 0x000f;
gmask = 0x00f0;
bmask = 0x0f00;
amask = 0xf000;
#endif

Watch out–you’re swapping nibbles, not bytes.

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xf000;
gmask = 0x0f00;
bmask = 0x00f0;
amask = 0x000f;
#else
rmask = 0x00f0;
gmask = 0x000f;
bmask = 0xf000;
amask = 0x0f00;
#endif

or more readably:

rmask = SDL_SwapBE16(0xf000);
gmask = SDL_SwapBE16(0x0f00);
bmask = SDL_SwapBE16(0x00f0);
amask = SDL_SwapBE16(0x000f);

Note, though, that 16-bit packed pixel formats are typically stored in
the CPU’s endianness (eg. when passing to OpenGL)–so you don’t always
want to do this.

(I think Michael said something similar, but his post was too long. :)On Tue, Oct 14, 2003 at 09:32:28AM -0700, Michael Rickert wrote:


Glenn Maynard

Hello!

I want to load a Bitmap onto a surface (bmp), than blit it on another
surface (sbmp) created by using SDL_CreateRGBSurface and than again blit
this surface (sbmp) on the screen-surface (screen). But it won’t work.
Here is the code:

/…

SDL_Surface *screen, *bmp, *sbmp;
Uint32 rmask, gmask, bmask, amask;

if(SDL_Init(SDL_INIT_VIDEO) != -1)
atexit(SDL_Quit);

screen = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
bmp = SDL_LoadBMP(“test.bmp”);

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif

sbmp = SDL_CreateRGBSurface(SDL_HWSURFACE, bmp->w, bmp->w, 16, rmask,
gmask, bmask, amask);

SDL_BlitSurface(bmp, NULL, sbmp, NULL);
SDL_BlitSurface(bmp, NULL, screen, NULL);

… /

is anyone able to help me?

thx

jk

Hello!

I want to load a Bitmap onto a surface (bmp), than blit it on another
surface (sbmp) created by using SDL_CreateRGBSurface and than again blit
this surface (sbmp) on the screen-surface (screen). But it won’t work.

Can you define “won’t work”? Does the blit come out all garbled? If so,
this will be because you’re not calling SDL_DisplayFormat on your
surfaces, so there is a pixel-format mismatch with the display.

Other than that, I’ll have to know what isn’t working before I start
trying to hazard a guess.

Quoth Todd Lang <todd.lang at kiyote.ca>, on 2005-04-04 17:13:03 -0400:

Hello!

I want to load a Bitmap onto a surface (bmp), than blit it on another
surface (sbmp) created by using SDL_CreateRGBSurface and than again blit
this surface (sbmp) on the screen-surface (screen). But it won’t work.

Can you define “won’t work”? Does the blit come out all garbled? If so,
this will be because you’re not calling SDL_DisplayFormat on your
surfaces, so there is a pixel-format mismatch with the display.

Blits should not become garbled by not calling SDL_DisplayFormat. SDL
converts pixel formats as necessary; not calling SDL_DisplayFormat
will decrease performance due to the conversion taking up CPU every
time the blit is performed, but should not cause incorrect blits.

—> Drake Wilson
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050404/50e2e838/attachment.pgp

Drake Wilson wrote:

Quoth Todd Lang <todd.lang at kiyote.ca>, on 2005-04-04 17:13:03 -0400:

Hello!

I want to load a Bitmap onto a surface (bmp), than blit it on another
surface (sbmp) created by using SDL_CreateRGBSurface and than again blit
this surface (sbmp) on the screen-surface (screen). But it won’t work.

Can you define “won’t work”? Does the blit come out all garbled? If so,
this will be because you’re not calling SDL_DisplayFormat on your
surfaces, so there is a pixel-format mismatch with the display.

Blits should not become garbled by not calling SDL_DisplayFormat. SDL
converts pixel formats as necessary; not calling SDL_DisplayFormat
will decrease performance due to the conversion taking up CPU every
time the blit is performed, but should not cause incorrect blits.

—> Drake Wilson



SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

with “won’t work” I mean that the screen is absolutely black. There is
nothing.
Besides I tried SDL_DisplayFormats but that didn’t affect the black screen.

<20050404220706.GA1120 at ampersand> <425216E3.1060804 at laklein.de>
In-reply-to: <42516A97.4000806 at laklein.de> <.216.16.236.14.1112649183.squirrel at mail.kiyote.ca>
<20050404220706.GA1120 at ampersand> <425216E3.1060804 at laklein.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-2
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
X-Mailer: Interfejs WWW poczty Wirtualnej Polski
Organization: Poczta Wirtualnej Polski S.A. http://www.wp.pl/
X-User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041217
X-IP: 213.69.244.34
X-WP-AV: skaner antywirusowy poczty Wirtualnej Polski S. A.
X-WP-SPAM: NO AS1=NO AS2=YES(0.999227) AS3=NO AS4=NO

Dnia 5-04-2005 o godz. 6:41 Jonas Klein napisa?(a):

Drake Wilson wrote:

Quoth Todd Lang <todd.lang at kiyote.ca>, on 2005-04-04 17:13:03
-0400:

Hello!

I want to load a Bitmap onto a surface (bmp), than blit it
on another

surface (sbmp) created by using SDL_CreateRGBSurface and
than again blit

this surface (sbmp) on the screen-surface (screen). But it
won’t work.

Can you define “won’t work”? Does the blit come out all
garbled? If so,

this will be because you’re not calling SDL_DisplayFormat on your
surfaces, so there is a pixel-format mismatch with the display.

Blits should not become garbled by not calling
SDL_DisplayFormat. SDL

converts pixel formats as necessary; not calling SDL_DisplayFormat
will decrease performance due to the conversion taking up CPU
every

time the blit is performed, but should not cause incorrect blits.

—> Drake Wilson



SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

with “won’t work” I mean that the screen is absolutely black.
There is
nothing.
Besides I tried SDL_DisplayFormats but that didn’t affect the
black screen.

‘black screen’ hmm… perhaps you forgot to update it
try this

bmp = SDL_LoadBMP( “somefile.bmp” );
sbmp = SDL_DisplayFormat( bmp );
/* don’t forget to free unused surfaces
or you will have some serious memory leakages !!! */
SDL_FreeSurface( bmp );

SDL_BlitSurface( sbmp, 0, display_surface, 0 );
/* if you don’t update display_surface you will see
wonderfully black screen */
SDL_UpdateRect( display_surface, 0, 0, 0, 0 );

and you should see something
hope it helps
pamashoid----------------------------------------------------
Jeste? pracodawc?? Szukasz pracownika?
Zamie?? og?oszenie w Praca.wp.pl!
Internet to skuteczne narz?dzie rekrutacyjne!
http://klik.wp.pl/?adr=http%3A%2F%2Fpraca.wp.pl%2Fzamiesc.html&sid=345

In order to display the results of the drawing, you must call SDL_Flip().

This is due to the fact that you are using SDL_DOUBLEBUF, that is two screen
buffers, one for drawing, one for displaying. Right now, you are only
drawing to the draw surface (“backbuffer”) and not displaying the results.

/OlofOn Apr 5, 2005 6:41 AM, Jonas Klein wrote:

Drake Wilson wrote:

Quoth Todd Lang <todd.lang at kiyote.ca>, on 2005-04-04 17:13:03 -0400:

Hello!

I want to load a Bitmap onto a surface (bmp), than blit it on another
surface (sbmp) created by using SDL_CreateRGBSurface and than again
blit

this surface (sbmp) on the screen-surface (screen). But it won’t work.

Can you define “won’t work”? Does the blit come out all garbled? If so,
this will be because you’re not calling SDL_DisplayFormat on your
surfaces, so there is a pixel-format mismatch with the display.

Blits should not become garbled by not calling SDL_DisplayFormat. SDL
converts pixel formats as necessary; not calling SDL_DisplayFormat
will decrease performance due to the conversion taking up CPU every
time the blit is performed, but should not cause incorrect blits.

—> Drake Wilson



SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

with “won’t work” I mean that the screen is absolutely black. There is
nothing.
Besides I tried SDL_DisplayFormats but that didn’t affect the black
screen.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

‘black screen’ hmm… perhaps you forgot to update it
try this
SDL_UpdateRect( display_surface, 0, 0, 0, 0 );

and you should see something

He is using SDL_DOUBLEBUF; then SDL_Flip() is the way to go,
documentation does not say what SDL_UpdateRect() does in case of
double buffering.

/Olof

screen = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);

How i should choose if use SDL_SWSURFACE instead of SDL_HDSURFACE?!?

Muzero

Use only SDL_SWSURFACE, nothing else:

screen = SDL_SetVideoMode(800, 600, 16, SDL_SWSURFACE);

/OlofOn Apr 5, 2005 11:02 PM, Muzero wrote:

screen = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);

How i should choose if use SDL_SWSURFACE instead of SDL_HDSURFACE?!?

Muzero


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Use only SDL_SWSURFACE, nothing else:

Why i should use ONLY SWSURFACE?

Muzero> screen = SDL_SetVideoMode(800, 600, 16, SDL_SWSURFACE);

/Olof

On Apr 5, 2005 11:02 PM, Muzero <@Muzero> wrote:

screen = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);

How i should choose if use SDL_SWSURFACE instead of SDL_HDSURFACE?!?

Muzero


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi All,

I’m a beginner in the ‘pixel business’. Could someone explain to me the semantic
of the R-, G-, B-, and A-Mask parameters of SDL_CreateRGBSurface ??

Best Regards

–Armin______________________________________________________________________
XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130

Sure…this explanation assumes that you will put pixels that are 32
bits wide…i.e. 8 bits for each of the R, G, B, and A channels (BTW…I
recently became aware that it is not universally obvious to people that
"any" color can be represented by a video display by blending Red,
Green, and Blue, and Alpha channel is used for transparency/blending. I
quote “any” because not every color can be represented by RGB–there is
an RGB color gamut that is not identical to the visible light gamut, but
that is way, way beyond the scope of your question).

So your image can be represented by an array of 32 bit values, where the
first 8 bits contain the Red intensity, the next 8 bits the Green
intensity, etc. The last 8 bits contain the Alpha blending
(transparency) level. You can actually put these values in any order
you want (RGBA, ABGR, ARGB, whatever), which is why you need to provide
a mask set for extracting these value.

The SDL Surface needs to know how to get the R, G, B, and A values out
of each pixel value. So you provide a bitmask to turn “off” all but the
R, G, B, or A bits in your pixel value. The docs provide example masks:

/* Create a 32-bit surface with the bytes of each pixel in R,G,B,A
order, as expected by OpenGL for textures */

SDL_Surface *surface;
Uint32 rmask, gmask, bmask, amask;

/* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif

surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
rmask, gmask, bmask, amask);

Hope that gets you started…

-EricOn Wed, 2006-06-07 at 15:40 +0200, Armin Steinhoff wrote:

Hi All,

I’m a beginner in the ‘pixel business’. Could someone explain to me the semantic
of the R-, G-, B-, and A-Mask parameters of SDL_CreateRGBSurface ??

Best Regards

–Armin


XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient(s) please contact the sender by reply email and destroy all copies of the original message. Thank you.

Eric,

many thanks for your useful response.

Best Regards

Armin

Eric Kort <eric.kort at vai.org> schrieb am 07.06.2006 16:26:49:>

Sure…this explanation assumes that you will put pixels that are 32
bits wide…i.e. 8 bits for each of the R, G, B, and A channels (BTW…I
recently became aware that it is not universally obvious to people that
"any" color can be represented by a video display by blending Red,
Green, and Blue, and Alpha channel is used for transparency/blending. I
quote “any” because not every color can be represented by RGB–there is
an RGB color gamut that is not identical to the visible light gamut, but
that is way, way beyond the scope of your question).

So your image can be represented by an array of 32 bit values, where the
first 8 bits contain the Red intensity, the next 8 bits the Green
intensity, etc. The last 8 bits contain the Alpha blending
(transparency) level. You can actually put these values in any order
you want (RGBA, ABGR, ARGB, whatever), which is why you need to provide
a mask set for extracting these value.

The SDL Surface needs to know how to get the R, G, B, and A values out
of each pixel value. So you provide a bitmask to turn “off” all but the
R, G, B, or A bits in your pixel value. The docs provide example masks:

/* Create a 32-bit surface with the bytes of each pixel in R,G,B,A
order, as expected by OpenGL for textures */

SDL_Surface *surface;
Uint32 rmask, gmask, bmask, amask;

/* SDL interprets each pixel as a 32-bit number, so our masks must depend
on the endianness (byte order) of the machine */

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif

surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
rmask, gmask, bmask, amask);

Hope that gets you started…

-Eric

On Wed, 2006-06-07 at 15:40 +0200, Armin Steinhoff wrote:

Hi All,

I’m a beginner in the ‘pixel business’. Could someone explain to me the semantic
of the R-, G-, B-, and A-Mask parameters of SDL_CreateRGBSurface ??

Best Regards

–Armin


XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient(s) please contact the sender by reply email and destroy all copies of the original message. Thank you.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Erweitern Sie FreeMail zu einem noch leistungsst?rkeren E-Mail-Postfach!
Mehr Infos unter http://freemail.web.de/home/landingpad/?mc=021131

I have used two methods to splilt a large image loaded from disk(whith
sprite images) into various frames of my SDL_Surface frames array. The first
one I create a empty surface whith SDL_CreateRGBSurface whith dimensions of
frames. Then i blit the large image with the calculated offsets in this
image, after this i use SDL_Display format to past the image for a element
of my array.
The second is to load a template image with frames dimensions from disk,
blit the larger image, then past it for my frames array.

The first method, using SDL_CreateRBGSurface slow down the animation, why?

thanks
Paulo

Hello !

I have used two methods to splilt a large image loaded from disk(whith
sprite images) into various frames of my SDL_Surface frames array. The
first one I create a empty surface whith SDL_CreateRGBSurface whith
dimensions of frames. Then i blit the large image with the calculated
offsets in this image, after this i use SDL_Display format to past the
image for a element of my array. The second is to load a template image
with frames dimensions from disk, blit the larger image, then past it for
my frames array.

The first method, using SDL_CreateRBGSurface slow down the animation,
why?

Look at the attached files.

CU

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: tiles.cxx
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060829/24123bbe/attachment.txt
-------------- next part --------------
A non-text attachment was scrubbed…
Name: tiles.h
Type: text/x-chdr
Size: 1738 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060829/24123bbe/attachment.h

Hello !

I have used two methods to splilt a large image loaded from disk(whith
sprite images) into various frames of my SDL_Surface frames array. The
first one I create a empty surface whith SDL_CreateRGBSurface whith
dimensions of frames. Then i blit the large image with the calculated
offsets in this image, after this i use SDL_Display format to past the
image for a element of my array. The second is to load a template image
with frames dimensions from disk, blit the larger image, then past it
for my frames array.

The first method, using SDL_CreateRBGSurface slow down the animation,
why?

Look at the attached files.

Oh i forgott in this example to use SDL_DisplayFormat.
Remember that SDL_DisplayFormat creates a new surface
for the conv. surface. SDL_DisplayFormat and other things
should not be used when running the main loop of your game
for example. It should be used in the init routines.

CU

thanks…>From: “Torsten Giebl”

Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: "A list for developers using the SDL library. (includes
SDL-announce)"
Subject: Re: [SDL] SDL_CreateRGBSurface
Date: Tue, 29 Aug 2006 01:28:19 +0200 (CEST)

Hello !

I have used two methods to splilt a large image loaded from disk(whith
sprite images) into various frames of my SDL_Surface frames array. The
first one I create a empty surface whith SDL_CreateRGBSurface whith
dimensions of frames. Then i blit the large image with the calculated
offsets in this image, after this i use SDL_Display format to past the
image for a element of my array. The second is to load a template image
with frames dimensions from disk, blit the larger image, then past it
for
my frames array.

The first method, using SDL_CreateRBGSurface slow down the animation,
why?

Look at the attached files.

CU

<< tiles.cxx >>

<< tiles.h >>


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl