SDL Digest, Vol 6, Issue 7

sdl-request at libsdl.org wrote:

Send SDL mailing list submissions to
sdl at libsdl.org

To subscribe or unsubscribe via the World Wide Web, visit
http://www.libsdl.org/mailman/listinfo/sdl
or, via email, send a message with subject or body ‘help’ to
sdl-request at libsdl.org

You can reach the person managing the list at
sdl-owner at libsdl.org

When replying, please edit your Subject line so it is more specific
than “Re: Contents of SDL digest…”


Today’s Topics:

  1. moving bitmap (Donald)
  2. Re: moving bitmap (Bill Kendrick)
  3. Re: moving bitmap (Michael B. Edwin Rickert)
  4. Wierd libraries loading (Nathan Grebowiec)
  5. Re: Wierd libraries loading (Jonathan Atkins)
  6. strange keyboard problem (Matthias Hennig)
  7. Re: strange keyboard problem (Michael B. Edwin Rickert)
  8. Re: strange keyboard problem (Matthias Hennig)
  9. SDL_GetNamedKeymap()? (Mark Schreiber)

Subject:
[SDL] moving bitmap
From:
Donald <@Donald_Cathcart>
Date:
Wed, 06 Oct 2004 20:39:43 -0300
To:
sdl at libsdl.org

To:
sdl at libsdl.org

Hi all

I am trying my hand at a simple little lunar lander style game. I have
the background bitmap and spaceship bitmapl loaded and I am trying to
get the ship to change postions by setting the dst.x and dst.y rect
members to a temp position, say 582 and 0.

When I make the changes to the code and execute it, the ship still
appears in the upper right of the screen. I have tried the
SDL_UpdateRect function, but have read that this is not needed when
using double buffering?

Here is my code snippet.
// Lunar Rescue Version 1.0
// Copyright © 2004
// Donald Cathcart

#include <sdl.h>
#include <stdlib.h>
#include <stdio.h>

bool Running;
SDL_Surface *screen,*background,playership;
SDL_Rect src, dst;
SDL_Event event;
int SetUp();
int GameLoop();
int main( int argc, char
argv[] )
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
printf(“Unable to initialize SDL: %s\n”, SDL_GetError());
return 1;
}
//exit function
atexit ( SDL_Quit );

//create a window
screen = SDL_SetVideoMode (
1024,768,32,SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_FULLSCREEN);
if (screen == NULL)
{
printf(“Unable to set video mode: %s\n”, SDL_GetError());
return 1;
}
SetUp();

//Poll Event Loop

for(;:wink:
{
if(SDL_PollEvent(&event)!=0)
{
printf(“inside event poll \n”);
switch(event.type)
{
case SDL_KEYDOWN:
if(event.key.keysym.sym==SDLK_ESCAPE)
{
printf(“escape pressed \n”);
return 0;
}
break;
case SDL_QUIT:
printf(“Quitting”);
exit(0);
}

   }

GameLoop();
}
return 0;
}
int SetUp()
{
// Load player bmp
playership=SDL_LoadBMP(“player.bmp”);
src.x=0;
src.y=0;
src.h=playership->h;
src.w=playership->w;
dst.x=512;
dst.y=0;
dst.h=playership->h;
dst.w=playership->w;
// Load background bmp
background=SDL_LoadBMP(“background.bmp”);
src.x=0;
src.y=0;
src.h=background->h;
src.w=background->w;
dst.x=0;
dst.y=0;
dst.h=background->h;
dst.w=background->w;
return 0;
}
int GameLoop()
{
SDL_BlitSurface(background,&src,screen,&dst);
SDL_BlitSurface(playership,&src,screen,&dst);
SDL_Flip(screen);
//SDL_UpdateRect(screen,0,0,0,0);
return 0;
}

Thanks


Subject:
Re: [SDL] moving bitmap
From:
Bill Kendrick
Date:
Wed, 6 Oct 2004 16:45:31 -0700
To:
“A list for developers using the SDL library. (includes SDL-announce)”

To:
“A list for developers using the SDL library. (includes SDL-announce)”

Hi all

I am trying my hand at a simple little lunar lander style game. I have
the background bitmap and spaceship bitmapl loaded and I am trying to
get the ship to change postions by setting the dst.x and dst.y rect
members to a temp position, say 582 and 0.

You appear to be using src/dst variables for BOTh the background AND the
sprite (space ship).

You should set dst.x and dst.y before your calls SDL_BlitSurface().

Check out some example SDL demos or games out there.
(My “Bug Squish” game took about 2 evenings to write, and is very simple
and small: http://www.newbreedsoftware.com/bugsquish/ … I’m sure there
are some good tutorials out there, too :^) )

Good luck!

-bill!
(wrote a vector-based lunar game recently :wink: )


Subject:
Re: [SDL] moving bitmap
From:
“Michael B. Edwin Rickert”
Date:
Wed, 06 Oct 2004 18:28:00 -0700
To:
“A list for developers using the SDL library. (includes SDL-announce)”

To:
“A list for developers using the SDL library. (includes SDL-announce)”

for(;:wink:
{
if(SDL_PollEvent(&event)!=0)

Usually I see this as “while(…)” rather than “if(…)”.

The problem is that with using an if statement, you will get a maximum
of 1 event per frame. If 20 events happen at the same time, it will
take 20 frames for them all to get processed. If a user is typing ___
keys per minute, unless the game is running at least ____ x 2 frames
per minute, it won’t even be able to keep up with just the SDL_KEYDOWN
and SDL_KEYUP events.

Using a while(…) loop reads all events currently needing processing
that frame.

int SetUp()
{
// Load player bmp
playership=SDL_LoadBMP(“player.bmp”);

Many of these lines end up doing nothing useful in the end, because…
(see next comment)

src.x=0;
src.y=0;
src.h=playership->h;
src.w=playership->w;
dst.x=512;
dst.y=0;
dst.h=playership->h;
dst.w=playership->w;
// Load background bmp
background=SDL_LoadBMP(“background.bmp”);

As soon as you get to the line bellow this comment, you start
overwriting them with new values!!!

src.x=0;
src.y=0;
src.h=background->h;
src.w=background->w;
dst.x=0;
dst.y=0;
dst.h=background->h;
dst.w=background->w;
return 0;
}

int GameLoop()
{
SDL_BlitSurface(background,&src,screen,&dst);
SDL_BlitSurface(playership,&src,screen,&dst);

You’re using the exact same rectanges for both surfaces here. Since
you loaded the values for the background second (which overwrote the
player image rectangle settings) it will use those rectangles for both
of them.

Now, if you rearange your code, setting the rectangles when you use
them instead of during your SetUp code:

int GameLoop()
{
//Set up the rectangles for the background
src.x=0;
src.y=0;
src.h=background->h;
src.w=background->w;
dst.x=0;
dst.y=0;
dst.h=background->h;
dst.w=background->w;
//Draw the background
SDL_BlitSurface(background,&src,screen,&dst);
//Set up the rectangles for the player’s ship
src.x=0;
src.y=0;
src.h=playership->h;
src.w=playership->w;
dst.x=512;
dst.y=0;
dst.h=playership->h;
dst.w=playership->w;
//Draw the player’s ship
SDL_BlitSurface(playership,&src,screen,&dst);
//Do other cool stuff
SDL_Flip(screen);
//SDL_UpdateRect(screen,0,0,0,0);
return 0;
}

Your code has a much better chance of working how you wanted (with the
player’s ship showing up at x=512, y=0). The other way to do it would
be to make it so the background and the ship have seperate rectangles,
aka playership_src, playership_dst, background_src, and background_dst.

-Mike


Subject:
[SDL] Wierd libraries loading
From:
Nathan Grebowiec
Date:
Wed, 6 Oct 2004 22:56:25 -0500
To:
“A list for developers using the SDL library. (includes
SDL-announce)”

To:
“A list for developers using the SDL library. (includes
SDL-announce)”

I am building an app like this:
g++ sdl-config --cflags sdl-config --libs -lSDL_mixer -lSDL_ttf
-static-libgcc -Wno-deprecated -O2 -o game cboard.cpp clickablockextreme.cpp

Even those I am using --libs from sdl-config it is still showing this in ldd
on the “game” binary:

linux-gate.so.1 => (0xffffe000)
libSDL-1.2.so.0 => /usr/lib/libSDL-1.2.so.0 (0xb7f8b000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb7f1f000)
libdl.so.2 => /lib/libdl.so.2 (0xb7f1c000)
libasound.so.2 => /usr/lib/libasound.so.2 (0xb7e4a000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0xb7d7d000)
libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0xb7d6d000)
libggi.so.2 => /usr/lib/libggi.so.2 (0xb7d61000)
libgii.so.0 => /usr/lib/libgii.so.0 (0xb7d59000)
libgg.so.0 => /usr/lib/libgg.so.0 (0xb7d53000)
libSDL_mixer-1.2.so.0 => /usr/lib/libSDL_mixer-1.2.so.0 (0xb7d15000)
libSDL_ttf-2.0.so.0 => /usr/lib/libSDL_ttf-2.0.so.0 (0xb7d0f000)
libstdc++.so.5
=> /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/libstdc++.so.5 (0xb7c46000)
libm.so.6 => /lib/libm.so.6 (0xb7c24000)
libc.so.6 => /lib/libc.so.6 (0xb7b16000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb7fed000)
libvorbisfile.so.3 => /usr/lib/libvorbisfile.so.3 (0xb7b0e000)
libvorbis.so.0 => /usr/lib/libvorbis.so.0 (0xb7ae5000)
libogg.so.0 => /usr/lib/libogg.so.0 (0xb7ae0000)
libsmpeg-0.4.so.0 => /usr/lib/libsmpeg-0.4.so.0 (0xb7a7f000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0xb7a10000)
libz.so.1 => /lib/libz.so.1 (0xb79ff000)
libgcc_s.so.1
=> /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/libgcc_s.so.1(0xb79f6000)

Why is ggi and libogg and crap like that showing up?


Subject:
Re: [SDL] Wierd libraries loading
From:
Jonathan Atkins
Date:
Thu, 07 Oct 2004 01:57:53 -0500
To:
“A list for developers using the SDL library. (includes SDL-announce)”

To:
“A list for developers using the SDL library. (includes SDL-announce)”

libSDL is linked to ggi
and libSDL_mixer is linked to ogg

ldd shows all dependancies, including dependancies from libraries that
you linked to directly in the first place.

don’t have a cow.

-LIM-

Nathan Grebowiec wrote:

I am building an app like this:
g++ sdl-config --cflags sdl-config --libs -lSDL_mixer -lSDL_ttf
-static-libgcc -Wno-deprecated -O2 -o game cboard.cpp
clickablockextreme.cpp

Even those I am using --libs from sdl-config it is still showing this
in ldd on the “game” binary:

linux-gate.so.1 => (0xffffe000)
libSDL-1.2.so.0 => /usr/lib/libSDL-1.2.so.0 (0xb7f8b000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb7f1f000)
libdl.so.2 => /lib/libdl.so.2 (0xb7f1c000)
libasound.so.2 => /usr/lib/libasound.so.2 (0xb7e4a000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0xb7d7d000)
libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0xb7d6d000)
libggi.so.2 => /usr/lib/libggi.so.2 (0xb7d61000)
libgii.so.0 => /usr/lib/libgii.so.0 (0xb7d59000)
libgg.so.0 => /usr/lib/libgg.so.0 (0xb7d53000)
libSDL_mixer-1.2.so.0 => /usr/lib/libSDL_mixer-1.2.so.0
(0xb7d15000)
libSDL_ttf-2.0.so.0 => /usr/lib/libSDL_ttf-2.0.so.0 (0xb7d0f000)
libstdc++.so.5 =>
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/libstdc++.so.5 (0xb7c46000)
libm.so.6 => /lib/libm.so.6 (0xb7c24000)
libc.so.6 => /lib/libc.so.6 (0xb7b16000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb7fed000)
libvorbisfile.so.3 => /usr/lib/libvorbisfile.so.3 (0xb7b0e000)
libvorbis.so.0 => /usr/lib/libvorbis.so.0 (0xb7ae5000)
libogg.so.0 => /usr/lib/libogg.so.0 (0xb7ae0000)
libsmpeg-0.4.so.0 => /usr/lib/libsmpeg-0.4.so.0 (0xb7a7f000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0xb7a10000)
libz.so.1 => /lib/libz.so.1 (0xb79ff000)
libgcc_s.so.1 =>
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.4/libgcc_s.so.1(0xb79f6000)

Why is ggi and libogg and crap like that showing up?


Subject:
[SDL] strange keyboard problem
From:
Matthias Hennig
Date:
Thu, 07 Oct 2004 11:43:29 +0100
To:
sdl at libsdl.org

To:
sdl at libsdl.org

Hi all!

I have a weird problem with the keyboard (linux, SDL+sge library).
Sometimes, but not always, the return key is no longer responding when I
start my program for the second time (I can always run it once without a
problem). Usually in this case I get lots of “returns” in the shell from
which I started the program after leaving it. Then it is not sufficient to
kill the X server, I have to reboot the machine to get rid of this problem!
I have not yet figured out under which conditions this happens, it seems
rather random. The question is whether this is a problem with SDL or (maybe
a typical) mistake in my program.

More specific, my program looks as follows: I’m using DGA
(SDL_VIDEODRIVER=dga, flags are: SDL_HWSURFACE|SDL_FULLSCREEN
SDL_DOUBLEBUF) - this all works fine.
I have a global event loop and a timer that does the graphics update. The
keyboard event are read in the usual fashion:

while( SDL_PollEvent( &event ) ) {
switch( event.type ) {
case SDL_KEYDOWN:
if(event.key.keysym.sym == SDLK_ESCAPE) {

So nothing unusual here, I think. Anyone a clue?

Matthias


Subject:
Re: [SDL] strange keyboard problem
From:
“Michael B. Edwin Rickert”
Date:
Thu, 07 Oct 2004 06:23:47 -0700
To:
“A list for developers using the SDL library. (includes SDL-announce)”

To:
“A list for developers using the SDL library. (includes SDL-announce)”

Hi all!

I have a weird problem with the keyboard (linux, SDL+sge library).
Sometimes, but not always, the return key is no longer responding when I
start my program for the second time (I can always run it once without a
problem). Usually in this case I get lots of “returns” in the shell from
which I started the program after leaving it. Then it is not
sufficient to
kill the X server, I have to reboot the machine to get rid of this
problem!
I have not yet figured out under which conditions this happens, it seems
rather random. The question is whether this is a problem with SDL or
(maybe

sounds like a focus problem… prehaps a X misconfiguration/bug, or
prehaps an improper shutdown of some sort. How are you qutting? What
version of SDL (and for that matter, XFree, or whatever X server
you’re running) are you using? You might try exiting by intentional
segfault (or prehaps simply sending a signal) to trip the SDL
parachute, and see if the problem goes away when you do so. Are you
sure you’re calling SDL_Quit in all the right places?

All the troubleshooting I can think of right off the top of my head.

-Mike


Subject:
[SDL] Re: strange keyboard problem
From:
Matthias Hennig
Date:
Thu, 07 Oct 2004 15:43:17 +0100
To:
sdl at libsdl.org

To:
sdl at libsdl.org

Hi,

many thanks for the response, Mike!

sounds like a focus problem… prehaps a X misconfiguration/bug, or
prehaps an improper shutdown of some sort. How are you qutting? What
version of SDL (and for that matter, XFree, or whatever X server you’re

I’m running XFree 4.3.0.1 on Debain testing, SDL 1.2.3 and sge version
020904, all on a kernel 2.6.8.

running) are you using? You might try exiting by intentional segfault
(or prehaps simply sending a signal) to trip the SDL parachute, and see
if the problem goes away when you do so. Are you sure you’re calling
SDL_Quit in all the right places?

Yes, SDL_Quit() is the last line of main(), and that is the only way to end
the program (no exit()) except for a segfault. I’ll try a segfault later -
what would be the consequence if this works?

Matthias


Subject:
[SDL] SDL_GetNamedKeymap()?
From:
Mark Schreiber
Date:
Thu, 7 Oct 2004 13:57:46 -0400
To:
SDL at libsdl.org

To:
SDL at libsdl.org

Is there any objection to adding an SDL_GetNamedKeysym() function to
SDL12 that would perform the inverse of SDL_GetKeyName()?

This would be useful when reading key binding config files – it
allows developers to use the SDL keynames.

Currently, applications can get similar functionality by extracting
all the names from SDL_GetKeyName() in a loop and then doing the
reverse mapping themselves, but that’s a bit of a hack…



SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Thanks for the help guys. Do I need the UpdateRect function? As I
understand the docs, I would only need it if I am not using DoubleBuf
flag. Is that correct?

Don>On Wed, Oct 06, 2004 at 08:39:43PM -0300, Donald wrote: