Sprite Automatic Transparency (problem)

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

Hey all,

I am a user for a time, from Blitz3d (and from the website), but i am starting post in the forum now.

well, i come with a problem:
when i load a sprite it comes with a automatic transparency O.O
i dont know what can be doing it, i use Vista (need to do the Recovery Cd to format and put the XP...), 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
___________________________

and the textures like this
ShotgunS(1)=LoadTexture("images/personageShotgun1.bmp",1)

used like this
EntityTexture Soldier,ShotgunS(Walkframe)

(walkframe = from the walk loop)

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
)

Its from a game project that i am doing. Spyfobia (in english, Spyfoby, or something like that, its because i am Brazilian O.O)

if some one haves a idea about whats happening
thanks

hugs and see ya

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.

sorry, its because i am not American, or British, and 14 years old xD. so my english is not the best.

the problem isnt the fact of the Alpha be not working. 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 xD.
I used the 1 flag, exactly because i just wanted the colors, no Alpha oO

yeah, i dont know, i just thought the textures would be easier, because theres going to be a lot of animations. so i thought it would be easier to use only textures xD.

when i started to develop the gameplay, it was with LoadImage, and everything. but the problem is that the rotatecomand simple didnt worked. it was too slow (there was a strange thing, it started to rotate and started getting smooth). i heard about a tecnic (i dont know if its that one you are talking about), that you do the animations in all the 360 degrees. but the problem is, how i said before, theres a lot of animations. so i would have a extremely hard job with it.

about the alpha, its still not the problem. but this bug, it really is. (the alpha i can do with the png, or simple painting the black details rgb 1,1,1 and using that flag that hides every black point).

thanks a lot

hugs and see you

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.

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

hey,

thanks for the answers =D

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 xD. But its helpful to know it =D (less headache trying to solut problems xD)

i didnt understood that last information.
"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."
that means i can set pixel by pixel the alpha mask of the image?

IPete2,
Thank you =D

yeah, really easier to do rotation. but now its being hard to solute this bug xD. but i hope i get this bug of soon, then i can try continue the project :)

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 give you new informations about the tests soon.

hugs and see you

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 hihg-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? so i think i am understanding. and now. i can make the project walks =D. but i still want to understand this all better. (sorry if i made some stupid question xD, i am just starting to use Sprites, i still dont get it really well =D. but falling you learn :) )

the codes from the test (where i discovered that thing up there =D):

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


EDIT:
correction, the flag in the code i used was 3, not 7 as it was in the code. (now changed)

Ian,

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


IPete2.

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.

Hey,

IPete2,
I will try upload something later (because now i am going out, just have time for a fast answer. but later i will have time and i can upload somethings).

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

(when i come back i post some news)

hugs and see ya

hey all,

i am sorry, i hadnt time to upload anything. i dont know even if i am going to have today (tests week...). but if i have, i will do it. and dont worry, i will upload it. maybe tomorrow i have time because the next tests are easier (from after tomorrow). Math and english =D (if i am not wrong)

hugs and see ya

no probs, we will wait - good luck in your tests btw.

IPete2.

Thanks a Lot xD

Finally the tests are over, now i just have 2 tests next friday. 1 from school, one from a course.

well, i am trying to upload a video, but seens like it cant be uploaded. i thonk it strange because its a Avi video, and youtube should know how to converse this kind of video right? (the video was made direct from fraps)

but, while i am trying to upload something, i got some news. well. before, i created the sprite with Loadsprite. then i had to use the flag. (when i used 1, the alpha went on, when i used alpha flag (2 or 3) it didnt gave any problem when i texturized it). now i am doing some tests. if i just load the sprite, and dont give it any texture (loading it with one texture), the flag 1 still have this problem of alpha. flag 3 do anoher kind of transparency (seens like, darker colors have more alpha, and lighter less).
its really hard to say oO
if i use the command CreateSprite, in the place of the personage, appear a White Solid Black (no alpha). then when i texture it, it stays with the flag of the texture normally. like, flag 1 in the texture, no alpha, just the image. flag 3, alpha with by that way with the darker colors more alpha, lighter less. so i think the problem is not in the texture, its on the Sprite, when i load it. i dont know.

well, if you dont understand what i mean, post something, then i answer.

(maybe the upload takes sometime, sorry for this)

hugs and see you

I just uploaded a video with some tests i made. i had some work doing it xD so i hope it helps :)

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

any doubts i am here :)
(maybe the video is a little confused)

hugs and see ya

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.

Ian,

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

peter@...

IPete2.

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 :)

thanks for the help

hugs and see ya

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.

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.

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!

IPete2,
Yeah, i can try this, but probably only in the weekend, because tomorrow is the German course test. do you have some website in mind, where i can upload it? i dont remember any o.O here in the blitz website, theres no place where can we upload it?

Ross C,
So blitz automatically applies alpha to a sprite? I am starting to work with sprites now, so i dont know a lot of things xD. but with the time i will learn it :)
well, i tryied the cleartexturefilters() but it didnt had any effects. about the copyrect, i still didnt used that one, but in the weekend i will try these commands (now its late, i gotta sleep xD). (but that alpha info you mentioned, is on the Image or in the program informations?)

Rafael_blitz,
yeah, the problem is over, but i think learn is aways nice. like, later, i can help someone with the same problem, or simple prevent from another problems involving that, and even for getting more used with the commands in the language. i think it was not the video card because my friend tested too, and the problem was there o.O
yeah, dont worry, i didnt freezed the project because of the error, but i think its important to learn from that, i dont know.
i tryied this command, didnt worked. but i will do some tests with the copyrect command in the weekend.
thanks :)

hugs and see you

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.

hey,
sorry i taked too long to reply

Ross C,
i think i got it, so he aplies the alpha to the texture when whe 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?

but these alpha information, is going to be wrote, in the Image into the program (the Soldier variable for example), or he saves it in the archive?

thanks a lot

Ps: IPete2, i will try upload the program into some website, but i still gotta find which one. maybe in my blog, but i need to check how to do it.
maybe today, i can talk with a friend, that knows how to upload that in the blog. and i send you a message saying that its uploaded. the blog is http://iancaio.wordpress.com

hugs and see you

hey all,

first, sorry for taking too long to upload it. but how people say, better late then never (at least here in Brazil xD). and its because i hadnt a lot of time, and was a little lost about where to upload it. finally i uploaded it in the www.4shared.com

well,
in the zip archive, theres the paste named Imagens (or images) with the images from the game (the ones i have until now). i made that zip a time ago, but there is the instructions that resulted in bugs. instead of a .bb archive, i had to use a txt. its because i am on windows Vista, and i can save, and open the .bb files in the Blitz3d, but i cant see it in the Explorer. so i made in txt to make it easier. there are some comments in the program, i cant remember which ones, but you can look at the code.
heres the link for the download:
http://www.4shared.com/file/63918051/73d6052b/Spyfobia_Beta_01__bug_tests_.html

i am sorry again for have took so long to upload it

thanks for the help
hugs and see you

somebody found something? i still cant find the motives for the bug happen oO. if someone needs something more, you can ask me ;)

hugs and see you

nobody?

i really need some help for checking what happened. if anybody knows something. i uploaded the images, and the code (didnt uploaded the .exe because with the code you could change the things and everything).

i know we found what was wrong, but for me its important to know what was the bug. kind of, i would be learning from my misses, and maybe it could help me with this project and another ones.

thanks

hugs and see you

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.

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.

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?

Hey Ross C

"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."

Dont worry ^^, i just posted again because the forum is big, so the topic could disapear soon.

"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? nice to learn it =D

"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?"

yeah, its kind of confusing right? i am still sticked in why the bug happened you know? i found a way to pass by it, but its important to me know why it happened, to have no trouble in the future, and for learning too :)

the images are there because it was in the code so a thought it was easier ^^. i still didnt masked they, but their background is white, because how they are images and not sprites, i can mask them which color i want :) :) :).

Thanks a lot :)

hugs and see you

hey again,

just to correct a thing.

"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 i am not sure if its a bug, but its still why is the alpha appearing you know? kind of, if you change the flags theres no effects. the alpha persists, the maximum can happen is another alpha channel appear, i dont know.

thanks :)

hugs and see you

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. thats all i need to know ^^.

sorry for stay asking too much. its because i guess we should learn something with this kind of thing.

Thanks again

hugs and see you