Hey, I completely new to SDL (been around the block a few times
with C though ;^) ). I didn’t see this addressed in the FAQs or in
the mailing list archive so I figured I’d go ahead and post it.
Using the 1.1.1-1 version of SDL with
[orion at localhost orion]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux/2.95.3/specs
gcc version 2.95.3 19991030 (prerelease)
on (code included below after signature for brevity), produces this error
message from gcc (grumbly c compiler? =) ):
[orion at localhost SDL]$ gcc -o sdltrial -lSDL -lpthread sdltrial.c
sdltrial.c: In function main': sdltrial.c:26: parse error before
*‘
sdltrial.c:27: `screen’ undeclared (first use in this function)
sdltrial.c:27: (Each undeclared identifier is reported only once
sdltrial.c:27: for each function it appears in.)
What’s up with that? (yeah, I know, prerelease compiler, but hey, it’s
worked for ~4 kernel compiles without a hitch)
(To save you reading through the code if you wish, which is basically
lifted straight from the introduction on devolution.com which I’m trying
to work through, the part it’s complaining about is:
SDL_Surface *screen; (line 26)
screen = SDL_SetVideoMode(800,600,16, SDL_HWSURFACE);
)
Am I screwing up the #include statements somehow? The odd thing is, it
seems to be finding the previous SDL stuff OK (SDL_Init et al.).
Thanks in advance!
Mike
Michael Orion Jackson*
TAMS Class of 96/UT Class of 200?*
Random Quote:*
Is it rational to lust after inanimate machines this *
much? (search for SGI or Silicon Graphics on eBay…)*******************************************************
/* compiled like this: gcc -o filename -lSDL -lpthread filename.c /
/ SDL library version is 1.1.1-1 */
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
void ShowBMP (char*,SDL_Surface*,int, int);
int main(int argc, char* argv[]) {
char file[12] = "myimage.bmp";
/* First, init. the library. */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Unable to init SDL: %S\n", SDL_GetError());
exit(1);
} else {
fprintf(stderr, "SDL initialized.\n");
}
atexit(SDL_Quit);
/* Next, init. the video display plane: */
SDL_Surface *screen; /* <--- this is the line it complains about */
screen = SDL_SetVideoMode(800,600,16, SDL_HWSURFACE);
if (screen == NULL) {
fprintf(stderr, "Unable to set 800x600x16bpp: %s\n", SDL_GetError());
exit(1);
}
/* Next, put something on it: (has to be a BMP for now, adjust
* file name above)
*/
ShowBMP(file,screen,0,0);
return 0;
}
void ShowBMP(char *file, SDL_Surface *screen, int x, int y) {
SDL_Surface *image;
SDL_Rect dest;
image = SDL_LoadBMP(file);
if (image == NULL) {
fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
return;
}
dest.x = x;
dest.y = y;
dest.w = image->w;
dest.h = image->h;
SDL_BlitSurface(image, NULL, screen, &dest);
SDL_UpdateRects(screen, 1, &dest);
}