Page 1 of 1

LoadSprite3D with and without Alphablending

Posted: Thu Apr 30, 2009 3:53 pm
by thyphoon
If you want to load png sprite 3D with no question about Alphablending
you can use this code

Code: Select all

;************************
;LoadSprite3D with and without Alphablending
;Thanks to Ollivier, Case and Cpl.Bator (french forum)
;source : http://www.purebasic.fr/french/viewtopic.php?p=97059#97059
;************************
Procedure LoadSprite3DAlphaAuto(NoSprite.l,Filename.s,Option.l)
  If LCase(GetExtensionPart(Filename.s))="png" And ReadFile(0, Filename.s )
    FileSeek(0, 25)
    If ReadByte(0) = 6
      Debug "alpha layer"
      Option.l=Option|#PB_Sprite_AlphaBlending;
    EndIf
    CloseFile(0)
  EndIf
  If  LoadSprite(NoSprite,Filename,Option) and CreateSprite3D(NoSprite,NoSprite)
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  Endif
EndProcedure 
Ps: Excuse me for my bad english !

Posted: Thu Apr 30, 2009 8:49 pm
by thyphoon
Little Error this topic must be in Tricks 'n' Tips not in Feature Requests and Wishlists
excuse me for this error. if an admin can change this ! Thanks

Posted: Fri May 01, 2009 6:03 am
by Hroudtwolf
Hi,

Nice idea.
But the problem with this solution is, I've no control about the sprite source.
I suggest, the function should return a dataset pointer like this....

Code: Select all

Structure tSprite3DBundle
    idSprite2D.i
    idSprite3D.i
EndStructure
What about the magic numbers here....

Code: Select all

    FileSeek(0, 25)
    If ReadByte(0) = 6 
... ?

Could you explain a little bit about it?
Thanks.

Best regards

Wolf

Posted: Fri May 01, 2009 7:45 am
by thyphoon
Hroudtwolf wrote: Nice idea.
Thanks ! it's a french forum group idea ! i just do the easyest stuff :P
Hroudtwolf wrote: But the problem with this solution is, I've no control about the sprite source.
I suggest, the function should return a dataset pointer
yes it's a good idea ! the Code is public ! Every body can use and modify it !
Hroudtwolf wrote: What about the magic numbers here....

Code: Select all

    FileSeek(0, 25)
    If ReadByte(0) = 6 
Ollivier is the man who found this magic number

if you read this doc : http://www.w3.org/TR/PNG/#11IHDR

you must found the IDHR chunk and take the bits about color-type
in the table 11.1 the value for Truecolour with alpha is 6

Olliver give more explain on the french forum. but in french !
:P

http://www.purebasic.fr/french/viewtopi ... 4&start=15