Jump to content
  • Advertisement
Sign in to follow this  
Lode

drawing a texture with SDL

This topic is 4841 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Say I have a 2D array representing an RGB image, and a single graphical surface in an SDL window. What's the fastest way to draw this image at a given position in the window? I once tried something with multiple surfaces and blitting, but I was confused about it, and for some reason on some computers it was flickering (not flickering in the low FPS way, but flickering between black and the image). Drawing the image pixel by pixel didn't flicker anywhere, but is slow. And I don't want to use OpenGL this time. [EDIT] I think I'll go with OpenGL again anyway, I want to do alpha translucency, multiplying with a color, and such too. But I'm still interested in the answer to the above question :)

Share this post


Link to post
Share on other sites
Advertisement
I'd create a pointer to the top-left point for the sprite inside the screen buffer. I'd have a for(y) loop that would go from the top to the bottom of the sprite - for each y setting up a pointer to the pixel row inside your 2D array. Next I'd have a for(x) loop that just copied each pixel over (*dest++=*source++). At the end of that for(x) loop, I'd increment the pointer to the screen by (the width of the screen - width of the sprite). Naturally, this wouldn't work for sprites that are part off the screen (you'd have to do the clipping yourself), in which case it would possibly be easier to just copy the entire 2D array to a new temporary surface and use SDL to handle the blitting.
Of course, this all makes a lot of assumptions (such as the data in the 2D array being at the same bpp as the screen surface).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!