SDL blits

Started by
5 comments, last by ohohvi 21 years, 5 months ago
I''m trying to make a very basic game with sdl, but even though the program is double-buffered, the objects leave marks across the screen as they''re moved. Its not that they arent being covered, its just its ugly looking. Any ideas what would cause this?
Advertisement
hey,
I''m working on a Map editor and need a library for the graphics in Windows/Linux, I had a look at SDL and downloaded the Windows runtime libraries and the development kit thing, I set it up with VC++ just like it said (I used the precompiled binaries) but I get errors when I tried to compile the test program. Do you think you can help? but at the moment I don''t have a solution to your problem (obviously)
slip
www.ice-d.com
ohohvi: Do you clear the screen before drawing the objets? (or draw a background picture?)
slip: What errors do you have?
As I remember, you need to do:
1) In the project options, the project has to be configured as "multithreaded dll".
2) You need to link this libraries: SDL and SDL_main
3) Be sure that the compiler can find the libraries and the header files (configuring include and library directories).
ohohvi - yea you''re prob not calling SDL_FillRect() to clear the screen before drawing and flipping.

slip - check out TAN''s SDL tut for Win32 setup

Drew Sikora
Executive Producer
GameDev.net

I''m just covering up (reblitting) the areas of the background that are affected by sprites, which in this program is 6 or less. It''s just that im covering them up before redraw but i can still see it. The framerate isnt bad either.
I''ve also tried it with SDL_FillRect, but my "bullets" that are moved across the screen at 20 pixels a frame seem to leave behind a couple old copies.
Your problem is because of double buffer.
I supose you are doing this:

-Draw the objects (1)
-SDL_Flip()
-Clear the position of the objects in previous frame (ERROR!!!) (2)
-Calculate new position
-Draw the objects
....

You have two buffers. When you draw (1) you draw in one buffer, then with SDL_Flip you make this buffer visible and the other buffer is active to draw. When you try to clear the position (2) you are clearing the objets in a buffer that isn´t the buffer you use to draw it and it might contains the objets drawed two frames before. This is the cause of your problem.
He is my current game loop in puesdo code, and under SDL it looks messy. Its not that theyre not getting cleaned up, it just the animation isnt clean.

  while( grass_grows ) {  CheckInputAndUpdateSpritePosistions();  DrawABigBlackRectangleAcrossTheWholeScreen();  DrawAllMySprites();  FlipBuffers }  

This topic is closed to new replies.

Advertisement