Hello all,
I just started with SDL, and I’ve been going through Marius Andra’s
excellent tutorials.
I have a problem, however; actually, a few, and I’d be very
appreciative of solutions. My system config:
- Mac OS 10.15
- 384 meg of ram
- iBook 500
- using command-line GNU tools and static library; building .APP bundle
by hand as per the README
My problem: full screen mode simply does not work. It’s strange – I
get good results with blitting and pixels in windowed modes, but once I
try full screen mode I get a black screen, lockups, and even crashes.
Here’s the code (nothing much):
//--------------------
/* test1.cpp
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include “gamedefs.h”
#include “game.h”
SDL_Surface *screen = NULL;
int main(int argc, char *argv[])
{
SDL_Surface *sprite;
SDL_Event event;
Uint8 *keys;
int i,j;
bool fullscreen = false;
bool done = false;
if (!g_init())
return (1);
screen = SDL_SetVideoMode(1024,768,16, SDL_HWSURFACE |
SDL_DOUBLEBUF | SDL_FULLSCREEN);
sprite = SDL_LoadBMP("sprite16.bmp");
if (!sprite)
crash("main: couldn't load sprite1.bmp.");
log("main: screen pixel depth is %i.", screen->format->BytesPerPixel);
/*
SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL,
sprite->format->palette->colors, 0,
sprite->format->palette->ncolors);
*/
i = screen->w/2 - sprite->w/2;
j = screen->h/2 - sprite->h/2;
// main game loop
while (!done)
{
// capture events
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
return (1);
else if (event.type == SDL_KEYDOWN)
{
// these check for independent presses
if (event.key.keysym.sym == SDLK_ESCAPE)
done = true;
else if (event.key.keysym.sym == SDLK_f)
{
fullscreen = !fullscreen;
//setmode(fullscreen);
}
}
}
// input update
keys = SDL_GetKeyState(NULL);
if (keys[SDLK_UP]) j-=4;
if (keys[SDLK_DOWN]) j+=4;
if (keys[SDLK_LEFT]) i-=4;
if (keys[SDLK_RIGHT]) i+=4;
// double check bounds... really half-assed
if (i < 0) i = 0;
if (j < 0) j = 0;
// draw
g_lock(screen);
SDL_FillRect(screen, NULL, 0);
g_drawimg(sprite, screen, i, j);
g_unlock(screen);
g_flip(screen);
}
// screenshot!
// SDL_SaveBMP(screen, "00screen.bmp");
// to keep the compiler happy
return (0);
}
//----------------------------------------------------------------------
/*
bool g_init()
Initializes low-level drivers (SDL).
Return true on success, or false on error. If false, also dumps
debug information through printf to the console.
*/
bool g_init()
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf(“Unable to initialize video subsystem (%s).\n\n”,
SDL_GetError());
return (false);
}
else
{
srand(time(NULL));
atexit(g_shutdown);
return (true);
}
}
//----------------------------------------------------------------------
/*
g_shutdown()
Does cleanup after program execution finishes.
*/
void g_shutdown()
{
// free memory here
SDL_Quit();
}
void g_drawimg(SDL_Surface *source, SDL_Surface *dest, int x, int y)
{
SDL_Rect destrect;
destrect.x = x;
destrect.y = y;
SDL_BlitSurface(source, NULL, dest, &destrect);
}
void g_lock(SDL_Surface *surface)
{
// should error checking be added?
if (SDL_MUSTLOCK(surface))
SDL_LockSurface(surface);
}
void g_unlock(SDL_Surface *surface)
{
// should error checking be added?
if (SDL_MUSTLOCK(surface))
SDL_UnlockSurface(surface);
}
I want to use full screen mode for the speed. I’ve noticed that under
Mac OS X there’s a huge speed drop among other programs that move from
full screen to windowed.
Have I missed something? Is there some trick that I should know about?
On a side note, the docs aren’t very helpful with the Mac OS X port,
and the stationary doesn’t work. Something that would be really nice
to add to the docs would be that the libSDLMain.o is created, which I
didn’t see anywhere (or maybe I just missed it?). As far as the
stationary goes, it seems to have been written for another version of
the Project Builder (or perhaps, not even for the Mac at all,
considering the port was done blindly?). I’d submit a changed version,
but I can’t figure out the stationary stuff (nothing in the PB docs),
and I’m a console builder anyways…
Another side note: the terminal traps all keyboard input if you run the
generated executable from it. Double-clicking an APP bundle works
fine, but then you don’t trap the printf()s. I don’t think this is
SDL’s problem, but all the same has anyone figured out how to get it to
not do that, and to launch the SDL window above the terminal one
instead of under it?
Thanks in advance,
- Charles Wardlaw
http://www.ministryofdoom.org/cloud/__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com