0 Members and 3 Guests are viewing this topic.
void setPixel(SDL_Surface *surface, int x, int y, Uint32 pixel){ int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: *p = pixel; break; case 2: *(Uint16 *)p = pixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break; case 4: *(Uint32 *)p = pixel; break; }}Uint32 getPixel(SDL_Surface *surface, int x, int y){ int bpp = surface->format->BytesPerPixel; Uint32 value; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: value = *p; break; case 2: value = *(Uint16 *)p; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { value = (p[0] & 0xff) | (p[1] << 8) | (p[2] << 16); } else { value = (p[2] & 0xff) | (p[1] << 8) | (p[0] << 16); } break; case 4: value = *(Uint32 *)p; break; } return value;}void nSDL_BlitSurfaceAlpha(SDL_Surface *src, SDL_Rect *srcRect, SDL_Surface *dst, SDL_Rect *dstRect, Uint16 alpha){ int x,y; Uint32 color; SDL_LockSurface(src); SDL_LockSurface(dst); for(y = 0 ; y < srcRect->h ; y++) { for(x = 0 ; x < srcRect->w ; x++) { if((Uint16)(color = getPixel(src, x + srcRect->x, y + srcRect->y)) != alpha) { setPixel(dst, x + dstRect->x, y + dstRect->y, color); } } } SDL_UnlockSurface(src); SDL_UnlockSurface(dst);}
char curDir[256];strncpy(curDir, argv[0], strflc(argv[0], '/')); chdir(curDir);...size_t strflc(const char *src, char character){ size_t offset = strlen(src) - 1; while(offset > 0) { if(src[offset] == character) break; offset--; } return offset;}
In my program, I'm loading a bitmap with SDL_LoadBMP(path), but it seems that relative path doesn't work. If I have image.bmp.tns in the same directory as my program, just typing SDL_LoadBMP("image.bmp.tns"); doesn't work. Is there a way to fix that ?
Second question, I have sprites that have transparent parts, but it seems that transparency isn't supported due to the NTI format and get replaced by white 0xffff. Is there a way to use transparent sprites or are they forbidden ?