Sprite Automatic Transparency (problem)

Blitz3D Forums/Blitz3D Beginners Area/Sprite Automatic Transparency (problem)

Ian Caio(Posted 2008) [#1]
Hey all,

I come with a problem:
when i load a sprite it comes with a automatic transparency.
The image is a 24 bits Bmp. i am loading it as a sprite like this: StartWeapon$="images/personageShotgun1.bmp"

Soldier=LoadSprite(StartWeapon$,1)
SpriteViewMode Soldier,1
ShotgunS(1)=LoadTexture("images/personageShotgun1.bmp",1)

EntityTexture Soldier,ShotgunS(1)

ShotgunS is a 5 elements Array. and the tag 1 can be taked of and the error persists. heres a image from the error (http://img99.imageshack.us/my.php?image=alphabetatestspyfobiajy2.jpg
)

if some one haves a idea about whats happening
thanks

cya


IPete2(Posted 2008) [#2]
Ian,

Let's take the issues one at a time.

Your post needs to be a little clearer - but it was good you posted an image so we can see what you are talking about.

From your post and the image I think you are asking why the alpha is not working? If you are then it is because to get alphas you need to use a texture flag of ',3' not ',1' when you load the image. ',1' sets the loaded image to a just a load an image with colour data.

Texture flags:
1 = load image colour
2 = load with alpha

So by adding the 1+2 = 3 we can load the colour image with alpha

Soldier=LoadSprite(StartWeapon$,1) ; just colour information

Soldier=LoadSprite(StartWeapon$,3) ; correct for loading the alpha too


Can I ask why are you using the loadtexture command? You may be better just using more Loadsprite commands. Do the same thing with the array but swap the animation.

Alternatively if this is a fully 2d game then why not simply use the LoadImage set of commands? You can do the animation using an image strip and an index counter such as shown here 'count' LoadAnimImage (filename,width,height,first,count)

Check out the docs. I personally always use png for sprites where I need alpha's.

Good luck

IPete2.


Ian Caio(Posted 2008) [#3]
Sorry about the english, its because its not my home language.

The problem isnt the fact of the Alpha be not working. actually, its the opposite, why is it working. I dont know if in the image, you can see it, but the personage is with a little Alpha. the way you can see it in the image is looking in the arm, its lighter. it should be like the body of the personage, a darker green. and the weapon on its hands, should be darker too.
I used the 1 flag, exactly because I just wanted the colors, no Alpha

yeah, I dont know, I just thought the textures would be easier, because I would use them to make the animation.

About the alpha, its still not the problem. but this bug. I can do the alpha using png, or simple painting the black details rgb 1,1,1 and using that flag that hides every black point)

cya


Ross C(Posted 2008) [#4]
So, your not wanting the alpha to appear at all, when you load a texture?

If so, blitz defaulty loads every texture with a colour flag and an alpha flag. Same with sprites. You need to only specify the color flag, as pete says. Blitz will take completely black as being completely see through and white as being solid. Everything inbetween will gradient accordinly. Even if the image doesn't not contain alpha information. (I'm not sure about .DDS textures, however)

Keep in mind also, copyrect does NOT copy any alpha information present in a texture. Just as a note.

Remember also, you can change the mask/alpha color of a texture, as masking/alpha does not work on a color basis in 3d. Blitz only does this to make it easier for you. It works on a per pixel/texel basis. It's just using colors to achieve this, is easier to do.


IPete2(Posted 2008) [#5]
Ian,

Don't worry about your English - it is fine my friend. ;)

Aha I see why you want to use sprite then! Sprites can be rotated easily and I think you could parent the sprite to another sprite (although I haven't tried that).

I think you should first just get one sprite working then build on that. It is always better to start small and build up.

Use sprites and go with the array method you have started with, you could maybe use hideentity and showentity based on which animation frame you want.

IPete2


Ian Caio(Posted 2008) [#6]
thanks for the answers :)

Ross C,
yeah, thats exactly the problem. I dont want alpha but it appears. in every sprite load.

i just made a test. putting in one of the textures a completely black, and completely white. White = solide and Black = 100% alpha. but i used the flag 1. it should work as a only color image, shouldnt it?

well, until now, i didnt used copyrect. But its helpful to know it.

"Remember also, you can change the mask/alpha color of a texture, as masking/alpha does not work on a color basis in 3d. Blitz only does this to make it easier for you. It works on a per pixel/texel basis. It's just using colors to achieve this, is easier to do."
Sorry, I didnt understand that.

IPete2,
Thanks :)

yeah, really easier to do rotation. but now its being hard to solve this bug.

yeah, you gave me an idea. i think i will do a pretty simple test. open a new project, make some basics commands (setbuffer...) load only the sprites, and try to see if it works. if it doesnt, would be easier to make it do. if it does, so the problem is in the rest of the code.

I'll update the post soon

cya


Ian Caio(Posted 2008) [#7]
Well, here is the news (Big news):

I Made some tests. the biggest result was when i changed the Flag from the loadSprite. (I could change the texture flag, and it had some colors difference, but still alpha). but when i put 2, or 3 in the flag from the Sprite, it loads without Alpha. but i didnt got it (still want to understand what happened). i though with the alpha flag, it would get the alpha information. but i am reading here the help:
(loadtexture)
2: Alpha - alpha map. If an image contains an alpha map, this will be used to make certain areas of the texture transparent. Otherwise, the colour map will be used as an alpha map. With alpha maps, the dark areas always equal high-transparency, light areas equal low-transparency.
that means if i dont use the alpha map, the image will use the colors as the alpha map?

the code:

Graphics3D 800,600
SetBuffer BackBuffer()

Camera=CreateCamera()
PositionEntity Camera,0,0,-5

Light1=CreateLight()
PositionEntity Light1,0,5,0

Dim ShotgunS(5)
ShotgunS(1)=LoadTexture("images/personageShotgun1.bmp",1)
ShotgunS(2)=LoadTexture("images/personageShotgun2.bmp",1)
ShotgunS(3)=LoadTexture("images/personageShotgun3.bmp",1)
ShotgunS(4)=LoadTexture("images/personageShotgun4.bmp",1)
ShotgunS(5)=LoadTexture("images/personageShotgun5.bmp",1)

StartWeapon$="images/personageShotgun1.bmp"

Soldier=LoadSprite(StartWeapon$,3)
SpriteViewMode Soldier,1

Map=LoadSprite("images/Minitestmap.bmp",1)
ScaleSprite Map,10,10
PositionEntity Map,0,0,1

HidePointer()

ClsColor 70,70,70

Walkframe=1

While Not KeyHit(1)

If KeyDown(200) Then
MoveEntity camera,0,0,1
EndIf

If KeyDown(208) Then
MoveEntity camera,0,0,-1
EndIf

If KeyHit(2) Then
Walkframe=1
EndIf

If KeyHit(3) Then
Walkframe=2
EndIf

If KeyHit(4) Then
Walkframe=3
EndIf

If KeyHit(5) Then
Walkframe=4
EndIf

If KeyHit(6) Then
Walkframe=5
EndIf

EntityTexture Soldier,ShotgunS(Walkframe)

UpdateWorld()
RenderWorld()
Locate 0,0

Flip
Cls
Wend
End



IPete2(Posted 2008) [#8]
Ian,

Can you post the images too so we can see what you are seeing? That way we can investigate the images themselves.


IPete2.


Ross C(Posted 2008) [#9]
ClearTextureFilters will definetly work, but, it will also disable mipmaps from working, so make sure when loading your textures you use the mipmap load flag.

If you don't want to do that, you could use the copyrect command to copy the entire texture back onto itself, wiping any alpha from the texture.


Ian Caio(Posted 2008) [#10]
Hey,

IPete2,
Sorry man, Im gonna have to upload the images later (only time to make a quick answer)

Ross C,
I will Study this commands, see what they do, and make some tests.

cya


Ian Caio(Posted 2008) [#11]
hey all,

Sorry for not uploading the images yet, and im gonna have to disappoint you again :/, Im having some tests this week, its gonna be hard to upload anything, but I will do it as soon as possible.

cya


IPete2(Posted 2008) [#12]
no probs, we will wait - good luck in your tests btw.

IPete2.


Ian Caio(Posted 2008) [#13]
Im having trouble uploading some stuff here, I tryied to upload a video of the program, but youtube wasnt really uploading it..
just to keep you updated

cya


Ian Caio(Posted 2008) [#14]
Here is the video i was trying to upload:

http://www.youtube.com/watch?v=zIyaMkSV5BU

cya


Kryzon(Posted 2008) [#15]
One of the scenes in that video has a sprite in Alpha mode. The white corners are 100% solid while the rest of it is semi-transparent because it's not a maximized 255 RGB value.

You need to repaint the white parts to 100% black (meaning, 0,0,0 RGB) and then load the sprite with the Masked flag (4, just 4, and nothing else. Perhaps 4 + 1 if you really wanna be precise of what you are doing).

That should work. Remember, it won't change anything if you don't paint the white parts black. You really need to this in order for the Masked flag to work.


IPete2(Posted 2008) [#16]
Ian,

E-mail me the images and the code - and let me sort it out for you.

peter@...

IPete2.


Ian Caio(Posted 2008) [#17]
rafael,
actually, what I am trying to discover now, is the motive of the error. if I load the sprite with the flag 1 it still has alpha. I can load the textures and the sprite with the flag 1 and it still have the alpha. I think the problem is in the sprite. I already modified the images to use it with the Flag 4. but the problem now is discover why all that happened.

IPete2,
The Email was sent IPete2 :)

cya


IPete2(Posted 2008) [#18]
ian,

9 hours later...

I haven't received an email - do you want to put the files somewhere I can grab them via a link?

IPete2.


Ross C(Posted 2008) [#19]
Blitz automatically applies alpha to a sprite. You need to call cleartexturefilters() then load it in with the appropriate flags.

Failing that, delete the alpha info, using the code i suggested.


Kryzon(Posted 2008) [#20]
Well, if the problem is over, then I think there's no need to dwell on why it happened in the first place. Sometimes it's just luck :D

Sometimes it's the videocard (all kinds of weird alpha glitches), sometimes it's weird electrons playing a prank on you.

I'd suggest to move on (taking note of the proper steps defined on how to avoid the problem next time, if it comes back).

PS: Yeah, the ClearTextureFilters(), followed by loading your sprites with the proper flags you want should work too.

Good luck with your project!


Ian Caio(Posted 2008) [#21]
IPete2,
Im gonna upload it, just gotta find a website. Do you have some in mind?

Ross C,
So blitz automatically applies alpha to a sprite?
well, I tryied the cleartexturefilters(), but it didnt work. and that alpha info you mentioned, is on the Image or in the program?

Rafael_blitz,
Yeah, I know its over, but if I find out why it happened it might be some good learning

cya


Ross C(Posted 2008) [#22]
Blitz, upon loading a sprite, via a texture, it applies alpha to the texture, regardless of whether it has alpha on it, based on the darkness/lightness of the pixels in the texture.

Blitz actually writes alpha information, that is stored on the image itself.


Ian Caio(Posted 2008) [#23]
Sorry I took long to reply

Ross C,
i think i got it, so he aplies the alpha to the texture when we load it by the sprite. but i still am confused why even when i use the flag 1, he still haves the alpha. Does he activate it without caring about which flags did you use?

cya


Ian Caio(Posted 2008) [#24]
I Uploaded (Finally!!) the code in 4Shared, the only note is that its in a txt file (hard to explain now).

http://www.4shared.com/file/63918051/73d6052b/Spyfobia_Beta_01__bug_tests_.html

cya


Ian Caio(Posted 2008) [#25]
Anybody found out something?

cya


Ian Caio(Posted 2008) [#26]
nobody? ^^


Ross C(Posted 2008) [#27]
Sorry, i didn't realise you posted anything :o) If it's a .bb i won't be able to look till i get home i'm afraid.


Ross C(Posted 2008) [#28]
Just as a matter of being tidy, i think your creating a memory leak if you use this code:


;If KeyHit(2) Then
;FreeEntity Soldier
;Soldier=LoadSprite(StartWeapon$,1)
;ShotgunS(1)=LoadTexture("images/personageShotgun1.bmp",1)
;EndIf


Your freeing the sprite, and reloading it. Fair enough. BUT your also loading a texture into the same place the previous texture was. Now you have no reference to the last texture and it will sit in memory, thus creating a memory leak.


Ross C(Posted 2008) [#29]
All of the images you have here, all have white backrounds. Blitz will not automactially mask them off. Blitz will give more alpha to the darker pixels. I'm not sure if your asking to find bugs in the code, or the images?


Ian Caio(Posted 2008) [#30]
Ross C,

"Just as a matter of being tidy, i think your creating a memory leak if you use this code:



;If KeyHit(2) Then
;FreeEntity Soldier
;Soldier=LoadSprite(StartWeapon$,1)
;ShotgunS(1)=LoadTexture("images/personageShotgun1.bmp",1)
;EndIf


Your freeing the sprite, and reloading it. Fair enough. BUT your also loading a texture into the same place the previous texture was. Now you have no reference to the last texture and it will sit in memory, thus creating a memory leak."

i searched whats memory leak ^^. so i should have used the FreeEntity ShotgunS(1) command?

"All of the images you have here, all have white backrounds. Blitz will not automactially mask them off. Blitz will give more alpha to the darker pixels. I'm not sure if your asking to find bugs in the code, or the images?"

I think the bug is in the code ^^

cya


Ian Caio(Posted 2008) [#31]
Just to add something,

"All of the images you have here, all have white backrounds. Blitz will not automactially mask them off. Blitz will give more alpha to the darker pixels. I'm not sure if your asking to find bugs in the code, or the images?"

Actually Im not sure if its a bug, but why is the alpha appearing even with the color flag?

cya


Ian Caio(Posted 2008) [#32]
i mean, why the Blitz is giving alpha to the darker pixels, even when i put, for example, a solid flag? is this kind of a standard?

Sorry for still bothering you all with it, its because Im still confused about it.

cya