Advertisement

SDL Help

Started by August 18, 2002 05:44 AM
4 comments, last by Dalik 22 years, 4 months ago
I am working on my first game and I am stuck atm. Here are my questions: In what order should I do my game loop? loop- 1. clear screen surface 2. blit backbuffer to screen 3. Test for input 4. change variables from input 5. Do any other calculations 6. Update screen surface 7. flip screen -end loop Is that the correct order? Also I want to have a few surfaces one is the screen one is the GUI one is the Playing field one is the background one is the backbuffer now I tried to blit each layer one at a time to the backbuffer then do a final blit to the screen, but I end up with errors or the screen is black. here is my blit code ------------------------------------------------------- // Blit to the screen surface if(SDL_BlitSurface(paddle, NULL, screen, &PrecDst) < 0) { fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError()); } else { fprintf(stderr, "Success in paddle blit to screen!\n"); } ------------------------------------------------------- This works but its bliting to the screen right away as I said before I want to blit all my surfaces to the backbuffer first then blit to the screen but I cant seem to do it. Any help would be great Thnx I have tried this and my app displays a black screen and runs very slow then crashes... I made a function that uses the blit code from above and its called DrawScene(); // Blit to the screen surface DrawScene(paddle, NULL, backbuffer, &PrecDst); DrawScene(paddle, NULL, backbuffer, &PrecDst2); DrawScene(backbuffer, NULL, screen, NULL); [edited by - Dalik on August 18, 2002 7:09:01 AM]
Interested in being apart of a team of people that are developing a toolkit that can help anyone product an online game? Then click here http://tangle.thomson.id.au/
ok... heres probably why you've got no reply:
SDL, from what i know, means Software Development Library.
which means that your being quite a bit ambiguous here.
try specifying what SDL your using.
but something i just noticed (bare with me if im wrong, im a newbie). why are you clearing the screen? i thought you just flipped the surfaces. clearing might cause the black screen effect you describe as you are updating at the end of your loop, then coming back and immediately clearing the screen. what chance does it have to show?

[edited by - SithLordAJ on August 18, 2002 12:35:51 PM]
Advertisement
I have no experience with SDL, but your loop seems kinda strange. Here's how I would do it:

loop-
1. Test for input
2. Do all game logic
3. Clear the surface
4. Blit everything to the back buffer
5. Flip
6. (Optional) Synch to 30-40 fps
-end loop

Besides that, make sure you CAREFULLY read the documentation. SDL is supposedly easy, but I think it's hard not to make a mistake when you don't have any books to learn from. Also, doesn't SDL provide a page flip function, so you don't actually have to blit the back buffer to the screen?

EDIT: Also, make sure you're not trying to blit to locked surfaces!



[edited by - micepick on August 18, 2002 1:37:25 PM]
First SDL means Simple DirectMedia Layer www.libsdl.org


Create the screen surface with:

SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);

flags should be something like this:
SDL_HWSURFACE | SDL_DOUBLEBUF (and SDL_FULLSCREEN if you need it)

SDL_DOUBLEBUF instructs SDL to use double buffering.
Thats why you don''t need to have a backsurface yourself.
Just draw (blit) to the screen and SDL takes care of the rest.

Draw everything to the screen and then SDL_Flip(screen);
This updates the screen.

I get the input before drawing, but you can do it in both ways.



schiggl
loop
1. Test for input
2. Do any other calculations
3. change variables from input
4. Update screen surface
5. blit backbuffer to screen
6. flip screen
7. clear screen surface
-end loop

This should be the correct order of things.

I found out the problem, but I am having trouble blitting all my images to the backbuffer then to the screen, but it works if I blit all my images to the screen.

other then that its going good.
Interested in being apart of a team of people that are developing a toolkit that can help anyone product an online game? Then click here http://tangle.thomson.id.au/
Read the above post by schiggl. You don't need to have a back buffer. Just blit everything to the screen and Flip, and SDL will take care of double buffering for you.

[edited by - micepick on August 19, 2002 10:06:33 AM]

This topic is closed to new replies.

Advertisement