CopyPixelFast() doesn't work
Blitz3D Forums/Blitz3D Beginners Area/CopyPixelFast() doesn't work
| ||
Trying to write data to the front buffer, I find CopyPixelFast doesn't work - I get a memory access error. Running the example code gives exactly the same problem, and mangles the mouse pointer graphic. The faulty code is listed here pic=LoadImage("media/blitz_pic.bmp") LockBuffer For y=0 To (ImageHeight(pic)/2)+ImageHeight(pic) For x=0 To ImageWidth(pic) CopyPixelFast x,y,ImageBuffer(pic),x,y Next Next UnlockBuffer WaitKey() I've tried cahnging buffers, locking FrontBuffer() and ImageBuffer(), but nowt works. |
| ||
You need to specify which buffer you're locking explicitly. i.e. Lockbuffer imagebuffer( myimage ) |
| ||
Tried that. Tried LockBuffer FrontBuffer(), LockBuffer BackBuffer(), and LockBuffer (Imagebuffer(pic)) and combinations of the three, making I sure I copy from ImageBuffer(pic) to either FrontBuffer() or BackBuffer(), whichever I've locked. Still don't work though! |
| ||
Try this code (tested):Graphics 1024, 768, 0, 1 SetBuffer BackBuffer() pic=LoadImage("test.bmp") LockBuffer ImageBuffer(pic) LockBuffer BackBuffer() For y=0 To ImageHeight(pic) For x=0 To ImageWidth(pic) CopyPixelFast x,y,ImageBuffer(pic),x,y, BackBuffer() Next Next UnlockBuffer BackBuffer() UnlockBuffer ImageBuffer(pic) SetBuffer BackBuffer() Flip WaitKey() You have to lock and unlock both buffers. Or you will get a MAV. Note: this doesn't work when using windowed mode (just found out myself). |
| ||
That works. Dunno what I missed. It also works windowed. thanks |
| ||
You sometimes have to actually specify the buffers your using. I know the docs say that if no buffer is specified, it uses the current drawing buffer, but best to put it in anyway. Some times fails if not :o) |