A little doubt

Hello;

I want to create a empty SDL surface, with this code:

int Guardian;
unsigned int rmask, gmask, bmask, amask;

SDL_Surface *mapa1;

rmask = 0xffffffff;
gmask = 0x00000000;
bmask = 0xffff0000;
amask = 0x00ffff00;

/* Code for init SDL in 640x480x16, it runs */

mapa1=SDL_CreateRGBSurface(SDL_SRCCOLORKEY,100,100,16,rmask,gmask,bmask,amask);
if (mapa1==NULL)
{
	printf("\nCreando mapa1 ERROR\n");
} else {
	printf("\nCreando mapa1 OK\n");
}
Guardian=SDL_BlitSurface(mapa1,NULL,screen,NULL);
if (Guardian==0)
{
	printf("\nCopiando imagen OK");
} else {
	printf("\nCopiando imagen ERROR");
}

Guardian=SDL_Flip(screen);
if (Guardian==0)
{
	printf("\nUpdate de screen OK");
} else {
	printf("\nUpdate de screen ERROR");
}

I cant see anything in screen and all messages are of OK. ?Any idea? :?

These look kind of… odd. Where did you come up with this RGBA mask values???

-bill!On Tue, May 10, 2005 at 09:46:05PM +0000, ALTAIR - wrote:

Hello;

I want to create a empty SDL surface, with this code:

int Guardian;
unsigned int rmask, gmask, bmask, amask;

SDL_Surface *mapa1;

rmask = 0xffffffff;
gmask = 0x00000000;
bmask = 0xffff0000;
amask = 0x00ffff00;

I want to create a empty SDL surface, with this code:
I cant see anything in screen and all messages are of OK. ?Any idea? :?

The masks don’t make much sense, unless you’re trying to do something
particularly weird. In general, the “1” bits of each mask should be "0"
in every other mask - put it another way, the AND of any two mask should
be exactly 0. Unless you really have bits which represent the intensity
of two channels.

For example, use R = 0xFF000000, G = 0x00FF0000, B = 0x0000FF00, A =
0x000000FF

Besides, even if you init the image correctly, it’s still an empty (ie
black) image. How do you know that you “can’t see anything on the
screen” if you’re drawing a black rectangle over a black background?

Now I think about it, do you know what the masks mean? They do NOT
represent a color, if that’s what you thought your code did.

    --Gabriel

Are NOT a color??

I don’t understand this. In the manual, I read:

SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int
depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);

Okay, and I searching in Google about this, a example page:

http://www.agali.org/javielinux/articulos/sdln2/sdl-n2/x225.html

How I can create a red surface, by example? :?>From: Gabriel

Reply-To: “A list for developers using the SDL library.
(includesSDL-announce)”
To: SDL Mailing List
Subject: Re: [SDL] A little doubt
Date: Tue, 10 May 2005 20:13:46 -0300

    I want to create a empty SDL surface, with this code:
    I cant see anything in screen and all messages are of OK. ?Any 

idea? :?

The masks don’t make much sense, unless you’re trying to do something
particularly weird. In general, the “1” bits of each mask should be "0"
in every other mask - put it another way, the AND of any two mask should
be exactly 0. Unless you really have bits which represent the intensity
of two channels.

For example, use R = 0xFF000000, G = 0x00FF0000, B = 0x0000FF00, A =
0x000000FF

Besides, even if you init the image correctly, it’s still an empty (ie
black) image. How do you know that you “can’t see anything on the
screen” if you’re drawing a black rectangle over a black background?

Now I think about it, do you know what the masks mean? They do NOT
represent a color, if that’s what you thought your code did.

    --Gabriel

Only an example what I found in the web. Download some game examples of the
SDL site, but I not found a example.>From: Bill Kendrick

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] A little doubt
Date: Tue, 10 May 2005 15:40:41 -0700

On Tue, May 10, 2005 at 09:46:05PM +0000, ALTAIR - wrote:

Hello;

I want to create a empty SDL surface, with this code:

int Guardian;
unsigned int rmask, gmask, bmask, amask;

SDL_Surface *mapa1;

rmask = 0xffffffff;
gmask = 0x00000000;
bmask = 0xffff0000;
amask = 0x00ffff00;

These look kind of… odd. Where did you come up with this RGBA mask
values???

-bill!


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

hello,

I am not an expert, and I dont understand 16 but surfaces and mask values.
My understanding of SDL_CreateRGBSurface is it fills the surface with 0’s.
So if your screen is black, you cannot diffrentiate between screen and
mapa1.
Fill something in mapa1 using SDL_FillRect() and then try.> ----- Original Message -----

From: sdl-bounces+admin=windows-games.com@libsdl.org
[mailto:sdl-bounces+admin=windows-games.com at libsdl.org]On Behalf Of
ALTAIR -
Sent: Wednesday, May 11, 2005 3:16 AM
To: sdl at libsdl.org
Subject: [SDL] A little doubt

Hello;

I want to create a empty SDL surface, with this code:

int Guardian;
unsigned int rmask, gmask, bmask, amask;

SDL_Surface *mapa1;

rmask = 0xffffffff;
gmask = 0x00000000;
bmask = 0xffff0000;
amask = 0x00ffff00;

/* Code for init SDL in 640x480x16, it runs */

mapa1=SDL_CreateRGBSurface(SDL_SRCCOLORKEY,100,100,16,rmask,gmask,bmask,amas
k);
if (mapa1==NULL)
{
printf("\nCreando mapa1 ERROR\n");
} else {
printf("\nCreando mapa1 OK\n");
}
Guardian=SDL_BlitSurface(mapa1,NULL,screen,NULL);
if (Guardian==0)
{
printf("\nCopiando imagen OK");
} else {
printf("\nCopiando imagen ERROR");
}

Guardian=SDL_Flip(screen);
if (Guardian==0)
{
printf("\nUpdate de screen OK");
} else {
printf("\nUpdate de screen ERROR");
}

I cant see anything in screen and all messages are of OK. ?Any idea? :?


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

Are NOT a color??

Nope. They’re masks, describing how each channel (R, G, B and A) are
stored inside a pixel. That is, in this case, they describe the pixel
format of the new surface.

I don’t understand this. In the manual, I read:

SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int
height, int
depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);

Okay, and I searching in Google about this, a example page:

http://www.agali.org/javielinux/articulos/sdln2/sdl-n2/x225.html

How I can create a red surface, by example? :?

You can’t; not using only SDL_CreateRGBSurface().

First create a surface (which is black by default), and then fill it
with whatever color you want using SDL_FillRect().

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Wednesday 11 May 2005 07.15, ALTAIR - wrote:

Are NOT a color??
I don’t understand this. In the manual, I read:
SDL_Surface *SDL_CreateRGBSurface(Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);

No. They are a “mask”, in the binary sense. RGB colors are actually a 3-
member struct, usually with 8 bits per channel. So you have 1 byte for
each of red, green and blue.

It’s convenient to pack these 3 bytes in a 32 bit value to pass it
around instead of passing 3 or 4 values. But there are many ways to pack
the color - for example, the highest byte could be red, or it could be
green or blue.

You have to describe to SDL how do you want them packed. For example,
say you want to pack it as 0xRRGGBB00. This means the most significant
byte is red. You tell SDL that by saying that the red mask is
0xFF000000. When SDL wants the red channel, it does Color & RedMask
which in this case is 0xRRGGBB00 & 0xFF000000 = 0xRR000000, counts the
number of bits in the mask and shifts the value to give you back 0xRR.

This is why I said your mask 1 bits can’t overlap. Each bit in the
packed color should belong go only one channel.

How I can create a red surface, by example? :?

You create a black surface and use SDL_FillRect() to make it red.

    --Gabriel

Okay, and I searching in Google about this, a example page:

http://www.agali.org/javielinux/articulos/sdln2/sdl-n2/x225.html

The example looks alright:

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

But perhaps the description isn’t so clear.

Rmask: color rojo.
Gmask: color verde.
Bmask: color azul.
Amask: transparencia.

It seems to imply that those values represent the color, rather than
the color mask.

How I can create a red surface, by example? :?

Once you create the surface correctly (go back to that example code, and
use it, but don’t try to change it ;^) ), use SDL_FillRect() like so:

SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 0xFF, 0x00, 0x00));

The “NULL” here simply tells SDL_FillRect(), “I’m not giving you an SDL_Rect
to tell you were to put the filled rectangle… I want you to just fill the
entire surface.”

In a sense, it’s similar to:

SDL_Rect dest;

dest.x = 0;
dest.y = 0;
dest.w = surface->w;
dest.h = surface->h;

SDL_FillRect(surface, &dest, SDL_MapRGB…

I hope that helps!On Wed, May 11, 2005 at 05:15:30AM +0000, ALTAIR - wrote:


-bill!
bill at newbreedsoftware.com
http://newbreedsoftware.com/