Video, keyboard, mouse and network

I’ve just ported my project (http://freeweb.lombardiacom.it/xarvh/) from
Allegro to SDL, but i encountered some minor problems:

I’m developing the game under X, but i’d like to port it to as many platforms
as possible.

  • Under ALLEGRO i write all data on a virtual memory buffer larger than
    screen, then i blit only the middle part to the real screen, so that i didn’t
    need clipping.
    Under SDL i found that i can’t write it directly, but i must blit my virtual
    buffer to an hardware surface (same size of the screen), and then update
    it… this seems slower than directly blit the virtual buffer on the screen.
    Is there a way to directly blit a larger (software) virtual screen to the
    screen with SDL?

  • I can’t set the keyboard repeat feature.
    The call
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
    returns no error, but does actually nothing.
    Any idea?

  • While in fullscreen mode the mouse becames slow, while in windowed mode it
    works correctly, this happens also when i toggle the video mode runtime.

  • One last question, hope is not OT.
    Is there a network library i can use with SDL to compile a native win32
    executable?
    SDL_net is only a wrapper, and internally makes the same calls my game does.
    I’d liked to compile with mingw, that is GNU and posix-compliant, but i was
    not able to find a network library for it.

Thanx,
Francesco Orsenigo, Xarvh Project

  • Under ALLEGRO i write all data on a virtual memory buffer larger than
    screen, then i blit only the middle part to the real screen, so that i didn’t
    need clipping.
    Under SDL i found that i can’t write it directly, but i must blit my virtual
    buffer to an hardware surface (same size of the screen), and then update
    it… this seems slower than directly blit the virtual buffer on the screen.
    Is there a way to directly blit a larger (software) virtual screen to the
    screen with SDL?

I’m not sure what the problem is here, as I do this exact thing with my
emulator. In some games, the in memory backbuffer is much larger than the
actual viewport (display) and I just blit from the backbuffer to the
screen with the section that I want. It’s just a single blit, too, so
maybe I’m not understanding what the problem is exactly.

–>Neil-------------------------------------------------------------------------------
Neil Bradley What are burger lovers saying
Synthcom Systems, Inc. about the new BK Back Porch Griller?
ICQ #29402898 “It tastes like it came off the back porch.” - Me

At 10:38 AM 8/21/02 +0200, you wrote:

  • One last question, hope is not OT.
    Is there a network library i can use with SDL to compile a native win32
    executable?
    SDL_net is only a wrapper, and internally makes the same calls my game does.
    I’d liked to compile with mingw, that is GNU and posix-compliant, but i was
    not able to find a network library for it.

SDL_net is a wrapper in the same sense that SDL itself is a wrapper – it
provides a constant interface for operating system specific code. An
application compiled against SDL_net should compile on any operating system
SDL_net supports – you only need another library if you’re trying to do
something SDL_net doesn’t support.

It works in my code. The defaults are 500 for delay and 30 for interval. I
Call SDL_EnableKeyRepeat with delay = 250 and interval = 50. Don’t know why
this might make a difference, but you might try it.

JeffOn Wednesday 21 August 2002 01:38 am, you wrote:

  • I can’t set the keyboard repeat feature.
    The call
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); returns no error, but does actually nothing.
    Any idea?

El Wed, 21 Aug 2002 10:38:37 +0200
Francesco Orsenigo escribi?:

I’ve just ported my project (http://freeweb.lombardiacom.it/xarvh/) from
Allegro to SDL, but i encountered some minor problems:

I’m developing the game under X, but i’d like to port it to as many platforms

as possible.

  • Under ALLEGRO i write all data on a virtual memory buffer larger than
    screen, then i blit only the middle part to the real screen, so that i didn’t

need clipping.

Do you write all data on a virtual memory buffer on each frame redraw? If the
virtual buffer is much larger than screen, I think it will be terribly slow.

Under SDL i found that i can’t write it directly, but i must blit my virtual
buffer to an hardware surface (same size of the screen), and then update
it… this seems slower than directly blit the virtual buffer on the screen.

I’m not sure of that. Do you mean, your virtual memory buffer isn’t a surface?
If that is the case, and the buffer has the same format as the screen, you can
convert it to a surface using SDL_CreateRGBSurfaceFrom. Then, you can do a
direct blit from that surface to the screen.

Is there a way to directly blit a larger (software) virtual screen to the
screen with SDL?

Yes; using SDL_BlitSurface. You just need to set a non-NULL SDL_Rect second
parameter.

Is there a network library i can use with SDL to compile a native win32
executable?

Maybe you need to add explicitly ws2_32 to your linker command line.

Regards,
Wizord.

Jos? Luis S?nchez:

Do you write all data on a virtual memory buffer on each frame redraw? If
the virtual buffer is much larger than screen, I think it will be terribly
slow.

Usually nothing is drawn outside the visible portion of the virtual screen,
but sometimes something exits it.

I’m not sure of that. Do you mean, your virtual memory buffer isn’t a
surface? If that is the case, and the buffer has the same format as the
screen, you can convert it to a surface using SDL_CreateRGBSurfaceFrom.
Then, you can do a direct blit from that surface to the screen.

The Virtual screen is a software SDL surface 950x750 (created with
SDL_CreateRGBSurface) vs a 800x600 real screen.

Yes; using SDL_BlitSurface. You just need to set a non-NULL SDL_Rect
second parameter.
It is just what i’m doing:

//================================================================
void screen_update(int x, int y, int w, int h)
{
src.x = x + 150/2;
src.y = y + 150/2;
dst.x = x;
dst.y = y;

src.w = dst.w = w;
src.h = dst.h = h;

SDL_BlitSurface(vscreen, &src, screen, &dst);
SDL_UpdateRect(screen, 0, 0, 800, 600);
}
//================================================================

I usually call screen_update(0, 0, 800, 600);
If I don’t call SDL_UpdateRect() the screen remains black.
This is the code i use to initialize video:

//================================================================
if(SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) return 0;

screen = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE);
if(screen == NULL) return 0;

vscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, 800+150, 600+150, 16,
31<<11, //Rmask
63<<5, //Gmask
31, //Bmask
0); //Amask
//================================================================

Maybe you need to add explicitly ws2_32 to your linker command line.
I’ll have a look.

Thank you,
Francesco Orsenigo, Xarvh Project

El Thu, 22 Aug 2002 11:20:11 +0200
Francesco Orsenigo escribi?:

The Virtual screen is a software SDL surface 950x750 (created with
SDL_CreateRGBSurface) vs a 800x600 real screen.

Ok, loud and clear now .

Yes; using SDL_BlitSurface. You just need to set a non-NULL SDL_Rect
second parameter.
It is just what i’m doing:

//================================================================
void screen_update(int x, int y, int w, int h)
{
src.x = x + 150/2;
src.y = y + 150/2;
dst.x = x;
dst.y = y;

src.w = dst.w = w;
src.h = dst.h = h;

SDL_BlitSurface(vscreen, &src, screen, &dst);
SDL_UpdateRect(screen, 0, 0, 800, 600);
}
//================================================================

I usually call screen_update(0, 0, 800, 600);
If I don’t call SDL_UpdateRect() the screen remains black.
This is the code i use to initialize video:

//================================================================
if(SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) return 0;

screen = SDL_SetVideoMode(800, 600, 16, SDL_HWSURFACE);
if(screen == NULL) return 0;

vscreen = SDL_CreateRGBSurface(SDL_SWSURFACE, 800+150, 600+150, 16,
31<<11, //Rmask
63<<5, //Gmask
31, //Bmask
0); //Amask
//================================================================

All this code is OK, but it will produce a Windowed mode application (maybe you
create a window the size of your desktop, but a window anyway). IIRC, you said
you’re comming from Allegro, which AFAIK doesn’t support windowed mode. Do you
really wish to use windowed mode?

If that’s not what you’d intended for, you need to add SDL_FULLSCREEN flag on
SDL_SetVideoMode. I can also tell you a few additional tricks to improve
performance for full screen mode if you wish.

Regards,
Wizord.

Jos? Luis S?nchez:

All this code is OK, but it will produce a Windowed mode application (maybe
you create a window the size of your desktop, but a window anyway). IIRC,
you said you’re comming from Allegro, which AFAIK doesn’t support windowed
mode. Do you really wish to use windowed mode?

If that’s not what you’d intended for, you need to add SDL_FULLSCREEN flag
on SDL_SetVideoMode. I can also tell you a few additional tricks to
improve performance for full screen mode if you wish.
Your tricks are gladly welcome!

I toggle between Fullscreen/Windowed mode with:

SDL_WM_ToggleFullscreen(screen);

Switching to Fullscreen or even starting directly in fullscreen mode does not
affect performance significatively (except mouse that slows down).

(ALLEGRO supports both Windowed and Fullscreen mode, but switching between
them is not so straightforward.)

Thank you!
Francesco Orsenigo, Xarvh Project
http://freeweb.lombardiacom.it/xarvh/

I toggle between Fullscreen/Windowed mode with:

SDL_WM_ToggleFullscreen(screen);

(This only works under Linux and…BeOS or something. Not Win32.)

–ryan.

I’ve finally fixed the keyboard reapeat bug.

It seems i must initialize the video (SDL_SetVideoMode) before enabling
keyboard repeat (SDL_EnableKeyRepeat).

Why?
I can think about mouse needing video mode to initialize, but what has
keyboard repeat to share with video?

If this problem is not only mine, i think SDL documentation must tell about
this interaction between video and keyboard, it is not SO obvious.
However, SDL keyboard works much better than ALLEGRO: has faster
responsiviness and better implementation.

I’m still in trouble with mouse movement speed.
Any idea, at least on setting mouse sensitivity?

Thanx to all,
Francesco

If this problem is not only mine, i think SDL documentation must tell about
this interaction between video and keyboard, it is not SO obvious.

Well, in all the windowed environments (X11, Windows, MacOS), keyboard
input comes when you have a window that has the keyboard focus, and you
have to have a window to get keyboard focus, so I thought it was obvious.
Feel free to add a note to the SDL Documentation Project:
http://sdldoc.csn.ul.ie/

I’m still in trouble with mouse movement speed.
Any idea, at least on setting mouse sensitivity?

When SDL is in windowed mode, the operating system is processing mouse
movement and sending SDL events, usually tuned based on your mouse
sensitivity settings. When SDL is in fullscreen mode, SDL usually gets
raw mouse motion from the mouse directly, which is not scaled based on
your mouse sensitivity settings. Theoretically we could look up those
settings and apply the scale ourselves, but I’m not sure how to look
them up programmatically. Any ideas? :slight_smile:

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

– Sam Lantinga wrote:

Theoretically we could look up those settings and apply the scale
ourselves, but I’m not sure how to look them up programmatically.
Any ideas? :slight_smile:

http://developer.apple.com/samplecode/Sample_Code/Devices_and_Hardware/ADB/ModifyMouseAccl.htm
has some code that may help under OS X.__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes