News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

CopyRect does not work with sprites

Started by ale870, September 26, 2006, 01:50:37 AM

Previous topic - Next topic

ale870

Hello,

in order to speed-up video refresh (FPS are important!) generally I don't use function CLS to clear the screen, but I maintain, when possible, a copy of background image and I use the command CopyRect to "delete" screen" area (I copy the original background image on the screen: it means it will overwrite current contents).

The problems is CopyRect does not affect drawings done by sprites.

Here an example:

; PROJECT : Project1
; AUTHOR  :
; CREATED : 25/9/2006
; EDITED  : 25/9/2006
; ---------------------------------------------------------------------

Explicit

// Load image TILE

Local tile1 = GetFreeImage()
LoadImage "ground01.jpg", tile1

// Sprite

Local imgSportinaTile = GetFreeImage()
LoadImage "SPORTROSSA128.png", imgSportinaTile

// Get single image to be used for sprite

Local imgSportina = GetFreeImage()

RenderToImage imgSportinaTile
GetImage imgSportina, 0, 0, 127, 127
RenderToScreen

PrepareFXImage imgSportina
ImageMaskColour imgSportina, RGB(255, 0, 255)

// Set sprite details

Local sprSportina = GetFreeSprite()
CreateSprite sprSportina
SpriteImage sprSportina, imgSportina

Ink $ffffff

PositionSprite sprSportina, 300, 200
SpriteTransparent sprSportina, 1
SpriteDrawMode sprSportina, 2

CenterSpriteHandle sprSportina

Local i = 0
;setfps(30)
TileImage tile1, 0, 0, 1

Do
CopyRect tile1, 0, 0, 800, 600, 0, 0, 0

Text 0, 0, FPS()

RotateSprite sprSportina, i
Inc i

DrawSprite sprSportina

Sync
Loop


WaitKey


Previous code is not correct since my CopyRect copies all the screen, but that is only a test (in the final version I copy only the area I need to update; example the sprites area). But if you execute it, you can see text is correctly "deleted" (overwritten from the original background) but the "trail" of the sprite is not deleted! :o

I cannot understand such phenomenon. Can you help me?

One thing more: can you suggest me another good way to update specific are on the screen?

Thank you!
--Alessandro

kevin

#1
   Sounds like a product of double buffering.

  The screen is really two buffers,  visual and hidden (or front and back if you like).   We see the front buffer while rendering takes place on the back buffer.  During a sync the buffers are swapped.  How they are swapped is up to your video card !. Some drivers copy the buffers, most redirect the hardware to the front->back, and back ->front surface. (ie. a pointer swap)

   If you selectively update sections of an image to the screen (back buffer),  then you'll need to update this section on both copies of the screen (Back and front buffers).  Which is going to be more trouble than it's worth.


    PlayBASIC Documentation: SYNC

ale870

Oh... I see.

Can you suggest me a technique to speed-up the update, even if I need to use camera?
I ask this because all the buffering techniques "eat" several FPS (more than 100 on my pc, and even more!).

You are expert people, so can you help me to gain useful FPS (generally speaking).

Thank you!  :)
--Alessandro

kevin


kevin


  A general rule is not to draw text real time. Text is awfully slow and can result in some rather large performance hits.. 

ale870

About text performance... I already made some tests and red the documentation.

About general performance... I will look for the topic you suggested me  :)

Thank you Kevin!
--Alessandro