[SDL] Small Blit program won't run unless breakpoint set (Mac/XCode)

Christian Walther cwalther at gmx.ch
Mon Jul 3 11:32:10 PDT 2006


Michael Ryan Bannon wrote:
>> But, naturally, I can't get the code sample to work.

I didn't try your code, but a few comments anyway:

- Why are you reading the file into memory before decoding it with 
SDL_image, when you could just have SDL_image read the file itself? (And 
using this complicated Carbon code at that, when simple stdio would do 
the job?)

>> #include <SDL/SDL.h>
>> #include <SDL_image/SDL_image.h>

Although I guess it doesn't matter for this sample code, I'd like to 
point out that this isn't portable. SDL.h happens to be in an "SDL" 
directory on Linux (and I guess other Unixes), so that would work, but 
SDL_image.h probably isn't in an "SDL_image" directory (or framework) 
anywhere but on Mac OS X. The portable way is to #include "SDL.h" and 
tell the compiler where it is in the platform-specific build system 
(e.g. on Mac OS X add "/Library/Frameworks/SDL.framework/Headers" to the 
"Header Search Paths" setting in Xcode, or specify 
"-I/Library/Frameworks/SDL.framework/Headers" on the command line). The 
same for SDL_image.h.

> the alpha calls that I'm doing still don't seem to be working.
...
>>    // Display
>>    int alpha = 0;
>>    while(true)
>>    {
>>        alpha += 10;
>>        if(alpha > 255)
>>        {
>>            alpha = 0;
>>        }
>>        pSurfaceOne->format->Amask = 0;
>>        SDL_SetAlpha(pSurfaceOne, SDL_SRCALPHA, alpha);
>>        SDL_BlitSurface(pSurfaceOne, NULL, pDisplaySurface, NULL);
>>    }

Care to explain how you expect it to work (after you add the missing 
SDL_UpdateRect)? I expect this code to blit the same image onto itself 
repeatedly in very fast succession (with varying alpha values), so 
except for the first split second you won't see anything but this image. 
Perhaps you meant to clear the display surface between blits, but even 
then you'll probably only get flicker unless you add some SDL_Delay to 
the loop.

Hope this helps

  -Christian





More information about the SDL mailing list