sprite3d transparency

Just starting out? Need help? Post your questions and find answers here.
diGGa
New User
New User
Posts: 6
Joined: Wed Jan 11, 2006 3:33 pm

sprite3d transparency

Post by diGGa »

hey
why doesnt work my code?

Code: Select all

; ###########################
;
; Projekt Titel: Mouse Avoider
; Autor: Jaap 'Thoniel.NET' Groeneveld
; Beginn: 10.1.06
; Idee: http://www.actionflash.com/mouseavoider2.php
;
; ###########################

;{/ ----- Initialisieren -----
InitSprite()
InitSprite3D()
InitMouse()
InitKeyboard()
UsePNGImageDecoder()

OpenWindow(#PB_Any, 10, 10, 640, 480, #PB_Window_ScreenCentered|#PB_Window_SystemMenu, "Mouse Avoider by Thoniel.NET /minigames")
OpenWindowedScreen(WindowID(),0,0,640,480, 1,0,0)
; OpenScreen(640,480,32,"Mouse Avoider")
;} ----- Initialisieren -----

;{/ ----- Variablen -----
; ----- Variablen Deklarieren -----
Global mx.f,my.f, Event
Global imgPlayer
; ----- Variablen Laden -----
#cfgPlayerTailLength = 4
Enumeration
        #imgPlayer
EndEnumeration

;} ----- Variablen Ende -----

;{/ ----- Strukturen -----
Structure player
        x.f
        y.f
        oldx.f
        oldy.f
EndStructure
Global spieler.player\x, spieler.player\y

Structure playertail Extends player
        remains.w
EndStructure
Dim tail.playertail(#cfgPlayerTailLength)


;} ----- Strukturen Ende -----

;{/ ----- Prozeduren -----
Procedure UpdateEngines()
        FlipBuffers()
       
        ;maus
        If GetFocus_() = WindowID()
                If WindowMouseX()>0 And WindowMouseX()<640-1 And WindowMouseY()>0 And WindowMouseY()<480-1
                        ExamineMouse()   
                        If captured = 0
                                ReleaseMouse(0)
                                captured = 1
                                MouseLocate(WindowMouseX(),WindowMouseY())
                        EndIf
                Else
                        ReleaseMouse(1)
                        captured = 0
                EndIf
        Else
                ReleaseMouse(1)
                captured = 0
        EndIf
        ; /maus     
        ExamineKeyboard()
        ClearScreen(0,0,0)   
       
        Event = WindowEvent()         
        mx=WindowMouseX()
        my=WindowMouseY() 
EndProcedure

Procedure UpdatePlayerPosition()
        spieler.player\oldx = spieler.player\x
        spieler.player\oldy = spieler.player\y
        spieler.player\x = mx
        spieler.player\y = my
EndProcedure

Procedure UpdatePlayerTail()
        Shared spieler.player\oldx, spieler.player\oldy
        For i=0 To #cfgPlayerTailLength
                tail.playertail(i)\oldx = tail.playertail(i)\x
                tail.playertail(i)\oldy = tail.playertail(i)\y
        Next
       
       
        tail.playertail(0)\x = spieler.player\oldx
        tail.playertail(0)\y = spieler.player\oldy
       
        For i = 1 To #cfgPlayerTailLength
                tail.playertail(i)\x = tail.playertail(i-1)\oldx
                tail.playertail(i)\y = tail.playertail(i-1)\oldy
        Next
EndProcedure

Procedure DrawPlayer()
        DisplaySprite3D(#imgPlayer, spieler.player\x, spieler.player\y)
EndProcedure

Procedure DrawPlayerTail()
        transparency.w = 100
        faktor.w = #cfgPlayerTailLength/100
        For i = 0 To #cfgPlayerTailLength
                transparency = transparency - faktor
                DisplaySprite3D(#imgPlayer, tail.playertail(i)\x, tail.playertail(i)\y, transparency)
        Next
EndProcedure
;} ----- Prozeduren Ende -----

;{/ ----- Start Prozeduren -----

;} ----- Start Prozeduren Ende -----

;{/ ----- Mediendaten Laden -----

LoadSprite(#imgPlayer, "player.png", #PB_Sprite_Texture)
CreateSprite3D(#imgPlayer, #imgPlayer)
TransparentSpriteColor(#imgPlayer, 255, 0, 255)

;} ----- Mediendaten Laden Ende -----

;{/ ----- Hauptschleife -----
Repeat
        UpdateEngines()

        UpdatePlayerPosition()
        UpdatePlayerTail()
       
        Start3D()
        DrawPlayerTail()
        DrawPlayer()
        Stop3D()
Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow
End
;} ----- Hauptschleife Ende ----- 
the problem is that the mousesprite/mousetailsprite is not transparent. the 255,0,255 is still on my screen...
why is that?

thanx for help
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Seems fine here.
Last edited by netmaestro on Tue Feb 21, 2006 11:12 pm, edited 2 times in total.
BERESHEIT
Truth_Seeker
Enthusiast
Enthusiast
Posts: 145
Joined: Tue Mar 01, 2005 8:41 pm
Location: Near a Computer

Post by Truth_Seeker »

Program works fine for me also. You might be seeing pink if the part you want to be not transparent on your image is anti-aliased. To get rid of all the pink you need to have non anti-aliased for the object you want displayed. When a object anti-aliased is used it smooths the edges by blending the background and the your object. Therefore the color you want transparent would not only be pink but the many variations between your object's color and the background. Which if you set all of those transparent you would end up with a non smooth edged object.

So until we have alphablending through png files (which I think is going to be in purebasic 4). We can not really do anything with anti-alias. So just remove the smoothing or anti-alias, whatever your program calls it, from the object and your program should work fine.
Thanks
Truth Seeker
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

There is probably something wrong with your image, as it should work. If The image is compressed, the transparent color won't be perfect. It must be perfect to work right.
Last edited by netmaestro on Tue Feb 21, 2006 11:13 pm, edited 2 times in total.
BERESHEIT
diGGa
New User
New User
Posts: 6
Joined: Wed Jan 11, 2006 3:33 pm

Post by diGGa »

the problem is when im not using sprite3d ive my transparency so it cant go with the image...
i will upload my image so you can test it.

http://web484.servana.de/temp/player.png

//edit
ok you're right but i dont know why my image was fucked up... i made a new one and it worked (beside this anti alias stuff)... so thx for your help...

//edit2
now im totaly confused... i made again a new "cursor" and this time it didnt work again... a 5x5 pixel one workd a 16x16 and 32x32 didnt work.
Last edited by diGGa on Fri Jan 13, 2006 8:02 pm, edited 1 time in total.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Little tip: For an image that size a .png file is going to be no smaller than a .bmp and the bmp is better quality and does not require the overhead of a decoder. Even when I'm already using a decoder for larger images in my projects, I leave the little ones .bmp for the quality.
Last edited by netmaestro on Tue Feb 21, 2006 11:15 pm, edited 2 times in total.
BERESHEIT
diGGa
New User
New User
Posts: 6
Joined: Wed Jan 11, 2006 3:33 pm

Post by diGGa »

now im totaly confused... i made again a new "cursor" and this time it didnt work again... a 5x5 pixel one workd a 16x16 and 32x32 didnt work.
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post by Max. »

Void.
Last edited by Max. on Thu Apr 06, 2006 5:48 pm, edited 1 time in total.
Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
diGGa
New User
New User
Posts: 6
Joined: Wed Jan 11, 2006 3:33 pm

Post by diGGa »

well... bmp doesnt even compress if im right
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

That's right, BMP's are uncompressed. But at small image sizes their filesize rivals that of the compressed formats. It's just the bigger images where you see a huge difference.
Last edited by netmaestro on Tue Feb 21, 2006 11:17 pm, edited 2 times in total.
BERESHEIT
diGGa
New User
New User
Posts: 6
Joined: Wed Jan 11, 2006 3:33 pm

Post by diGGa »

doesnt works... i dont unterstand this...

ive got this code

Code: Select all

TransparentSpriteColor(#PB_Any, 255, 0, 255) 
LoadSprite(#imgPlayer, "player.png", #PB_Sprite_Texture)
CreateSprite3D(#imgPlayer, #imgPlayer)


LoadSprite(#imgTileset,"tileset.png") : CreateAnimSprite(Tileset.AnimSprite,#imgTileset,32,32)
my tileseit is transparent but my cursor remains pink.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You can't use #PB_Any to set TransparentSpriteColor. It must be set to a specific sprite.
Last edited by netmaestro on Tue Feb 21, 2006 11:19 pm, edited 2 times in total.
BERESHEIT
diGGa
New User
New User
Posts: 6
Joined: Wed Jan 11, 2006 3:33 pm

Post by diGGa »

so then why is my tileset transparent?
Fred
Administrator
Administrator
Posts: 18247
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

sprite3() size should be square multiple of 2 to work (almost) everywhere. So, if you need a 5x5 sprite, do a 8x8 one with the remaining pixels as transparent (it's documented in the sprite3D doc IIRC).
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

BMP does handle RLE as well, Its just never been widely supported.
"Never say never".

PNG is lossless as said. The encoding is pretty much slow (on high compression settings of course), the decoding however is pretty fast (although PB implementation -is pnglib?- Is actually pretty slow).

If you want to save space (both in disk and memory).. and your sprites has limited amounts of color, best thing is to save them in 8bpp. (Just make sure, in the case that you've got a transparent color, for example: R=255,G=0,B=255, that you save this color in the indexed table, because if you let your program generate the index table by itself, it might only give you an approximate of said color, hence, you will have trouble with the transparency since the color is not 255,0,255 anymore in RGB, So, it is wise to lock this color on index 1 if you can).

8 bits per pixel means a byte per pixel- A pixel can have therefore one of 255 different colors which are stored in an indexing list (usualy at the header of the image file format).

I can't tell how PB handles different bpp ... However my advice is that you shouldnt mix this (ie: have some tiles with 24bpp and some others with 8bpp or less, just to prevent compatibility issues. But then again, I don't know how PB handles this internally).


If you're feeling adventurous, you can always design your own image format among with your own color space system, etc. ;)

If HDD space is an issue for you, PM me for some tips regarding image compression (both lossy and lossless).

As said, theres always a tradeoff between speed, size, etc. So choose wisely!.



(Sorry for the ugly formatting of the text, I'm just in a hurry!).
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Post Reply