SDL_BlitSurface problem

Started by
4 comments, last by DAharon 22 years, 2 months ago
void DrawStuff(SDL_Surface *image, SDL_Surface *screen) { SDL_BlitSurface(image, NULL, screen, NULL); } int main(void) { SDL_Surface *screen, *image; // Init SDL, set the video mode, load a bitmap into image... DrawStuff(image, screen); // Do everything to cleanly exit return 0; } ***** Why is it that the above program won''t work on my computer? All I get is a blank screen.
Advertisement
Gah!
Sheesh, this'll teach me not to read comments.
It's not as bad as I thought, your only missing a rectangle to blit to.

So in main() you declare a rectangle:

SDL_Rect dstrectangle; // a Destination Rectangle.

Then you give it attributes.

dstrectangle.x = 0;
dstrectangle.y = 0;
dstrectangle.w = image->w;
dstrectnalge.h = image->h;

Then you pass it do your DrawStuff()

And change your Blit call to:
SDL_BlitSurface(image, NULL, screen, &dstrectangle);

And vwallah.
Don't forget to check for errors.

Edit:

Bah, You also forgot to update the screen.
If inside your SDL_SetVideoMode() you set SDL_DOUBLEBUF, then all you have to do is call SDL_Flip();

Put it in a loop which called DrawStuff() and SDL_Flip(screen); And all should work.

I'm going to create this program real quick to see if you missed anything else.



-AfroFire

Edited by - AfroFire on February 1, 2002 7:52:51 PM
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein
Please check all your return values! That''s what they''re there for. Have you called SDL_UpdateRects or SDL_Flip after you draw to the screen?

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
I already said that!


-AfroFire
AfroFire | Brin"The only thing that interferes with my learning is my education."-Albert Einstein
Indeed you did There is often a time lag between when I open a post and when I respond to it, so people commonly post an answer that is similar to mine before I manage to post

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
Thanks for the help. I''ll try to use SDL_UpdateRect. I know I should always use it or SDL_Flip, but usually I don''t need to when blitting from main. Anyway, thanks for replying.

This topic is closed to new replies.

Advertisement