SDL_ConvertSurface losing information on alpha?

View: New views
17 Messages — Rating Filter:   Alert me  

SDL_ConvertSurface losing information on alpha?

by Vittorio G. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
i updated SDL to the latest version on Mac, and i came across the BGR/RGB conversion due to the switch to ImageIO in SDL_image.
I found this forum thread that explained very well what to do (even though is was for BMP while i use PNG):
http://www.idevgames.com/forum/showpost.php?p=85954&postcount=9

So i used SDL_ConvertSurface() to update the surface that is created from the IMG_Loda() with a proper pixel format
SDL_PixelFormat format = {NULL, 32, 4, 0, 0, 0, 0, 0, 8, 16, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000, 0, 255};
and normal images were loaded very well! However i noticed that every image that had transparency (eg. faded into the background) was no more transparent!
i've tried in any way i knew, but i couldn't make head or tails of this!

can anyone help me?
Thanks
Vittorio
--

Pablo Picasso  - "Computers are useless. They can only give you answers."
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL_ConvertSurface losing information on alpha?

by Sam Lantinga-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Did you try SDL_DisplayFormatAlpha() instead?

On Wed, Oct 21, 2009 at 8:35 PM, Vittorio G. <vitto.giova@...> wrote:

> Hello,
> i updated SDL to the latest version on Mac, and i came across the BGR/RGB
> conversion due to the switch to ImageIO in SDL_image.
> I found this forum thread that explained very well what to do (even though
> is was for BMP while i use PNG):
> http://www.idevgames.com/forum/showpost.php?p=85954&postcount=9
>
> So i used SDL_ConvertSurface() to update the surface that is created from
> the IMG_Loda() with a proper pixel format
>
> SDL_PixelFormat format = {NULL, 32, 4, 0, 0, 0, 0, 0, 8, 16, 24, 0x000000FF,
> 0x0000FF00, 0x00FF0000, 0xFF000000, 0, 255};
>
>
> and normal images were loaded very well! However i noticed that every image
> that had transparency (eg. faded into the background) was no more
> transparent!
> i've tried in any way i knew, but i couldn't make head or tails of this!
>
> can anyone help me?
> Thanks
> Vittorio
> --
>
> Pablo Picasso  - "Computers are useless. They can only give you answers."
> _______________________________________________
> SDL mailing list
> SDL@...
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>



--
        -Sam Lantinga, Founder and President, Galaxy Gameworks LLC
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL_ConvertSurface losing information on alpha?

by Vittorio G. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes i tried that but perhaps in a wrong way
here's what i tried

call SDL_ConvertSurface and then SDL_DisplayFormatAlpha -> switch again red and blue channels (wrong result)
directly call SDL_DisplayFormatAlpha -> the red and blue channel are not swapped (wrong result)
try to hack the format of the surface loaded with img_load, image.format= convertedFormat -> some very weird color distortion (wrong result)

plus in all three cases alpha was not applied
i could post images if needed
Vittorio

On Thu, Oct 22, 2009 at 6:49 AM, Sam Lantinga <slouken@...> wrote:
Did you try SDL_DisplayFormatAlpha() instead?

On Wed, Oct 21, 2009 at 8:35 PM, Vittorio G. <vitto.giova@...> wrote:
> Hello,
> i updated SDL to the latest version on Mac, and i came across the BGR/RGB
> conversion due to the switch to ImageIO in SDL_image.
> I found this forum thread that explained very well what to do (even though
> is was for BMP while i use PNG):
> http://www.idevgames.com/forum/showpost.php?p=85954&postcount=9
>
> So i used SDL_ConvertSurface() to update the surface that is created from
> the IMG_Loda() with a proper pixel format
>
> SDL_PixelFormat format = {NULL, 32, 4, 0, 0, 0, 0, 0, 8, 16, 24, 0x000000FF,
> 0x0000FF00, 0x00FF0000, 0xFF000000, 0, 255};
>
>
> and normal images were loaded very well! However i noticed that every image
> that had transparency (eg. faded into the background) was no more
> transparent!
> i've tried in any way i knew, but i couldn't make head or tails of this!
>
> can anyone help me?
> Thanks
> Vittorio
> --
>
> Pablo Picasso  - "Computers are useless. They can only give you answers."
> _______________________________________________
> SDL mailing list
> SDL@...
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>



--
       -Sam Lantinga, Founder and President, Galaxy Gameworks LLC
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



--

Joan Crawford  - "I, Joan Crawford, I believe in the dollar. Everything I earn, I spend."
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL_ConvertSurface losing information on alpha?

by Kenneth Bull :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

have you tried this?

SDL_Surface* tmp;
SDL_Surface* img;
SDL_PixelFormat f = {0};

SDL_PixelFormatEnumToMasks(
  SDL_ARRAYORDER_BGRA,  /* or SDL_ARRAYORDER_ABGR */
  &f.BitsPerPixel,
  &f.Rmask,
  &f.Gmask,
  &f.Bmask,
  &f.Amask
);
/* other format fields are ignored anyway for conversion */

tmp = IMG_Load("myimage.png");
img = SDL_ConvertSurface(tmp, f, 0);
SDL_FreeSurface(tmp);

/* do stuff with img... */
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL_ConvertSurface losing information on alpha?

by Vittorio G. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i was going to try it but then i discovered it was only for sdl 1.3
i need something compatible in both 1.2 and 1.3
what can i do?
vittorio

On Fri, Oct 23, 2009 at 5:07 AM, Kenneth Bull <llubnek@...> wrote:
have you tried this?

SDL_Surface* tmp;
SDL_Surface* img;
SDL_PixelFormat f = {0};

SDL_PixelFormatEnumToMasks(
 SDL_ARRAYORDER_BGRA,  /* or SDL_ARRAYORDER_ABGR */
 &f.BitsPerPixel,
 &f.Rmask,
 &f.Gmask,
 &f.Bmask,
 &f.Amask
);
/* other format fields are ignored anyway for conversion */

tmp = IMG_Load("myimage.png");
img = SDL_ConvertSurface(tmp, f, 0);
SDL_FreeSurface(tmp);

/* do stuff with img... */
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



--

Stephen Leacock  - "I detest life-insurance agents: they always argue that I shall some day die, which is not so."
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL_ConvertSurface losing information on alpha?

by Kenneth Bull :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/23 Vittorio G. <vitto.giova@...>:
> i was going to try it but then i discovered it was only for sdl 1.3
> i need something compatible in both 1.2 and 1.3
> what can i do?

If this doesn't work...

SDL_Surface* tmp;
SDL_Surface* img;

tmp = IMG_Load("myimage.png");
img = SDL_DisplayFormatAlpha(tmp);
SDL_FreeSurface(tmp);

/* do stuff with img */

... then check your source image, submit a bug report and use this temporarily:

Uint32 tmpmask;

tmpmask = img.format.Rmask;
img.format.Rmask = img.format.Bmask;
img.format.Bmask = tmpmask;

(and similar for loss and shift).

That is, if red and blue are swapped, swap them back.
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL_ConvertSurface losing information on alpha?

by Vittorio G. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've filed a bug here: http://bugzilla.libsdl.org/show_bug.cgi?id=868
we've discovered that basically alpha works only if alpha color is red... my suspect is that red and alpha channel get somehow swapped during blending
Vittorio

On Sat, Oct 24, 2009 at 2:22 AM, Kenneth Bull <llubnek@...> wrote:
2009/10/23 Vittorio G. <vitto.giova@...>:
> i was going to try it but then i discovered it was only for sdl 1.3
> i need something compatible in both 1.2 and 1.3
> what can i do?

If this doesn't work...

SDL_Surface* tmp;
SDL_Surface* img;

tmp = IMG_Load("myimage.png");
img = SDL_DisplayFormatAlpha(tmp);
SDL_FreeSurface(tmp);

/* do stuff with img */

.... then check your source image, submit a bug report and use this temporarily:

Uint32 tmpmask;

tmpmask = img.format.Rmask;
img.format.Rmask = img.format.Bmask;
img.format.Bmask = tmpmask;

(and similar for loss and shift).

That is, if red and blue are swapped, swap them back.
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--

Joan Crawford  - "I, Joan Crawford, I believe in the dollar. Everything I earn, I spend."
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL_ConvertSurface losing information on alpha?

by René Dudfield :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Oct 29, 2009 at 3:13 PM, Vittorio G. <vitto.giova@...> wrote:

> I've filed a bug here: http://bugzilla.libsdl.org/show_bug.cgi?id=868
> we've discovered that basically alpha works only if alpha color is red... my
> suspect is that red and alpha channel get somehow swapped during blending
> Vittorio
>
> On Sat, Oct 24, 2009 at 2:22 AM, Kenneth Bull <llubnek@...> wrote:
>>
>> 2009/10/23 Vittorio G. <vitto.giova@...>:
>> > i was going to try it but then i discovered it was only for sdl 1.3
>> > i need something compatible in both 1.2 and 1.3
>> > what can i do?
>>
>> If this doesn't work...
>>
>> SDL_Surface* tmp;
>> SDL_Surface* img;
>>
>> tmp = IMG_Load("myimage.png");
>> img = SDL_DisplayFormatAlpha(tmp);
>> SDL_FreeSurface(tmp);
>>
>> /* do stuff with img */
>>
>> .... then check your source image, submit a bug report and use this
>> temporarily:
>>
>> Uint32 tmpmask;
>>
>> tmpmask = img.format.Rmask;
>> img.format.Rmask = img.format.Bmask;
>> img.format.Bmask = tmpmask;
>>
>> (and similar for loss and shift).
>>
>> That is, if red and blue are swapped, swap them back.
>> _______________________________________________
>> SDL mailing list
>> SDL@...
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
>
>
>
> --
>
> Joan Crawford  - "I, Joan Crawford, I believe in the dollar. Everything I
> earn, I spend."
> _______________________________________________
> SDL mailing list
> SDL@...
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>

hi,

Is there a way to build using the normal SDL_image stuff on OSX?
Considering this bug, and for consistency with other platforms I'd
like to do that.

That is probably a good work around for it... if it's possible.

cu,
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL_ConvertSurface losing information on alpha?

by Vittorio G. :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

yes, you can still use the old backend but it's not a real solution
plus on the iphone you can't use other backends at all so the problem still applies

Vittorio

On Thu, Oct 29, 2009 at 7:34 PM, René Dudfield <renesd@...> wrote:
On Thu, Oct 29, 2009 at 3:13 PM, Vittorio G. <vitto.giova@...> wrote:
> I've filed a bug here: http://bugzilla.libsdl.org/show_bug.cgi?id=868
> we've discovered that basically alpha works only if alpha color is red... my
> suspect is that red and alpha channel get somehow swapped during blending
> Vittorio
>
> On Sat, Oct 24, 2009 at 2:22 AM, Kenneth Bull <llubnek@...> wrote:
>>
>> 2009/10/23 Vittorio G. <vitto.giova@...>:
>> > i was going to try it but then i discovered it was only for sdl 1.3
>> > i need something compatible in both 1.2 and 1.3
>> > what can i do?
>>
>> If this doesn't work...
>>
>> SDL_Surface* tmp;
>> SDL_Surface* img;
>>
>> tmp = IMG_Load("myimage.png");
>> img = SDL_DisplayFormatAlpha(tmp);
>> SDL_FreeSurface(tmp);
>>
>> /* do stuff with img */
>>
>> .... then check your source image, submit a bug report and use this
>> temporarily:
>>
>> Uint32 tmpmask;
>>
>> tmpmask = img.format.Rmask;
>> img.format.Rmask = img.format.Bmask;
>> img.format.Bmask = tmpmask;
>>
>> (and similar for loss and shift).
>>
>> That is, if red and blue are swapped, swap them back.
>> _______________________________________________
>> SDL mailing list
>> SDL@...
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
>
>
>
> --
>
> Joan Crawford  - "I, Joan Crawford, I believe in the dollar. Everything I
> earn, I spend."
> _______________________________________________
> SDL mailing list
> SDL@...
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>

hi,

Is there a way to build using the normal SDL_image stuff on OSX?
Considering this bug, and for consistency with other platforms I'd
like to do that.

That is probably a good work around for it... if it's possible.

cu,
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



--

Marie von Ebner-Eschenbach  - "Even a stopped clock is right twice a day."
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

using SDL_UserEvent with SDL_timer

by Leonel Florín Selles :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hello:

how can i call a function from a timer using a SDL_UserEvent, i know how this
work but what i don't know is how to connect the function to the SDL_UserEvent.



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

Parent Message unknown Re: SDL_ConvertSurface losing information on alpha?

by nemo-17 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.







René Dudfield wrote:
On Thu, Oct 29, 2009 at 3:13 PM, Vittorio G. <> wrote:







Quote:
I've filed a bug here: http://bugzilla.libsdl.org/show_bug.cgi?id=868
we've discovered that basically alpha works only if alpha color is red... my
suspect is that red and alpha channel get somehow swapped during blending
Vittorio


hi,

Is there a way to build using the normal SDL_image stuff on OSX?
Considering this bug, and for consistency with other platforms I'd
like to do that.

That is probably a good work around for it... if it's possible.

cu,


Hey. Turns out the problem was a bit weirder than someone simply messing up RGBA vs ABGR.
http://forums.libsdl.org/viewtopic.php?p=20011#20011

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

Re: using SDL_UserEvent with SDL_timer

by Bill Kendrick :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Oct 29, 2009 at 03:47:43PM -0500, Leonel Florín Selles wrote:
> hello:
>
> how can i call a function from a timer using a SDL_UserEvent, i know how this
> work but what i don't know is how to connect the function to the SDL_UserEvent.

In your event loop, you watch for events of type 'SDL_USEREVENT'.

If... I understand your question.  (Which I might not.)

--
-bill!
Sent from my computer
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: using SDL_UserEvent with SDL_timer

by Christopher Eineke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Leonel Florín Selles wrote:
> how can i call a function from a timer using a SDL_UserEvent, i know how this
> work but what i don't know is how to connect the function to the SDL_UserEvent.

There are two parts to this solution:

1. Set up the timer. When the timer fires, don't actually invoke the function in
the timer callback. Instead, you push an user event into the queue with a code
(SDL_UserEvent.code) that you somehow associate with the function that you want
to call. This schedules the actual work to be done for later. (The "hard IRQ.")
You could do this with a kind of manager module or #define's. (I'm not offering
judgment whether these are good methods or not.)

2. In your event loop, you check for user events. When you find one, examine its
code and call the function that you earlier identified, optionally with
parameters provided. (The "soft IRQ.")

This approach is similar to the top-half-bottom-half approach in operating
systems, where the top half "actually responds to the hardware interrupt and a
bottom half (or "soft" irq) that is scheduled by the top half to do additional
processing." (http://lwn.net/Articles/302043/)

- --
- -*- Christopher C. Eineke          -*- Email: chris@... -*-
- -*- Independent Software Developer -*- Cell:  1-519-852-3409        -*-
- -*-                                -*- Home:  1-226-663-3651        -*-
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEAREKAAYFAkrqHwQACgkQPOmqd0kEEbu4IgCgm7LDOpW5vCxW74Rzs3pgZj2r
nNQAoM665vSyP/xFrxgW/+usqHW3rUtl
=p4wL
-----END PGP SIGNATURE-----
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: using SDL_UserEvent with SDL_timer

by Leonel Florín Selles :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well friends, i'll going to repeat the question, I have a callback function
where I want to call an other function, and I want do that from SDL_UserEvent,
but what i know is that SDL_UserEvent is an structure that have 4 kind of data
or more

SDL_UserEvent -> type
SDL_UserEvent -> code
SDL_UserEvent -> void * data1
SDL_UserEvent -> void * data2

 and the last one i don't  remember, well how using this i can connect this
UserEvent with a function.



> On Thu, Oct 29, 2009 at 03:47:43PM -0500, Leonel Florín Selles wrote:
>> hello:
>>
>> how can i call a function from a timer using a SDL_UserEvent, i know how this
>> work but what i don't know is how to connect the function to the
>> SDL_UserEvent.
>
> In your event loop, you watch for events of type 'SDL_USEREVENT'.
>
> If... I understand your question.  (Which I might not.)
>
> --
> -bill!
> Sent from my computer
> _______________________________________________
> SDL mailing list
> SDL@...
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>


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

Re: using SDL_UserEvent with SDL_timer

by Christopher Eineke :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Leonel Florín Selles wrote:

> Well friends, i'll going to repeat the question, I have a callback function
> where I want to call an other function, and I want do that from SDL_UserEvent,
> but what i know is that SDL_UserEvent is an structure that have 4 kind of data
> or more
>
> SDL_UserEvent -> type
> SDL_UserEvent -> code
> SDL_UserEvent -> void * data1
> SDL_UserEvent -> void * data2
>
> and the last one i don't  remember, well how using this i can connect this
> UserEvent with a function.

In C, you may cast the pointer to the function to a void*, but you must ensure
that when you "recover" the pointer to the function its signature is the same
(see items 766-768 @ http://c0x.coding-guidelines.com/6.3.2.3.html):

#include <stdio.h>
int foo(int bar) { return bar; }
int main()
{
        void* function = &foo;
        int (*fooz)(int) = function;
        printf("3 == %d\n", fooz(3));
        return 0;
}

In C++, you need to add the (in-)appropriate casts:
#include <stdio.h>
int foo(int bar) { return bar; }
int main()
{
        void* function = reinterpret_cast<void*>(&foo);
        int (*fooz)(int) = reinterpret_cast<int (*)(int)>(function);
        printf("3 == %d\n", fooz(3));
        return 0;
}

But that's like sledgehammering a rose petal. You're completely foregoing type
safety and it's a nightmare to debug. And on-top, it doesn't work for class methods.

One approach is to store instances that adhere to an interface in a vector
somewhere:

#include <vector>
struct IEvtCB
{
        virtual int bar(void*, void*) = 0;
};
struct EvtCB_1 : public IEvtCB
{
        virtual int foo(void*, void*) { return bar; }
};

std::vector<EvtCB_1*> vec;

int main()
{
        vec.push_back(new EvtCB_1());
        return 0;
}

then find the corresponding instance in the vector and invoke the the method in
question:

/* ... */

if (evt.type == SDL_USEREVENT) {
    if (evt.user.code > -1) {
        IEvtCB& cb = vec[evt.user.code];
        int ret = cb.bar(evt.user.data1, evt.user.data2);
    }
    else {
        /* something's amiss */
    }
}

/* ... */

Another way is to use a functor (google it) that encapsulates the function or
method call and that you can then store in data1 or data2 and cast back to a
functor later on.

- --
- -*- Christopher C. Eineke          -*- Email: chris@... -*-
- -*- Independent Software Developer -*- Cell:  1-519-852-3409        -*-
- -*-                                -*- Home:  1-226-663-3651        -*-
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEAREKAAYFAkrqWhgACgkQPOmqd0kEEbtvAwCgpVEFBdecm+I97Xc1Dym6bwvZ
J2gAoIv9191GdGVU3n1veJhYRjx2q5Kz
=Zexz
-----END PGP SIGNATURE-----
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: using SDL_UserEvent with SDL_timer

by masonwheeler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>----- Original Message ----

>From: Christopher Eineke <chris@...>
>Subject: Re: [SDL] using SDL_UserEvent with SDL_timer
>
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA512
>
>Leonel Florín Selles wrote:
>> Well friends, i'll going to repeat the question, I have a callback function
>> where I want to call an other function, and I want do that from SDL_UserEvent,
>> but what i know is that SDL_UserEvent is an structure that have 4 kind of data
>> or more
>>
>> SDL_UserEvent -> type
>> SDL_UserEvent -> code
>> SDL_UserEvent -> void * data1
>> SDL_UserEvent -> void * data2
>>
>> and the last one i don't  remember, well how using this i can connect this
>> UserEvent with a function.
>
>In C, you may cast the pointer to the function to a void*, but you must ensure
>that when you "recover" the pointer to the function its signature is the same
>(see items 766-768 @ http://c0x.coding-guidelines.com/6.3.2.3.html):
> <SNIP>
>In C++, you need to add the (in-)appropriate casts:
> <SNIP>
>But that's like sledgehammering a rose petal. You're completely foregoing type
>safety and it's a nightmare to debug. And on-top, it doesn't work for class methods.

Hmm.  In Delphi, a method pointer is represented by a record (struct) composed of
two pointers: one to the function and one to the object instance.  I notice the
SDL_UserEvent struct here has two miscellaneous data pointers for general
use.  I don't know too much about C++ method pointers, but is there any way
you could use them for that purpose?
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: using SDL_UserEvent with SDL_timer

by Brian Barrett :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

C++ member function pointers are tricky beasts. For one thing, they
aren't required to be the same size as a void pointer. In fact, they
often *are* 8 or 16 bytes on 32 bit compilers. You can wrap them in a
struct with a virtual function, and use template hackery to generate
the boilerplate (or use boost::function<>). For simpler tasks, you can
wrap the member function in a free function:

template<class T, void (T::*function)()>
void wrapper( T *instance)
{

   ((instance) ->* (function)) ();
}

This would require more work to support varying return types and
parameters, but for one or two of each it might be a simpler
alternative to boost::function.

Still, technically I believe casting any function to void * is
illegal, at least in C++:
http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.8


On Fri, Oct 30, 2009 at 3:33 AM, Mason Wheeler <masonwheeler@...> wrote:
>
> Hmm.  In Delphi, a method pointer is represented by a record (struct) composed of
> two pointers: one to the function and one to the object instance.  I notice the
> SDL_UserEvent struct here has two miscellaneous data pointers for general
> use.  I don't know too much about C++ method pointers, but is there any way
> you could use them for that purpose?
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org