Sprite3D from the same source

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Sprite3D from the same source

Post 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 ?
Last edited by eddy on Tue Jun 24, 2008 9:34 pm, edited 1 time in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post 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
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post 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)
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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...
oh... and have a nice day.
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post 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...
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post 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...
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Post 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.
Post Reply