Skip to main content
gamedev.net
🔒 Locked

SDL pixels?

Started by Paprica 5 replies 1k views
Original Post
Paprica
Paprica
I need to save a certain surface's pixels and them draw them back when needed. How do I do it?
rip-off
rip-off
All the pixels? Just create a copy of the surface (something like SDL_ConvertSurface(surface, surface->format, 0) and then use SDL_BlitSurface() to draw them back later.

If you only need to do this for a subset of the pixels, you can create a surface of the correct size and use SDL_BlitSurface() back and forth.

If this is the screen surface and you are doing a dirty rectangle system, keep one surface the same size and just blit rectangles to/from it using the clipping rectangle parameters SDL_BlitSurface() provides. If you are redrawing more than 50% of the screen every frame it might be more efficient to just re-draw everything rather than worry about this kind of thing.

If you give us a higher level overview of your goal we can be more specific.
Paprica
Paprica
Thanks but I don't know how to do what you said
Could you post or link to some code?

[Edited by - Paprica on September 9, 2010 3:34:17 AM]
rip-off
rip-off
I gave a reasonably low level description. If you want me to write the code for you, you'll have to pay me.

Of course, I'd be willing to discuss how to solve this for free, if you were a little clearer about what part is causing you trouble. A good place to start is here.
Paprica
Paprica
I need to store a surface and then redraw its certain x/y w/h on another surface.
Storing it should not be a problem but I do not know how to access its pixels and draw them on another surface.
Gage64
Gage64
Use SDL_BlitSurface(). If you only want to draw a portion of a surface, you specify that portion in the source rectangle.

SDL_Rect srcRect = { x, y, w, h };   // The portion we want to copySDL_Rect pos = { posX, posY };   // Position on the target surface (w/h are not used)SDL_BlitSurface(mySurface, &srcRect, otherSurface, &pos);
Paprica
Paprica
Thanks Gage64!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.