Aaarghh! Help!

This should be a simple thing really, at least it seems that way. But I need
some direction here, the HTML documentation included with SDL-1.0.3 isn’t too
clear about the SDL_GetModState function or it’s usage. The examples don’t use
it either, so it’s hard to know how to use it :frowning: Anyway, I am trying to detect
if the user is pressing the left shift and escape key at the same time. I have
managed to come up with three pieces of code that to me seem that they should
work. But only one works, the piece of code that doesn’t use SDL_GetModState().
So, my question is: How do I use SDL_GetModState? I’m guessing that’s why i’m
technically supposed to use to determine if one of the Shift, Control, Alt, etc
keys are pressed on the keyboard at the same time as another key instead of the
hack I did in code snippet one. Anyway, if someone could explain to me why the
1st one works, and the other 2 don’t, I would be very grateful…

The 1st one:
Uint8 *keys;
keys = SDL_GetKeyState(NULL);
if(keys[SDLK_LSHIFT] == SDL_PRESSED) {
if(keys[SDLK_ESCAPE] == SDL_PRESSED) {
printf(“Quitting…\n”);
}
}

The 2nd one:
Uint8 *keys;
keys = SDL_GetKeyState(NULL);
if(SDL_GetModState == KMOD_LSHIFT) {
if(keys[SDLK_ESCAPE] == SDL_PRESSED) {
printf(“Quitting…\n”);
}
}

The 3rd one:
Uint8 *keys;
keys = SDL_GetKeyState(NULL);
if ((SDL_GetModState == SDLK_LSHIFT) && (keys[SDLK_ESCAPE] == SDL_PRESSED) ) {
printf(“Quitting…\n”);
}

My main frustration here is the fact that SDL_GetModState is briefly mentioned
in the documentation, and doesn’t really show how to use it, it just mentions
that it’s SDL_GetModState(void); Which doesn’t help a whole lot. So if someone
would be so kind as to explain it’s inner workings, I would appreciate it
greatly :slight_smile:

Thanks,

DrEvil
@EvilTypeGuy

[snip]

The 2nd one:
Uint8 *keys;
keys = SDL_GetKeyState(NULL);
if(SDL_GetModState == KMOD_LSHIFT) {
if(keys[SDLK_ESCAPE] == SDL_PRESSED) {
printf(“Quitting…\n”);
}
}
The 3rd one:
Uint8 *keys;
keys = SDL_GetKeyState(NULL);
if ((SDL_GetModState == SDLK_LSHIFT) && (keys[SDLK_ESCAPE] == SDL_PRESSED) ) {
printf(“Quitting…\n”);
}
It seems to me that instead of SDL_GetModState, you’re going to want:
SDL_GetModState()

You’re code is comparing the function (pointer?), rather than actually
calling the said function.

Now, as for the actual use of said function, I have no idea. :slight_smile:

Good luck,
JoshOn Mon, Feb 07, 2000 at 11:00:17PM -0600, DrEvil wrote:

Doh! However, it still doesn’t work even after changing SDL_GetModState to
SDL_GetModState()…Which I should have noticed :stuck_out_tongue: Been a long time since I
wrote C programs…Too long, Perl has fried my brain :slight_smile: So, I could still use
some help on how to use the blasted SDL_GetModState function if anyone is
willing…

Thanks,

DrEvil
@EvilTypeGuyOn Mon, 07 Feb 2000, you wrote:

You’re code is comparing the function (pointer?), rather than actually
calling the said function.

Now, as for the actual use of said function, I have no idea. :slight_smile:

Good luck,
Josh

Hi all,

I’ve managed to get partial SDL support for our custom
hardware by integrating calls to my device driver within the SDL
library. All I’ve done is added a modified SDL_LowerBlit,
and SDL_UpdateRect(s) which call the custom LowerBlit method.
The demos I’ve ported so far will only call the modified
LowerBlit function via SDL_UpdateRect(s), so the intermediate
drawing won’t be visible–in other words, both the old and
new SDL_LowerBlit may be used by a program; in general if
a program calls SDL_UpdateRect(s) then it’s time to draw to the
custom hardware; otherwise the software is just prepping rects
to blit later.

So far, I can display demos which use shadow
surfaces at 8 or 32 bpp. Demos which I’ve been able to
get working so far are water, xflame, fire and aliens. Also
the TTF demo (showfont).

I can’t display SDL_VideoSurfaces since they are blitted differently.
Demos which don’t work properly are founts and warp, since they
use SDL_VideoSurfaces rather than shadow surfaces.

Can anyone point me to where the internals of an SDL_VideoSurface
are defined, so that I can put my driver’s hooks in the appropriate
places to intercept the pixel data, and blit it to my hardware? I
believe that SDL_VideoSurface is tied closely to the X server on
my system, and I’m trying to avoid getting too heavily into that.
My goal is to be able to get the demo apps working with a minimum
of modifications…

Any ideas or suggestions appreciated.

Thanks,

Steve Madsen
H2Eye Ltd
24-28 Hatton Wall
London EC1N 8JH
Tel: +44-171-404-9600
Fax: +44-171-404-9490
Email: @Steve_Madsen

I’ve managed to get partial SDL support for our custom
hardware by integrating calls to my device driver within the SDL
library.

What you probably want to do is write your own custom video driver
which people can then enable via an autodetection routine or an
environment variable.

The low level video driver interface is defined in:
src/video/SDL_sysvideo.h

Most of the functions listed are optional, so it shouldn’t be too
much work to implement a simple driver.

I should implement a simple framebuffer driver that can be used as
a sample when programming custom hardware. In the meantime, you can
look at the framebuffer console driver, which is probably close to
what you want:
src/video/fbcon/SDL_fbvideo.c

See ya!
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec