Page 1 of 1

Sprite3D from the same source

Posted: Tue Jun 24, 2008 8:13 pm
by eddy
I didn't found a easy way to create some sprite3Ds from the same source (texture)

1- first solution: a new function

Code: Select all

CropSprite3D(#Sprite3D, #Sprite, x,y,w,h) ;// like CreateSprite3D
2 - second solution: using ClipSprite

Code: Select all

ClipSprite(#Sprite, x, y, Width, Height) ;// has effect on CreateSprite3D 
CreateSprite3D(#Sprite3D, #Sprite)
3- third solution: more parameters

Code: Select all

CreateSprite3D(#Sprite3D, #Sprite [, x,y,w,h]) 
If it's possible, which solution is the best for performance and compatibility ?

Posted: Tue Jun 24, 2008 8:42 pm
by Foz
I found it quite easy, this bit of code is used in my demo scroller.
It takes a long PNG of bitmapped fonts, and splits them. Each character is 64x64 pixels in size, and there are 64 of them:

Code: Select all

Dim spriteFonts.l(64)
Dim spriteFonts3D.l(64)

UsePNGImageDecoder()
Alphabet = LoadImage(#PB_Any, "nuskool_krome_64x64x32.png")

i.l = 0
For i = 0 To 63
  tempImage = GrabImage(Alphabet, #PB_Any, i*64, 0, 64, 64)
  
  spriteFonts(i) = CreateSprite(#PB_Any, 64, 64, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
  StartDrawing(SpriteOutput(spriteFonts(i)))
    DrawAlphaImage(ImageID(tempImage), 0, 0)
  StopDrawing()
  spriteFonts3D(i) = CreateSprite3D(#PB_Any, spriteFonts(i))
Next

Posted: Tue Jun 24, 2008 8:58 pm
by eddy
Foz wrote:I found it quite easy, this bit of code is used in my demo scroller.
It takes a long PNG of bitmapped fonts, and splits them. Each character is 64x64 pixels in size, and there are 64 of them:

Code: Select all

Dim spriteFonts.l(64)
Dim spriteFonts3D.l(64)

UsePNGImageDecoder()
Alphabet = LoadImage(#PB_Any, "nuskool_krome_64x64x32.png")

i.l = 0
For i = 0 To 63
  tempImage = GrabImage(Alphabet, #PB_Any, i*64, 0, 64, 64)
  
  spriteFonts(i) = CreateSprite(#PB_Any, 64, 64, #PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
  StartDrawing(SpriteOutput(spriteFonts(i)))
    DrawAlphaImage(ImageID(tempImage), 0, 0)
  StopDrawing()
  spriteFonts3D(i) = CreateSprite3D(#PB_Any, spriteFonts(i))
Next
:D
I know it's possible. But it's not the easy way to do it.
But it's technically longest way to do : duplicated resources + redrawing + copysprite3D

Sprite3D is a quad mesh, so several sprite3Ds can share the same texture source (sprite) with different UV coordinates (clipsprite)

Posted: Tue Jun 24, 2008 9:06 pm
by Kaeru Gaman
a Sprite3D is a quadro with complete Texture, thus it will be from a complete Sprite.
should be possible to change that by altering the u/v texture-coordinates of the quadro....

the question is,
how much work would it be to change this,
how much could it slow the resulting codes down and
how useful is it really...

Posted: Tue Jun 24, 2008 9:16 pm
by Foz
*scratches head*

Well, all my code is for is initial set up to generate the sprites - and it runs very quick and only runs once.

I free up the Alphabet image after the sprites have been generated, so I don't have duplicate resources in memory.

I could make it into a generic procedure where it loads the image, grabs the area and generates the sprites, frees up the memory and exits... so I don't know what it would give us...

Posted: Tue Jun 24, 2008 9:20 pm
by Kaeru Gaman
anyways, what is the use in using big big sets?
as a sprite the sets should not be bigger than the screen.

you can use single images aswell.

Posted: Thu Jun 26, 2008 6:36 am
by eddy
The part of code takes too much time
I supposed DrawAlphaImage takes more time than DrawImage.

Code: Select all

StartDrawing(SpriteOutput(spriteFonts(i))) 
    DrawAlphaImage(ImageID(tempImage), 0, 0) 
  StopDrawing() 
I tested a grid of sprites 20 x 20 = 400 sprites to load and to draw...

Posted: Thu Jun 26, 2008 9:45 am
by Foz
Post up what you trying to do, and we'll see what we can do.

Remember this is supposed to be a one off set up call, so if it has to take ages, consider a loading screen.