About SDL_Draw library

I am reading the source code of SDL_draw library,here is the prototype
of Draw_Pixel function:

void Draw_Pixel(SDL_Surface *super,
Sint16 x, Sint16 y,
Uint32 color);

But I can’t find the implement of this function.
I can only find a function pointer of Draw_Pixel :

extern DECLSPEC
void (*Draw_Pixel)(SDL_Surface *super,
Sint16 x, Sint16 y, Uint32 color);

this is just a definition of Draw_Pixel(variable) ,isn’t it?

Anyone can help me?

Regards!

/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/

Do you just want pixel access functions (I don’t know what else
SDL_Draw can do), use the functions here from the SDL documentation:
http://www.libsdl.org/cgi/docwiki.cgi/Pixel_20AccessOn 09/10/2007, cocobear <cocobear.cn at gmail.com> wrote:

I am reading the source code of SDL_draw library,here is the prototype
of Draw_Pixel function:

void Draw_Pixel(SDL_Surface *super,
Sint16 x, Sint16 y,
Uint32 color);

But I can’t find the implement of this function.
I can only find a function pointer of Draw_Pixel :

extern DECLSPEC
void (*Draw_Pixel)(SDL_Surface *super,
Sint16 x, Sint16 y, Uint32 color);

this is just a definition of Draw_Pixel(variable) ,isn’t it?

Anyone can help me?

Regards!

/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/


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

Hi there, Coco.

If you’d like to see the source for Draw_Pixel, you’ll have to download the source from SourceForge. What you see there probably won’t make you happy. The Draw_Pixel function, like all the rest in SDL_Draw, is a mess of macros. Like that other guy said, if you really want a pixel function, check the one in the SDL docs.

Jonny D> Date: Tue, 9 Oct 2007 22:55:36 +0800> To: sdl at lists.libsdl.org> From: cocobear.cn at gmail.com> Subject: [SDL] About SDL_Draw library> > I am reading the source code of SDL_draw library,here is the prototype> of Draw_Pixel function:> > void Draw_Pixel(SDL_Surface *super,> Sint16 x, Sint16 y, > Uint32 color);> > But I can’t find the implement of this function.> I can only find a function pointer of Draw_Pixel :> > extern DECLSPEC> void (*Draw_Pixel)(SDL_Surface super,> Sint16 x, Sint16 y, Uint32 color);> > this is just a definition of Draw_Pixel(variable) ,isn’t it?> > Anyone can help me?> > > Regards!> > /> *Welcome to cocobear’s home!> *http://cocobear.cn> */> _______________________________________________> SDL mailing list> SDL at lists.libsdl.org> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Climb to the top of the charts!? Play Star Shuffle:? the word scramble challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_oct

Yes. Where did you find that? in SDL_draw.c, I see[1]

68 void (*Draw_Pixel)(SDL_Surface *super,
69 Sint16 x, Sint16 y, Uint32 color) = Draw_Pixel_Init;

So calling “Draw_Pixel” the first time actually

* dereferences the Draw_Pixel pointer
* calls Draw_Pixel_Init()
	* calls Draw_Init
		* re-assigns the Draw_Pixel pointer to a
		  function specific to your bit-depth, e.g.
		  Draw_Pixel_4
	* re-calls Draw_Pixel (involves a dereference)
* re-calls Draw_Pixel (involves a dereference)

This seems to be a way of avoiding the user of the library (I.e. you)
having to call an initialisation function before using the methods.

It’s also buggy, if I’ve read this correctly, drawing the first pixel
you specify twice.

It also means that each call to Draw_Pixel has an extra bit of
indirection involved over a normal function call. I did some tests a
while ago to see which is faster: the function-pointer based approach to
specifying a colourdepth-specific draw function or the switch-based that
is in the SDL docs. I was suprised to find that for small-medium numbers
of calls, the switch-based tended to be faster in my environment, with
the function-pointer method pulling ahead only once you are calling the
putpixel method millions of times in succession, certainly, many times
more than there were pixels in my surface (which I imagine no real-world
app will do)

[1]
http://sdl-draw.cvs.sourceforge.net/sdl-draw/sdl-draw/src/SDL_draw.c?view=markupOn Tue, Oct 09, 2007 at 10:55:36PM +0800, cocobear wrote:

I am reading the source code of SDL_draw library,here is the prototype
of Draw_Pixel function:

void Draw_Pixel(SDL_Surface *super,
Sint16 x, Sint16 y,
Uint32 color);

But I can’t find the implement of this function.
I can only find a function pointer of Draw_Pixel :

extern DECLSPEC
void (*Draw_Pixel)(SDL_Surface *super,
Sint16 x, Sint16 y, Uint32 color);

this is just a definition of Draw_Pixel(variable) ,isn’t it?


Jon Dowland

That’s a pointer to a function rather than a function in and of itself.
The functions themselves (which may be chosen based on colour depth or
compile-time directives such as endianness) will be in another file in
the source code.On Tue, 2007-10-09 at 22:55 +0800, cocobear wrote:

extern DECLSPEC
void (*Draw_Pixel)(SDL_Surface *super,
Sint16 x, Sint16 y, Uint32 color);


All new Yahoo! Mail “The new Interface is stunning in its simplicity and ease of use.” - PC Magazine
http://uk.docs.yahoo.com/nowyoucan.html

? Thu, 11 Oct 2007 15:28:34 +0100
Jon Dowland ??:

I am reading the source code of SDL_draw library,here is the
prototype of Draw_Pixel function:

void Draw_Pixel(SDL_Surface *super,
Sint16 x, Sint16 y,
Uint32 color);

But I can’t find the implement of this function.
I can only find a function pointer of Draw_Pixel :

extern DECLSPEC
void (*Draw_Pixel)(SDL_Surface *super,
Sint16 x, Sint16 y, Uint32 color);

this is just a definition of Draw_Pixel(variable) ,isn’t it?

Yes. Where did you find that? in SDL_draw.c, I see[1]

I find it in: SDL_draw.h line 35.

68 void (*Draw_Pixel)(SDL_Surface *super,
69 Sint16 x, Sint16 y, Uint32 color) =
Draw_Pixel_Init;

So calling “Draw_Pixel” the first time actually

  • dereferences the Draw_Pixel pointer
  • calls Draw_Pixel_Init()
    • calls Draw_Init
      • re-assigns the Draw_Pixel pointer to a
        function specific to your bit-depth, e.g.
        Draw_Pixel_4
    • re-calls Draw_Pixel (involves a dereference)
  • re-calls Draw_Pixel (involves a dereference)

This seems to be a way of avoiding the user of the library (I.e. you)
having to call an initialisation function before using the methods.

It’s also buggy, if I’ve read this correctly, drawing the first pixel
you specify twice.

static
void Draw_Pixel_Init(SDL_Surface *super,
Sint16 x, Sint16 y, Uint32 color)
{
Draw_Init();
Draw_Pixel(super, x, y, color);
}

void (*Draw_Pixel)(SDL_Surface *super,
Sint16 x, Sint16 y, Uint32 color) = Draw_Pixel_Init;

Draw_Pixel is a pointer of Draw_Pixel_Init function,but
Draw_Pixel_Init use Draw_Pixel too.

Do you mean it is a bug?

It also means that each call to Draw_Pixel has an extra bit of
indirection involved over a normal function call. I did some tests a
while ago to see which is faster: the function-pointer based approach
to specifying a colourdepth-specific draw function or the
switch-based that is in the SDL docs. I was suprised to find that for
small-medium numbers of calls, the switch-based tended to be faster
in my environment, with the function-pointer method pulling ahead
only once you are calling the putpixel method millions of times in
succession, certainly, many times more than there were pixels in my
surface (which I imagine no real-world app will do)

[1]
http://sdl-draw.cvs.sourceforge.net/sdl-draw/sdl-draw/src/SDL_draw.c?view=markup

It seemed that this library use so many macro,and I spend a lot of time
to understand it.

Regards!

/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/> On Tue, Oct 09, 2007 at 10:55:36PM +0800, cocobear wrote:

? Thu, 11 Oct 2007 20:06:11 +0100
Paul Duffy ??:

extern DECLSPEC
void (*Draw_Pixel)(SDL_Surface *super,
Sint16 x, Sint16 y, Uint32 color);

That’s a pointer to a function rather than a function in and of
itself. The functions themselves (which may be chosen based on colour
depth or compile-time directives such as endianness) will be in
another file in the source code.

I can only find Draw_Pixel as a variable in the source code.


All new Yahoo! Mail “The new Interface is stunning in its simplicity
and ease of use.” - PC Magazine
http://uk.docs.yahoo.com/nowyoucan.html
_______________________________________________ SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Regards!

/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/> On Tue, 2007-10-09 at 22:55 +0800, cocobear wrote:

? Tue, 9 Oct 2007 17:42:14 +0100
Brian <brian.ripoff at gmail.com> ??:

Do you just want pixel access functions (I don’t know what else
SDL_Draw can do), use the functions here from the SDL documentation:
http://www.libsdl.org/cgi/docwiki.cgi/Pixel_20Access

SDL_Draw can do other things, like draw a circle etc.
Acutally I want to learn the way of SDL_Draw library implement this
functions.

thanks for your url, it is useful.> On 09/10/2007, cocobear <@cocobear> wrote:

I am reading the source code of SDL_draw library,here is the
prototype of Draw_Pixel function:

void Draw_Pixel(SDL_Surface *super,
Sint16 x, Sint16 y,
Uint32 color);

But I can’t find the implement of this function.
I can only find a function pointer of Draw_Pixel :

extern DECLSPEC
void (*Draw_Pixel)(SDL_Surface *super,
Sint16 x, Sint16 y, Uint32 color);

this is just a definition of Draw_Pixel(variable) ,isn’t it?

Anyone can help me?

Regards!

/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/


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

Regards!

/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/

? Wed, 10 Oct 2007 22:13:24 -0400
Jonathan Dearborn ??:

Hi there, Coco.

If you’d like to see the source for Draw_Pixel, you’ll have to
download the source from SourceForge. What you see there probably
won’t make you happy. The Draw_Pixel function, like all the rest in
SDL_Draw, is a mess of macros. Like that other guy said, if you
really want a pixel function, check the one in the SDL docs. Jonny D

Thanks for you advice.
I had download the source code from SourceForge before.

mess of macros, I think so too :slight_smile:

I am reading the source code of SDL_draw library,here is the
prototype> of Draw_Pixel function:> > void Draw_Pixel(SDL_Surface
prototype> *super,> Sint16 x, Sint16 y, > Uint32 color);> > But I
prototype> can’t find the implement of this function.> I can only
prototype> find a function pointer of Draw_Pixel :> > extern
prototype> DECLSPEC> void (*Draw_Pixel)(SDL_Surface super,>
prototype> DECLSPEC> Sint16 x, Sint16 y, Uint32 color);> > this
prototype> DECLSPEC> is just a definition of
prototype> DECLSPEC> Draw_Pixel(variable) ,isn’t it?> > Anyone
prototype> DECLSPEC> can help me?> > > Regards!> > /
> *Welcome
prototype> DECLSPEC> to cocobear’s home!> *http://cocobear.cn>
prototype> DECLSPEC> */>
prototype> DECLSPEC> _______________________________________________>
prototype> DECLSPEC> SDL mailing list> SDL at lists.libsdl.org>
prototype> DECLSPEC> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Climb to the top of the charts!? Play Star Shuffle:? the word
scramble challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_oct

Regards!

/*
*Welcome to cocobear’s home!
*http://cocobear.cn
*/> > Date: Tue, 9 Oct 2007 22:55:36 +0800> To: sdl at lists.libsdl.org>

From: @cocobear> Subject: [SDL] About SDL_Draw library>

That is ok; I mistakenly thought that Draw_Pixel was called twice as
part of the initial stuff, but it seems only once after all.On Fri, Oct 12, 2007 at 12:32:39PM +0800, cocobear wrote:

Draw_Pixel is a pointer of Draw_Pixel_Init function,but
Draw_Pixel_Init use Draw_Pixel too.

Do you mean it is a bug?


Jon Dowland