Problem with LoadMaskedAnimTexture() ?
Blitz3D Forums/Blitz3D Programming/Problem with LoadMaskedAnimTexture() ?
| ||
Hi all. I was wondering why this isn't removing all masked pixels no matter how big the quad / texture size is. LoadMaskedAnimTexture.bb: Here is the link to the media along with the source and a compiled version of the above source code in order to show the problem I'm having. https://mega.co.nz/#!jgthBQQZ!Dwu7HzVlLg1K5tyDYXW5Whps_FBgWl39nTWNfkd1m24 Thank You to all that help! ~GF |
| ||
Textures are loaded 32x32 32x64 64x64 64x128 etc. Power of 2 Your 4x32x48 Sprite gets obviously loaded as 4x32x64 After loading a texture you must check the actual size with TextureWidth and TextureHeight if you want to paint on it ... texture = LoadAnimTexture (f$, flags, width, height, startframe, frames) If texture tempwidth = TextureWidth(texture) tempheight = TextureHeight(texture) tBuffer = GraphicsBuffer () ; Store current graphics buffer For loop = 0 To frames - 1 ; Do each frame in turn SetBuffer TextureBuffer (texture, loop) ; Use texture frame's buffer LockBuffer GraphicsBuffer () ; Lock it for 'fast' pixel access ; Read each pixel of texture frame... For x = 0 To tempwidth - 1 For y = 0 To tempheight - 1 rgb = ReadPixelFast (x, y) And $00FFFFFF ; Read pixel, strip alpha value If rgb = trgb ;((r Shl 16) + (g Shl 8) + b) ; If pixel = rgb mask... WritePixelFast x, y, $00000000 ; ... make transparent, else... Else ; Not rgb mask pixel, so... WritePixelFast x, y, rgb Or $FF000000 ; ... make 'solid' EndIf Next Next UnlockBuffer GraphicsBuffer () ; Unlock texture buffer Next SetBuffer tBuffer ; Restore graphics buffer Return texture ; Hand back the AnimTexture... EndIf |