![]() ![]() Its basically that the image surface gets optimized so that the whole color keying process gets done faster. Its a bit outside the scope of this HOWTO to go into details of RLE but a good five minutes on Google typing in run length encoding will get you a good explanation if you really want one. The other two SDL_RLEACCEL and SDL_SRCCOLORKEY specify how the images will be drawn. Hence black, which is no color at all really, is red=0,green=0 and blue=0. ![]() In the SDL_MapRGB function we can tell SDL three numbers that form a color with Red, Green and Blue parts. SDL_SRCCOLORKEY tells SDL that this color key applies to the source image SDL_RLEACCEL is run lenght encoded acceleration to speed up the colorkeying SDL_SetColorKey( compatible_image, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey) Uint32 colorkey = SDL_MapRGB( compatible_image->format, 0, 0, 0) // choose black specify a colour that will be used to signify 'transparent' pixels So how can we specify what color SDL can treat as transparent? Well, when we load an image we can add a little code to take care of this: Granted, you would still see the little guy but it takes quite a bit of convincing that this is a rendered scene and not something you knocked up in windows paint! If we draw this as is, you will get a nasty black rectangle over the top of our lovely hills and sky!. ![]() If you download our example code and take a look at the image file 'sprite.bmp' you can see that our sprite is draw on a black background. By that we mean that a specially selected color will be deliberately NOT drawn when we apply the different layers to our scene. That means that all other layers infront have to be drawn as if they were a transparent film over the top. If you look closely at any 2d game you will find that most backgrounds are not ever in front of anything. Draw any scenery that goes behind your sprites So whats the standard procedure for this I hear you cry! Thats exactly how 2d games generate their scenes! er. Then if you want to change or add anything, you add an new layer on top and place new image data on it. Usually in GIMP or Photoshop you start by creating a background layer which is usually white. The reason this is true is that they both use a system of layers to create a composite image that is then displayed at the end of the process. Rendering or 'Drawing' a scene in a game believe it or not works a lot like most image manipulation packages like GIMP or Photoshop. This HOWTO covers the following subjects:Ģ) Seeing in the dark or how color keying worksģ) How to tell SDL which color to make transparent This function is available since SDL_image 2.0.0.This is the fourth HOWTO in a series of HOWTOs about game development using Simple DirectMedia Layer. When done with the returned texture, the app should dispose of it with a call to SDL_DestroyTexture(). If you would rather decode an image to an SDL_Surface (a buffer of pixels in CPU memory), call IMG_LoadTyped_RW() instead. There is also IMG_LoadTexture_RW(), which is equivalent to this function except that it will rely on SDL_image to determine what type of data it is loading, much like passing a NULL for type. There is a separate function to read files from disk without having to deal with SDL_RWops: IMG_LoadTexture("filename.jpg") will call this function and manage those details for you, determining the file type from the filename's extension. If type is NULL, SDL_image will rely solely on its ability to guess the format. ![]() SDL_image reads everything it needs from the RWops during this call in any case.Įven though this function accepts a file type, SDL_image may still try other decoders that are capable of detecting file type from the contents of the image data, but may rely on the caller-provided type string for formats that it cannot autodetect. If freesrc is non-zero, the RWops will be closed before returning, whether this function succeeds or not. Otherwise, SDL_image will attempt to create an SDL_Texture in the most format that most reasonably represents the image data (but in many cases, this will just end up being 32-bit RGB or 32-bit RGBA). If the loaded image has transparency or a colorkey, a texture with an alpha channel will be created. This can be significantly more efficient than using a CPU-bound SDL_Surface if you don't need to manipulate the image directly after loading it. RemarksĪn SDL_Texture represents an image in GPU memory, usable by SDL's 2D Render API. Non-zero to close/free the SDL_RWops before returning, zero to leave it open.Ī filename extension that represent this data ("BMP", "GIF", "PNG", etc). The SDL_Renderer to use to create the GPU texture.Īn SDL_RWops that data will be read from. SDL_Texture * IMG_LoadTextureTyped_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type) Function Parameters renderer ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |