Using SDL under mac os

Hello!

I want to show the picture on the fixed window which is not SDL creating.

For Win32 ,we can use the SDL_putenv() method to implement it.

But under mac os ,how can we implement it?

Thank you!

But under mac os ,how can we implement it?

You can’t in 1.2.14. In 1.2.13, you can do it with an NSQuickDrawView
(we had to remove the functionality due to Snow Leopard.)

–ryan.

hello again friends:

well now I have a problem with threads, the point is that I have a class that
handles a thread, and when I send to the function SDL_Thread
*SDL_CreateThread(int (*fn)(void *), void *data); his first argument that is the
funtion that I want as a threads I get an error message, telling me this

error: argument of type ‘int (Cpacman::)(void*)’ does not match ‘int ()(void)’

I understand what means that message, but i don’t know how to made the
conversion, because the funtion that I’m sending is a class method and
SDL_CreateThread need a function, not a method of a class, I don’t know if I
make myself clear.

but if anyone knows what I mean, please tell me how to solve this problem.

greetings.

You can’t pass pointer to a class method function this way unless this method
is static. Method is connected to specific class instance, how would the
thread function know from which object it should be called?On Tuesday 27 October 2009 00:30:39 Leonel Flor?n Selles wrote:

error: argument of type ‘int (Cpacman::)(void*)’ does not match ‘int
()(void)’

I understand what means that message, but i don’t know how to made the
conversion, because the funtion that I’m sending is a class method and
SDL_CreateThread need a function, not a method of a class, I don’t know if
I make myself clear.


Regards Havner {jid,mail}:havner(at)pld-linux.org
"Quis custodiet ipsos custodes?"

Ryan C. Gordon wrote:

But under mac os ,how can we implement it?

You can’t in 1.2.14. In 1.2.13, you can do it with an NSQuickDrawView
(we had to remove the functionality due to Snow Leopard.)

–ryan.


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

Thanks for your reply

Ryan C. Gordon wrote:

But under mac os ,how can we implement it?

You can’t in 1.2.14. In 1.2.13, you can do it with an NSQuickDrawView
(we had to remove the functionality due to Snow Leopard.)

–ryan.


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

I have tried.But I can’t realeze it.Can you tell me detailedlyI want to play video by SDL on the fixed window ,not the SDL creating.

Ryan C. Gordon wrote:

But under mac os ,how can we implement it?

You can’t in 1.2.14. In 1.2.13, you can do it with an NSQuickDrawView
(we had to remove the functionality due to Snow Leopard.)

–ryan.


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

I have tried.But I can’t realeze it.Can you tell me detailedlyI want to play video by SDL on the fixed window ,not the SDL creating.

Ryan C. Gordon wrote:

But under mac os ,how can we implement it?

You can’t in 1.2.14. In 1.2.13, you can do it with an NSQuickDrawView
(we had to remove the functionality due to Snow Leopard.)

–ryan.


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

I have tried.But I can’t realeze it.Can you tell me detailedlyI want to play video by SDL on the fixed window ,not the SDL creating.

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

Leonel Flor?n Selles wrote:

hello again friends:

well now I have a problem with threads, the point is that I have a class that
handles a thread, and when I send to the function SDL_Thread
*SDL_CreateThread(int (*fn)(void *), void *data); his first argument that is the
funtion that I want as a threads I get an error message, telling me this

error: argument of type ‘int (Cpacman::)(void*)’ does not match ‘int ()(void)’

I understand what means that message, but i don’t know how to made the
conversion, because the funtion that I’m sending is a class method and
SDL_CreateThread need a function, not a method of a class, I don’t know if I
make myself clear.

Hello Leonel,

Yes, you’re making yourself clear. You’re wondering how a class method can be
cast to a regular function.

Unfortunately, unless the function is declared static (that is, ye ol’ regular
function that isn’t passed a pointer to a class instance) you won’t be able to.
One technique I use in my C++ wrapper is to declare a static pointer to the
instance and a static member function. The function bounces the call to the
instance:

class Thread_handler
{
Thread_handler()
{
if (Instance != 0) {
throw Singleton_exception(“Tried to instantiate class more than once.”);
}
/* construct here */

Instance = this;

}

static int Thread_callback_trampoline(void* data)
{
assert(Instance != 0);
return Instance->thread_callback(data);
}

static Thread_handler* Instance;
}

Then you can register it with
SDL_CreateThread(&Thread_handler::Thread_callback_trampoline, …);

Hope that helped.

CE


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

iEYEAREKAAYFAkrmWBAACgkQPOmqd0kEEbtYggCgw2K412vt90RezbmbOS0gYEk8
KaYAoJWkzUPlvbmcQqhF/o/ivJIqF5I7
=J3QQ
-----END PGP SIGNATURE-----

Or you can just pass /this/ as the parameter to the thread:

SDL_CreateThread(ThreadFunc, (void*)this);

ThreadFunc must be declared as

static int ThreadFunc(void* data)
{
Cpacman* instance = (Cpacman*)data;
// use /instance/ here as it were /this/

return 0; // or whatever you want to return
}

If you need to pass more data to ThreadFunc, create a structure to hold
/this/ and the additional data.

Cheers,

Andre

Christopher Eineke wrote:> -----BEGIN PGP SIGNED MESSAGE-----

Hash: SHA512

Leonel Flor?n Selles wrote:

hello again friends:

well now I have a problem with threads, the point is that I have a class that
handles a thread, and when I send to the function SDL_Thread
*SDL_CreateThread(int (*fn)(void *), void *data); his first argument that is the
funtion that I want as a threads I get an error message, telling me this

error: argument of type ‘int (Cpacman::)(void*)’ does not match ‘int ()(void)’

I understand what means that message, but i don’t know how to made the
conversion, because the funtion that I’m sending is a class method and
SDL_CreateThread need a function, not a method of a class, I don’t know if I
make myself clear.

Hello Leonel,

Yes, you’re making yourself clear. You’re wondering how a class method can be
cast to a regular function.

Unfortunately, unless the function is declared static (that is, ye ol’ regular
function that isn’t passed a pointer to a class instance) you won’t be able to.
One technique I use in my C++ wrapper is to declare a static pointer to the
instance and a static member function. The function bounces the call to the
instance:

class Thread_handler
{
Thread_handler()
{
if (Instance != 0) {
throw Singleton_exception(“Tried to instantiate class more than once.”);
}
/* construct here */

Instance = this;

}

static int Thread_callback_trampoline(void* data)
{
assert(Instance != 0);
return Instance->thread_callback(data);
}

static Thread_handler* Instance;
}

Then you can register it with
SDL_CreateThread(&Thread_handler::Thread_callback_trampoline, …);

Hope that helped.

CE


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

iEYEAREKAAYFAkrmWBAACgkQPOmqd0kEEbtYggCgw2K412vt90RezbmbOS0gYEk8
KaYAoJWkzUPlvbmcQqhF/o/ivJIqF5I7
=J3QQ
-----END PGP SIGNATURE-----


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

You’re trying to pass a C++ method as a function pointer; unless it’s a
class method, that’s not going to work (there won’t be a 'this’
pointer). You need to define a C helper function, something like this:

extern “C” int call_helper( void *obj );

int call_helper( void obj )
{
Cpacman
instance = static_cast<Cpacman*>( obj );
instance->TheMethodYouWanted();
return 0;
}

Then create the thread thusly:

SDL_Thread* tid = SDL_CreateThread( call_helper, static_cast<void*>(
myCpacman ) );

Note that it’s been years since I touched C++, so my use of static_cast
might be way off… the general idea should be correct though.On 09-10-26 7:30 PM, Leonel Flor?n Selles wrote:

hello again friends:

well now I have a problem with threads, the point is that I have a class that
handles a thread, and when I send to the function SDL_Thread
*SDL_CreateThread(int (*fn)(void *), void *data); his first argument that is the
funtion that I want as a threads I get an error message, telling me this

error: argument of type ‘int (Cpacman::)(void*)’ does not match ‘int ()(void)’


Chris Herborth (@Chris_Herborth) – http://www.pobox.com/~chrish/
Marooned, the survival game! – http://marooned-game.livejournal.com/
Never send a monster to do the work of an evil scientist.

-------------- next part --------------
A non-text attachment was scrubbed…
Name: chrish.vcf
Type: text/x-vcard
Size: 386 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20091027/6bb9f087/attachment.vcf

thanks friends for the help you have given me, special to Christopher C. Eineke
and Andre de Leiradella, and a thanks for Chris Herborth too.

I had resolve me problem. thanks you.> Or you can just pass /this/ as the parameter to the thread:

SDL_CreateThread(ThreadFunc, (void*)this);

ThreadFunc must be declared as

static int ThreadFunc(void* data)
{
Cpacman* instance = (Cpacman*)data;
// use /instance/ here as it were /this/

return 0; // or whatever you want to return
}

If you need to pass more data to ThreadFunc, create a structure to hold
/this/ and the additional data.

Cheers,

Andre

Christopher Eineke wrote:

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

Leonel Flor?n Selles wrote:

hello again friends:

well now I have a problem with threads, the point is that I have a class that
handles a thread, and when I send to the function SDL_Thread
*SDL_CreateThread(int (*fn)(void *), void *data); his first argument that is
the
funtion that I want as a threads I get an error message, telling me this

error: argument of type ‘int (Cpacman::)(void*)’ does not match ‘int
()(void)’

I understand what means that message, but i don’t know how to made the
conversion, because the funtion that I’m sending is a class method and
SDL_CreateThread need a function, not a method of a class, I don’t know if I
make myself clear.

Hello Leonel,

Yes, you’re making yourself clear. You’re wondering how a class method can be
cast to a regular function.

Unfortunately, unless the function is declared static (that is, ye ol’ regular
function that isn’t passed a pointer to a class instance) you won’t be able
to.
One technique I use in my C++ wrapper is to declare a static pointer to the
instance and a static member function. The function bounces the call to the
instance:

class Thread_handler
{
Thread_handler()
{
if (Instance != 0) {
throw Singleton_exception(“Tried to instantiate class more than once.”);
}
/* construct here */

Instance = this;

}

static int Thread_callback_trampoline(void* data)
{
assert(Instance != 0);
return Instance->thread_callback(data);
}

static Thread_handler* Instance;
}

Then you can register it with
SDL_CreateThread(&Thread_handler::Thread_callback_trampoline, …);

Hope that helped.

CE


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

iEYEAREKAAYFAkrmWBAACgkQPOmqd0kEEbtYggCgw2K412vt90RezbmbOS0gYEk8
KaYAoJWkzUPlvbmcQqhF/o/ivJIqF5I7
=J3QQ
-----END PGP SIGNATURE-----


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