can anyone please write me an example or something how to use this command. I tried it but integer returned by the function was always 0 though i locked the buffer?! :S
Help with LockedPixels
BlitzPlus Forums/BlitzPlus Beginners Area/Help with LockedPixels Have a look at this thread, it pretty much shows how to use lockedpixels in a few posts about halfway down:
http://blitzbasic.com/Community/posts.php?topic=27004
It would have been nice to have an example like that in the documentation.
Personally I 'love' lockedpixels and blitzplus. I am working on an isometric game that uses a zbuffer and prerendered scenes (also with animated zbuffers/collision maps). All the characters are stored in my own image format - in system memory rather than video memory allowing me to have thousands of frames of animation per character and the ability to still draw hundreds of them at once on screen.
http://blitzbasic.com/Community/posts.php?topic=27004
It would have been nice to have an example like that in the documentation.
LockBuffer If LockedFormat(BackBuffer())=4 Then ;ie 32bit color LockedBufferBank=LockedPixels(BackBuffer()) pitch=LockedPitch() ;length in bytes of each row of pixels (note it is not necessarily the same length as the buffer width*bitdepth) ;to poke directly to the buffer do this: ;PokeInt lockedbufferbank,4*((ScreenY)*(pitch/4)+ScreenX),RGB Next unlockbuffer
Personally I 'love' lockedpixels and blitzplus. I am working on an isometric game that uses a zbuffer and prerendered scenes (also with animated zbuffers/collision maps). All the characters are stored in my own image format - in system memory rather than video memory allowing me to have thousands of frames of animation per character and the ability to still draw hundreds of them at once on screen.
LockedPixels isn't faster than WritePixelFast?
Hold down spacebar to use WritePixelFast:
Hold down spacebar to use WritePixelFast:
Graphics 320, 240, 32, 1 Global fps# Global fpstime% While Not KeyHit(1) If Not KeyDown(57) Then Draw() Else Draw2() EndIf CountFPS() Color 0, 0, 0 Rect 10, 10, 100, 20 Color 200, 200, 200 Text 10, 10, FPS Flip Wend End Function draw() LockBuffer If LockedFormat() = 4 Then LockedBufferBank = LockedPixels() pitch = LockedPitch() For y = 0 To GraphicsHeight() For x = 0 To GraphicsWidth() - 1 PokeInt lockedbufferbank, 4 * (y * (pitch / 4) + x), (Rand(0, 255) Or (Rand(0, 255) Shl 8) Or (Rand(0, 255) Shl 16) Or ($FF000000)) Next Next EndIf UnlockBuffer End Function Function draw2() LockBuffer For y = 0 To GraphicsHeight() - 1 For x = 0 To GraphicsWidth() - 1 WritePixelFast x, y, (Rand(0, 100) Or (Rand(0, 100) Shl 8) Or (Rand(0, 255) Shl 16) Or ($FF000000)) Next Next UnlockBuffer End Function Function CountFPS() fps = 1000.0 / (MilliSecs() - fpstime) fpstime = MilliSecs() End Function
Lockedpixels is not significantly different for altering individual pixels, but for copying entire banks of pixels at once it is very quick using the copybank feature.