December 04, 2020, 03:32:25 am

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Locking And Unlocking Surfaces

Started by Zen, June 27, 2006, 03:25:05 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zen

As i am a noob when it comes to 2D programming, well programming in general but im not understanding why you need to lock and unlock the surfaces???

I have tried to use DrawRect with it locked and it works, however, DrawFilledRect doesnt work with the surface locked, only when unlocked.

I think thats where i have been having some problems with other things, so i guess i need to try them all again now.

Lewis

Ionic Wind Support Team

A surface needs to be locked when your directly writing to it.  Such as WritePixelFast or when using the internal memory pointer obtained with C2DSurface::GetSurfacePointer.

Any other time you don't need to explictily lock/unlock as that is handled internally.   There are a few functions that will fail if the surface is already locked since they use the hardware blitter.

C2DSurface::Fill
C2DSurface::DrawFilledRect

And the hardware expects an unlocked surface.  This will also happen with most of the sprite render modes since they also use the graphics hardware to draw the image. 

The exception being RENDER_BLKALPHA, RENDER_TRANSALPHA, RENDER_BLKROTOZOOM and RENDER_TRANSROTOZOOM which all use software to render and will work if the surface is already locked.

There are times you want to prelock the surface for speed, when using the line and pixel drawing commands in a tight loop for example.  But you have to be sure to unlock it again before using:

1) any fill funciton
2) any GDI function inherited from CWindow
3) Rendering a sprite with the exception of the modes listed above.

Paul.
Ionic Wind Support Team

Zen

Great stuff Paul, thanks a lot. I think i need to read into 2D programming a bit more as i think i have jumped into the deep end here lol.

Lewis