[SDL] Small Blit program won't run unless breakpoint set (Mac/XCode)
Michael Ryan Bannon
ryan.bannon at humagade.com
Mon Jul 3 08:41:54 PDT 2006
Sorry...I was not doing an SDL_UpdateRect on the display surface. The jpeg
appears each time, but the alpha calls that I'm doing still don't seem to be
working.
"Michael Ryan Bannon" <ryan.bannon at humagade.com> wrote in message
news:e8b8ck$olg$1 at sea.gmane.org...
> Hello,
>
> In the attempts to make an example for another problem I was having, I
> started to put together a code sample. But, naturally, I can't get the
> code sample to work.
>
> The following is the beginning of my sample. Two problems: first, it only
> works if I set a breakpoint early in the "main" and second, the alpha
> calls aren't doing anything.
>
> ==========================================
> #include <Carbon/Carbon.h>
> #include <SDL/SDL.h>
> #include <SDL_image/SDL_image.h>
>
> void GetPixelData(void** aData, int* aSize, const char* aPath)
> {
> // Get file ref.
> FSRef fileRef;
> FSPathMakeRef((const UInt8*)(aPath), &fileRef, NULL);
>
> // Get catalog info and data fork name (which is nothing).
> FSCatalogInfo catalogInfo;
> FSGetCatalogInfo(&fileRef, kFSCatInfoDataSizes, &catalogInfo, NULL,
> NULL, NULL);
> HFSUniStr255 dataForkName;
> FSGetDataForkName(&dataForkName);
>
> // Open data fork.
> SInt16 dataForkNumber = -1;
> OSStatus error = FSOpenFork(&fileRef, dataForkName.length,
> dataForkName.unicode, fsCurPerm, &dataForkNumber);
>
> // Get position of fork.
> SInt64 position = -1;
> error = FSGetForkPosition(dataForkNumber, &position);
>
> // Set size.
> *aSize = catalogInfo.dataLogicalSize;
>
> // Read the fork.
> ByteCount actualCount;
> *aData = new char[*aSize];
> error = FSReadFork(dataForkNumber, fsFromStart, position, *aSize,
> (void*)(*aData), &actualCount);
>
> // Close the fork.
> FSCloseFork(dataForkNumber);
> }
>
>
> int main(int argc, char*argv[])
> {
> // Initialize SDL with the given driverName. This driver is specified by
> setting the
> // environment variable, "SDL_VIDEODRIVER" to driverName.
> int error = SDL_Init(SDL_INIT_VIDEO);
> SDL_putenv("SDL_VIDEODRIVER=Quartz");
>
> // Create window and display surface.
> SDL_Surface* pDisplaySurface = SDL_SetVideoMode(800, 600, 32,
> SDL_SWSURFACE);
> pDisplaySurface->format->Amask = 0;
>
> // Get pixel data.
> void* pPixelDataOne;
> int sizePixelDataOne = 0;
> GetPixelData(&pPixelDataOne, &sizePixelDataOne, "/1.jpg");
>
> // Create surfaces.
> SDL_RWops *rwOne = SDL_RWFromMem(pPixelDataOne, sizePixelDataOne);
> SDL_Surface *pSurfaceOne = IMG_Load_RW(rwOne, 0);
>
> // 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);
> }
>
> return 0;
> }
> ==========================================
>
> Please note that I'm using XCode 2.3 on Mac OS 10.4.6. The SDL frameworks
> are universal binary (as is my project). The code is experiencing
> problems with both the PPC and i386. Also I just stuck my jpg resource
> (1.jpg) in the volume root...I'm lazy.
>
> Thanks,
>
> Ryan
>
> ps - I now it sounds stupid that I couldn't make a simple sample even
> though I had an already working bigger SDL project, but I'm working on a
> port...so it wasn't originally my code :)
More information about the SDL
mailing list