SDL_BlitSurface problem
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.
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
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
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 ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
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 ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement