SDL 1.3 video example

Attached is a simple example using the new video API for use with the
latest SDL snapshot:
http://www.libsdl.org/tmp/SDL-1.3.zip

You’ll notice a lot of the new complexity is automatically taken care
of for you, if you don’t want it. :slight_smile:

See ya!–
-Sam Lantinga, Founder and President, Galaxy Gameworks LLC
-------------- next part --------------
A non-text attachment was scrubbed…
Name: testspriteminimal.c
Type: text/x-csrc
Size: 4438 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20091027/2b554d16/attachment.c

You forgot to call SDL_quit in your quit function:

/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
exit(rc);
}

2009/10/28 Sam Lantinga :> Attached is a simple example using the new video API for use with the

latest SDL snapshot:
http://www.libsdl.org/tmp/SDL-1.3.zip

You’ll notice a lot of the new complexity is automatically taken care
of for you, if you don’t want it. :slight_smile:

See ya!

? ? ? ?-Sam Lantinga, Founder and President, Galaxy Gameworks LLC


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

2009/10/28 Kenneth Bull <@Kenneth_Bull>:

You forgot to call SDL_quit in your quit function:

/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
? ?exit(rc);
}

nvm, there’s no SDL_Init() either.

Yeah, there’s also a memory leak because I don’t free the window. I’m
still debating whether I want to enforce calling SDL_Quit() or have a
reference counted de-init on the video system.On Wed, Oct 28, 2009 at 12:57 AM, Kenneth Bull wrote:

2009/10/28 Kenneth Bull :

You forgot to call SDL_quit in your quit function:

/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
? ?exit(rc);
}

nvm, there’s no SDL_Init() either.


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


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Yeah, there’s also a memory leak because I don’t free the window. ?I’m
still debating whether I want to enforce calling SDL_Quit() or have a
reference counted de-init on the video system.

Both are fine with me. OTOH, I might want to completely shut down SDL
and start it clean and fresh and then I would be wondering why I can’t
find SDL_Quit. I’d provide and SDL_Quit() even if it didn’t do
anything just to keep the 1,000,001 questions that all start “I can’t
find anything like SDL_Quit()…” off the list.

Bob PendletonOn Wed, Oct 28, 2009 at 8:17 AM, Sam Lantinga wrote:

On Wed, Oct 28, 2009 at 12:57 AM, Kenneth Bull wrote:

2009/10/28 Kenneth Bull :

You forgot to call SDL_quit in your quit function:

/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
? ?exit(rc);
}

nvm, there’s no SDL_Init() either.


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


? ? ? ?-Sam Lantinga, Founder and President, Galaxy Gameworks LLC


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


±----------------------------------------------------------

Yeah, there’s also a memory leak because I don’t free the window. I’m
still debating whether I want to enforce calling SDL_Quit() or have a
reference counted de-init on the video system.

Both are fine with me. OTOH, I might want to completely shut down SDL
and start it clean and fresh and then I would be wondering why I can’t
find SDL_Quit. I’d provide and SDL_Quit() even if it didn’t do
anything just to keep the 1,000,001 questions that all start “I can’t
find anything like SDL_Quit()…” off the list.

Bob Pendleton

Agreed, but I’d take it one step further. Have SDL_Quit be part of the
reference counting system. So for example, if I call SDL_Init(SDL_INIT_VIDEO)
twice, it shouldn’t shut down the video subsystem until the second
SDL_Quit call.>----- Original Message ----

From: Bob Pendleton
Subject: Re: [SDL] SDL 1.3 video example
On Wed, Oct 28, 2009 at 8:17 AM, Sam Lantinga wrote:

Yeah, there’s also a memory leak because I don’t free the window. ?I’m
still debating whether I want to enforce calling SDL_Quit() or have a
reference counted de-init on the video system.

Both are fine with me. OTOH, I might want to completely shut down SDL
and start it clean and fresh and then I would be wondering why I can’t
find SDL_Quit. I’d provide and SDL_Quit() even if it didn’t do
anything just to keep the 1,000,001 questions that all start “I can’t
find anything like SDL_Quit()…” off the list.

Bob Pendleton

Agreed, but I’d take it one step further. ?Have SDL_Quit be part of the
reference counting system. ?So for example, if I call SDL_Init(SDL_INIT_VIDEO)
twice, it shouldn’t shut down the video subsystem until the second
SDL_Quit call.

Yeah, I can see that. If I call a library that uses SDL to pop up an
interface that then goes away, having the library and my code both be
able to init SDL and Quit SDL could be nice. But, that means they have
to not share any values between the two instances of SDL. Otherwise if
one sets something that the other has also set, you get inconsistent
behavior. It doesn’t seem like a good idea to me.

Bob PendletonOn Wed, Oct 28, 2009 at 12:37 PM, Mason Wheeler wrote:

----- Original Message ----
From: Bob Pendleton <@Bob_Pendleton>
Subject: Re: [SDL] SDL 1.3 video example
On Wed, Oct 28, 2009 at 8:17 AM, Sam Lantinga wrote:


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


±----------------------------------------------------------

But, that means they have to not share any values between the two
instances of SDL. Otherwise if one sets something that the other
has also set, you get inconsistent behavior. It doesn’t seem like a
good idea to me.

OK, I’m lost. What sort of potential problems are you talking about
here?>----- Original Message ----

From: Bob Pendleton
Subject: Re: [SDL] SDL 1.3 video example

2009/10/28 Bob Pendleton :

Yeah, I can see that. If I call a library that uses SDL to pop up an
interface that then goes away, having the library and my code both be
able to init SDL and Quit SDL could be nice. But, that means they have
to not share any values between the two instances of SDL. Otherwise if
one sets something that the other has also set, you get inconsistent
behavior. It doesn’t seem like a good idea to me.

I did something like that for an instance class a while back… Not
really useful though without actually putting it in SDL.

See attached if you’re interested. Wouldn’t take much to move this to
SDL_Init, SDL_Quit, etc.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: SDLppInstance.hpp
Type: application/octet-stream
Size: 500 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20091029/95894459/attachment.obj
-------------- next part --------------
A non-text attachment was scrubbed…
Name: SDLppInstance.cpp
Type: application/octet-stream
Size: 1438 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20091029/95894459/attachment-0001.obj

Hello !

find SDL_Quit. I’d provide and SDL_Quit() even if it didn’t do
anything just to keep the 1,000,001 questions that all start “I can’t
find anything like SDL_Quit()…” off the list.

It is natural, i would wonder too if
there is a XYXY_Init, why is there no XYXY_Quit :slight_smile:

CU

But, that means they have to not share any values between the two
instances of SDL. Otherwise if one sets something that the other
has also set, you get inconsistent behavior. It doesn’t seem like a
good idea to me.

OK, I’m lost. ?What sort of potential problems are you talking about
here?

If SDL has any global variables or any internal state that my program
can set. Then my program will expect it to stay the way I set it. If I
use a library that does SDL_init() it will expect to be able to set
the same internal state and expect it to stay the way it set it. So,
if you want different parts of process to be able to init and quit SDL
then SDL has to be written so that every SDL_init creates a separate
instance of all the of SDL’s internal state.

The most obvious example is the event queue. SDL puts every event on
one queue. If I want to do my own SDL_init then I also want to read
events from the queue, right? How else would I be able to interact
with the user? So, SDL would need a way to some how support two event
queues. I am not talking about a second thread here, I am talking
about a library.

So, no, SDL should not allow multiple calls to SDL_init.

Bob PendletonOn Wed, Oct 28, 2009 at 1:33 PM, Mason Wheeler wrote:

----- Original Message ----
From: Bob Pendleton <@Bob_Pendleton>
Subject: Re: [SDL] SDL 1.3 video example


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


±----------------------------------------------------------

2009/10/30 Bob Pendleton :

If SDL has any global variables or any internal state that my program
can set. Then my program will expect it to stay the way I set it. If I
use a library that does SDL_init() it will expect to be able to set
the same internal state and expect it to stay the way it set it. So,
if you want different parts of process to be able to init and quit SDL
then SDL has to be written so that every SDL_init creates a separate
instance of all the of SDL’s internal state.

That’s not all bad really… Create an SDL instance handle that can
be passed in to various SDL_Create* functions. Store the instance
handle in SDL_Surface, SDL_Window, etc. It does mean checking or
switching instances on most API calls though.

But this is back to global state vs passed state. Right now SDL is
mostly global state.

The most obvious example is the event queue. SDL puts every event on
one queue. If I want to do my own SDL_init then I also want to read
events from the queue, right? How else would I be able to interact
with the user? So, SDL would need a way to some how support two event
queues. I am not talking about a second thread here, I am talking
about a library.

And again, you could create a queue object to store events, then pass
a queue handle to SDL_CreateWindow, SDL_PeepEvents, SDL_PushEvent,
etc. Which actually could be a good thing, since you could get
multiple threads, each with their own event queues, managing their own
windows, even on Win32.

So, no, SDL should not allow multiple calls to SDL_init.

Or you could have some way of informing the calling program/library
that SDL has already been initialized. Other than checking
SDL_WasInit for specific subsystems, you could have SDL_Init return 1
(instead of 0 or -1) if SDL itself has already been initialised (and
maintain a reference count for SDL_Quit).

Then code like so:

int main(int, char**) {
if (SDL_Init(0) < 0) {
printf(“Error initialising SDL: %s\n”, SDL_GetError());
return 1;
}
if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
if (SDL_InitSubsystem(SDL_INIT_VIDEO) != 0) {
printf(“Error initialising SDL video: %s\n”, SDL_GetError());
SDL_Quit();
return 2;
}
}

/* … */

SDL_Quit();
return 0;
}