![]() |
|
SDL Blitting - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Graphics & Audio Programming (/forum-9.html) +--- Thread: SDL Blitting (/thread-6740.html) |
SDL Blitting - KidTsunami - Sep 20, 2003 07:21 PM I'm trying to blit sections of an SDL surface to a blank SDL surface so that I can split up textures when i load them into OpenGL. I haven't been able to successfully blit from the original surface to the blank surface. I've tried the function (destSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 128, 128, 32, rmask, gmask, bmask, amask) And I've tried just rocking a NULL surface. And they all have not worked correctly. What is an easy way to make a blank surface that I blit a section of another surface to make a bunch of textures from a larger surface. Any help would be appreciate thanks.
SDL Blitting - IBethune - Sep 21, 2003 10:12 AM In the docs it says that you need to call SDL_SetVideoMode() first so maybe you need to do something like this: Code: SDL_Surface* screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);I think this should work? SDL Blitting - sealfin - Sep 21, 2003 10:32 AM A little source which merely blits an image - sorry for the lack of comments in the code... by the way, this uses the SDL_Image libraries. Code: int main( int argc,SDL Blitting - KidTsunami - Sep 21, 2003 12:02 PM Ok, see the problem I have is not blitting to the screen, that works. My only problem is creating a blank surface and blitting to that. Here is my code: Uint32 rmask, gmask, bmask, amask; SDL_Surface * destSurface = NULL; #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif destSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 128, 128, 32, rmask, gmask, bmask, amask); // destSurface = IMG_Load (fileName.c_str()); SDL_Rect * sourceRect = new SDL_Rect (); sourceRect -> x = i * tileWidth; sourceRect -> y = j * tileHeight; sourceRect -> w = tileWidth; sourceRect -> h = tileHeight; SDL_Rect * destRect = new SDL_Rect (); destRect -> x = 0; destRect -> y = 0; destRect -> w = tileWidth; destRect -> h = tileHeight; SDL_UnlockSurface (tempSurface); SDL_UnlockSurface (destSurface); cout << SDL_BlitSurface(tempSurface, sourceRect, destSurface, NULL); SDL_Surface *screen; screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); SDL_BlitSurface (destSurface, destRect, screen, NULL); SDL_UpdateRect(screen, 0, 0, 640, 480); SDL_Delay (1000); I know thats not pretty but pretty much I'm just trying to get this to work somehow. As you can see, towards the top I have two different ways of making the destSurface surface. Currently the load image one is commented out. With that one, the blit works, but the result is a composite of the blit and the image that was already there. So I want a blank surface to blit to, but the blit just doesn't work when I rock the create RGB surface. Thanks for the help though. Any other thoughts???
SDL Blitting - alienjon - Mar 5, 2008 07:05 PM I just had the same issue. Turns out that the problem is that the format of the newly created surface doesn't match that of the screen. Converting it via: SDL_DisplayFormat(mySurface) will fix the problem like so: Code: SDL_Surface* Get_Sub_Surface(SDL_Surface* metaSurface, int x, int y, int width, int height)I know that this post originated 5 years ago, but I just had the problem myself and couldn't find a suitable answer anywhere online so I figured I'd let you guys know too :-) SDL Blitting - leRiCl - May 8, 2008 08:17 AM Code: SDL_Surface* subSurface = SDL_DisplayFormat(SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, r, g, b, a)) |