Best practice? 2D - OpenGL? Threads?

Hello everyone,

in the last months I have read a lot about SDL (tutorials,
wikis, etc. etc.). But now, since I am pretty familiar with
programming SDL I have two questions about the best practices
for making, let’s say a 2D Game. For example, I like to do
a Tetris Clone. While the logic is not a problem, I would
like to use up-to-date graphic things, like animations, particles etc.

So, what is teh best way to do it? Would it be sufficient
to use SDL with SDL_Blit, alpha blending and that stuff,
or should i use OpenGL with SDL instead?

Oh, and can someone tell me when it is good to use threads
or mutexes? Should I run music /sfx in a different thread?

I would like to hear your opinion on that befor I begin
to program something and then find out, that all the
blitting is to slow or the CPU goes up to 100%.

Some advice would be nice,

greetings
yosh

Hello everyone,

in the last months I have read a lot about SDL (tutorials,
wikis, etc. etc.). But now, since I am pretty familiar with
programming SDL I have two questions about the best practices
for making, let’s say a 2D Game. For example, I like to do
a Tetris Clone. While the logic is not a problem, I would
like to use up-to-date graphic things, like animations, particles etc.

So, what is teh best way to do it? Would it be sufficient
to use SDL with SDL_Blit, alpha blending and that stuff,
or should i use OpenGL with SDL instead?

In most cases, SDL_Blit will be slower than rendering via OpenGL.
After all, most hardware doesn’t provide 2D acceleration, only 3D. So
you can use OpenGL in orthographic mode and you’ve essentially got
hardware accelerated 2D :slight_smile:

I have a basic game which actually allows using SDL blits, OpenGL, or
Direct3D. If interested, check out the Graphics folder of this
project: http://github.com/tycho/arc/tree/master

Oh, and can someone tell me when it is good to use threads
or mutexes? Should I run music /sfx in a different thread?

If you use SDL_mixer, I think it already uses its own thread.On Sat, Aug 1, 2009 at 8:54 AM, yosh wrote:

I would like to hear your opinion on that befor I begin
to program something and then find out, that all the
blitting is to slow or the CPU goes up to 100%.

Some advice would be nice,

greetings
?yosh


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

What is your experience level? If you:

  • Don’t know OpenGL yet
  • Want results soon
  • Haven’t made a game before
    …then you should stick with 2D SDL for this game.

Jonny DOn Sat, Aug 1, 2009 at 8:54 AM, yosh wrote:

Hello everyone,

in the last months I have read a lot about SDL (tutorials,
wikis, etc. etc.). But now, since I am pretty familiar with
programming SDL I have two questions about the best practices
for making, let’s say a 2D Game. For example, I like to do
a Tetris Clone. While the logic is not a problem, I would
like to use up-to-date graphic things, like animations, particles etc.

So, what is teh best way to do it? Would it be sufficient
to use SDL with SDL_Blit, alpha blending and that stuff,
or should i use OpenGL with SDL instead?

Oh, and can someone tell me when it is good to use threads
or mutexes? Should I run music /sfx in a different thread?

I would like to hear your opinion on that befor I begin
to program something and then find out, that all the
blitting is to slow or the CPU goes up to 100%.

Some advice would be nice,

greetings
?yosh


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

What is your experience level? If you:

  • Don’t know OpenGL yet
  • Want results soon
  • Haven’t made a game before
    …then you should stick with 2D SDL for this game.

Jonny D

I think too many people reach for OpenGL too soon when just basic blits
would suffice. I wrote an set of functions that deals with objects and
animation along with backgrounds using just basic SDL. While testing I was
able to get at least 100 induvidual animated sprites on screen without any
slow-down. Surely a tetris game would fall into a catagory where simple
blits would be enough.On Sat, Aug 1, 2009 at 8:12 PM, Jonathan Dearborn wrote:

What is your experience level? ?If you:

  • Don’t know OpenGL yet
  • Want results soon
  • Haven’t made a game before
    …then you should stick with 2D SDL for this game.

Jonny D

I think too many people reach for OpenGL too soon when just basic blits
would suffice. I wrote an set of functions that deals with objects and
animation along with backgrounds using just basic SDL. While testing I was
able to get at least 100 induvidual animated sprites on screen without any
slow-down. Surely a tetris game would fall into a catagory where simple
blits would be enough.

True. Though I gave my advice considering the potential future use of
learning such an API. With OpenGL you have a lot more flexibility and
you get the hardware acceleration advantage. With SDL, you can do
limited graphics, but how useful would that knowledge be later? You
could run into a point later where those restrictions bite you in the
ass, and then you have to learn OpenGL anyway. Just my two cents.

  • StevenOn Sun, Aug 2, 2009 at 1:09 AM, Sysmatrix User wrote:

On Sat, Aug 1, 2009 at 8:12 PM, Jonathan Dearborn wrote:

I’m still a bit confused about the hardware acceleration when it comes
to blitting in SDL…

is it true that the Windows Version uses DirectDraw and therefore
accelerates 2D blitting ?
is it true that the “ordinary” Mac version does NOT use openGL and
therefore does NOT accelerate blitting ?

how big is the speed difference on mac between plain_SDLand
SDL_with_openGL when it comes to 2D blitting ? On a modern CPU/GPU, is
it worth the effort ? Or is plain_SDL already within 1msec for a
fullscreen blit (1024x768) ?

I sincerely hope someone can shed some light on this

Recent versions of SDL will not use DirectDraw, but you can enable it
using environmental variables. I don’t know about the Mac backend but
my understanding is that SDL 1.2 does not use OpenGL as a backend.
Note that using HW_SURFACE can actually slow down performance in some
cases, because when SDL cannot use the accelerated code paths it might
have to read data back from the GPU at quite a cost. An example is
alpha blending, which is AFAIK unaccelerated, at least on windows.

OpenGL is typically a lot faster, but as you hinted it depends on your
needs. Unaccelerated blits can be “fast enough” for a variety of
games.

SDL 1.3 allows for (and has) OpenGL backends, so can be very fast.

As for the exact timing, you can write some test programs yourself to
experiment with how fast you can do full screen blits etc. It will
vary between computers and platforms. Be sure to test your minimum
hardware too. It depends on your needs, the question is too vague to
have a correct answer.On Mon, Aug 3, 2009 at 10:10 PM, jeroen clarysse<jeroen.clarysse at telenet.be> wrote:

I’m still a bit confused about the hardware acceleration when it comes to
blitting in SDL…

is it true that the Windows Version uses DirectDraw and therefore
accelerates 2D blitting ?
is it true that the “ordinary” Mac version does NOT use openGL and therefore
does NOT accelerate blitting ?

how big is the speed difference on mac between plain_SDLand SDL_with_openGL
when it comes to 2D blitting ? On a modern CPU/GPU, is it worth the effort ?
Or is plain_SDL already within 1msec for a fullscreen blit (1024x768) ?

I sincerely hope someone can shed some light on this

I wouldn’t bother with hardware surfaces in SDL 1.2. Either try SDL
1.3 or use software surfaces optimized for blitting with
SDL_DisplayFormat() and SDL_DisplayFormatAlpha().

Jonny DOn Mon, Aug 3, 2009 at 9:48 PM, Brian<brian.ripoff at gmail.com> wrote:

Recent versions of SDL will not use DirectDraw, but you can enable it
using environmental variables. I don’t know about the Mac backend but
my understanding is that SDL 1.2 does not use OpenGL as a backend.
Note that using HW_SURFACE can actually slow down performance in some
cases, because when SDL cannot use the accelerated code paths it might
have to read data back from the GPU at quite a cost. An example is
alpha blending, which is AFAIK unaccelerated, at least on windows.

OpenGL is typically a lot faster, but as you hinted it depends on your
needs. Unaccelerated blits can be “fast enough” for a variety of
games.

SDL 1.3 allows for (and has) OpenGL backends, so can be very fast.

As for the exact timing, you can write some test programs yourself to
experiment with how fast you can do full screen blits etc. It will
vary between computers and platforms. Be sure to test your minimum
hardware too. It depends on your needs, the question is too vague to
have a correct answer.

On Mon, Aug 3, 2009 at 10:10 PM, jeroen clarysse<jeroen.clarysse at telenet.be> wrote:

I’m still a bit confused about the hardware acceleration when it comes to
blitting in SDL…

is it true that the Windows Version uses DirectDraw and therefore
accelerates 2D blitting ?
is it true that the “ordinary” Mac version does NOT use openGL and therefore
does NOT accelerate blitting ?

how big is the speed difference on mac between plain_SDLand SDL_with_openGL
when it comes to 2D blitting ? On a modern CPU/GPU, is it worth the effort ?
Or is plain_SDL already within 1msec for a fullscreen blit (1024x768) ?

I sincerely hope someone can shed some light on this


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

thanks to Jonathan & Brian, i now know a bit more, but i still have
questions :

you say that SDL 1.3 has an openGL backend… does this mean that
simple 2D blitting is hardware accelerated ?

on all major platforms (mac, win, linux) ?

I tried to figure out some of the internal workings of SDL, and
seemingly, the mac version relies on CoreImage (or some other CoreXXX
tech)… is that true ? Does the windows counterpart do the same with
DirectX or openGL ?

also, on the issue of testing blitting : is a hardware optimised blit
synchronous, or asynchronous ? I mean : when I call Blit(), does it
simply send some commands to the GPU and return, or will it wait for
the GPU to complete ?> I wouldn’t bother with hardware surfaces in SDL 1.2. Either try SDL

1.3 or use software surfaces optimized for blitting with
SDL_DisplayFormat() and SDL_DisplayFormatAlpha().

Jonny D

On Mon, Aug 3, 2009 at 9:48 PM, Brian<brian.ripoff at gmail.com> wrote:

Recent versions of SDL will not use DirectDraw, but you can enable it
using environmental variables. I don’t know about the Mac backend but
my understanding is that SDL 1.2 does not use OpenGL as a backend.
Note that using HW_SURFACE can actually slow down performance in some
cases, because when SDL cannot use the accelerated code paths it
might
have to read data back from the GPU at quite a cost. An example is
alpha blending, which is AFAIK unaccelerated, at least on windows.

OpenGL is typically a lot faster, but as you hinted it depends on
your
needs. Unaccelerated blits can be “fast enough” for a variety of
games.

SDL 1.3 allows for (and has) OpenGL backends, so can be very fast.

As for the exact timing, you can write some test programs yourself to
experiment with how fast you can do full screen blits etc. It will
vary between computers and platforms. Be sure to test your minimum
hardware too. It depends on your needs, the question is too vague to
have a correct answer.

On Mon, Aug 3, 2009 at 10:10 PM, jeroen clarysse<@Jeroen_Clarysse> wrote:

I’m still a bit confused about the hardware acceleration when it
comes to
blitting in SDL…

is it true that the Windows Version uses DirectDraw and therefore
accelerates 2D blitting ?
is it true that the “ordinary” Mac version does NOT use openGL and
therefore
does NOT accelerate blitting ?

how big is the speed difference on mac between plain_SDLand
SDL_with_openGL
when it comes to 2D blitting ? On a modern CPU/GPU, is it worth
the effort ?
Or is plain_SDL already within 1msec for a fullscreen blit
(1024x768) ?

I sincerely hope someone can shed some light on this


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