Entityalpha() bug??
BlitzMax Forums/MiniB3D Module/Entityalpha() bug??
| ||
Function check_picked_tiles() For Local t:tile_set = EachIn tile_list If m_picked = t.mesh EntityAlpha t.mesh, 0.50 'FreeEntity t.mesh 'ListRemove tile_list, t Else EntityAlpha t.mesh, 1.0 EndIf Next If m_picked Then Print "PICKING!!!" End Function The code above works if I use Tmesh instead of Tentities - if I use Tentities then only the last Tentity in the list will be set to 0.5 alpha if it is picked - all the others register as being picked but no alpha changes take place...or they all completely disappear except the 'picked' tile which gets alpha set to the correct 0.5. What's going wrong - anybody please? TMeshes use too much ram compared to Entities. By the way - they get deleted fine if they are picked! Just the alpha doesn't change :( |
| ||
For Local t:tile_set = EachIn tile_list EntityAlpha (t.ent, Rnd(0.0, 1.0)) Next GAAAH!!! This works!! It sets them all randomly no problem! |
| ||
Can anybody fix this? Honestly it's bloody weird and frustrating. If I set the alpha value in the tile list (EntityAlpha t.mesh, 1.0) to 0.999999 instead of 1.0 it all works normally!! It's got to be a simple fix =[ |
| ||
To begin with, I would advise using methods rather than functions, e.g.: t.ent.EntityAlpha(1.0) Rather than EntityAlpha(t.ent,1.0) The latter way only calls the former method anyway, and so is slower, and occasionally there may be a bug where a parameter isn't being passed from the function to the method. If you want me to take a look, send me a working sample (including media) that demonstrates the problem in the smallest possible amount of code. |
| ||
Okay - I ripped out the problem code and it will run where ever the miniB3D 'inc' folder & "minib3d.bmx" is. Main tile response function is at the bottom of the code. As you will see -a picked tile gets a correct entityFX setting but an alpha value is ignored unless it is the very last bottom right tile to be set. Set the alpha value to 0.9999 instead of one and it all works. Also - in the main loop, try remming out the BeginMax2D() & EndMax2D() functions as this also has a strange effect on the entities - all colour is lost...so what's happening there? |
| ||
unedited, your code produces this on my mac:![]() Is that how it's supposed to look? The entities get brighter as you mouse over them. Cheers Charlie |
| ||
No they shouldn't get bigger - I think it's the 'full bright' effect. Place the mouse over the bottom right tile - it will go translucent, but none of the other tiles will when it is over them...this is why I made them 'full bright' as well, to show that the code is working correctly and that they are being picked correctly. |
| ||
Ah, i see what you mean. some of the other tiles turn translucent when the mouse is over the bottom right tile. Definitely looks like a bug! Cheers Charlie |
| ||
Bug seems to be somewhere in your code, sorry. If you use the code below: m_picked = CameraPick(camera, mx, my) If m_picked Then entityalpha m_picked, 0.5 You see that entityalpha works correctly. I tried to find what is the problem exactly, but I couldn't find it :( |
| ||
I still have this adapted version of minib3d, so it is more difficult to help. I have the usage of brushes customized. But maybe a smaller test can shed some light to this problem. The following seems to work on my version: It does in essence the same, but it is shorter, and it might be easier to debug. |
| ||
Hmmm.... something may be indeed wrong in miniB3D. The code translated to B3D works: But the same code on BlitzMax produces strange results: And it's something related to copyentity, since when creating individual cubes, instead of using copyentity, it works. |
| ||
Found it: put EntityBlend cube, 3 when creating the cubes, then they will flicker correctly! (Why it needs blendmode 3 I have no clue :P) |
| ||
Thanks for trying guys - the problem is definitely related to entities, as if you use copymesh() it will work no problem also! But maybe you're missing the actual problem in my code above? If I set the original code to just assign random alpha values to the tiles then it will work no problem anyway. The problem is to do with the alpha value 1.0 - if I set non-picked tiles to 0.999 (near as solid as possible) then it will all work as it should do and ANY picked tile will be set to 0.25 and the OTHER non-picked tiles will retain their correct values of 0.999 as well. But set that near solid value to 1.0 and only the last bottom right tile will have its alpha value set to 0.25 - all other picked tiles no matter where are ignored. Hope you see what I'm getting at. It's best to comment out the entity FX values in the bottom function so that only alpha values should change and you can see what's going wrong clearer. Also in the main loop - Rem out the updatemax2D() function calls and see what happens!!! |
| ||
Well, this seems to work as well: |
| ||
Warner - You need to go through your entity types list each loop and reset their alpha values to 1.0 if they are not picked. Then you'll see the problem.Import sidesign.minib3d Graphics3D 800, 600, 0, 2 cam = CreateCamera() MoveEntity cam, 0, 0, -15 Local list:TList = CreateList() Local org:TMesh = CreateCube() FitMesh org, -0.5, -0.5, -0.5, 1, 1, 1 For i# = -3 To 3 For j# = -3 To 3 Local cube:TEntity = CopyEntity(org) cube.brush = CreateBrush(Rand(0,255),Rand(0,255),Rand(0,255)) PositionEntity cube, i, j, 0 ListAddLast list, cube EntityPickMode cube, 2 Next Next FreeEntity org Repeat If MouseHit(1) CameraPick cam, MouseX(), MouseY() For e:TEntity = EachIn list If e:TEntity =PickedEntity() EntityAlpha e:TEntity, 0.15 Else EntityAlpha e:TEntity, 1 EndIf Next End If RenderWorld Flip Until KeyHit(27) In this case only the top right tile is affected if you click it. |
| ||
This also works - using CopyMesh instead of CopyEntity. |
| ||
If you open up TMesh.bmx, there is the following piece of code. It should be changed:' if surface contains alpha info, enable blending If surf.alpha_enable=True glEnable(GL_BLEND) glDepthMask(GL_FALSE) Else glDisable(GL_BLEND) glDepthMask(GL_TRUE) EndIf Seems replacing these lines by the following works: |
| ||
I just changed a bunch of things, and suddenly it started working! What I *remember* I changed: On functions.bmx GetEntityBrush returned nothing! It was missing the RETURN keyword. Function GetEntityBrush:TBrush(ent:TEntity) Return TBrush.GetEntityBrush(ent) End Function On the sample, I created a brush for every cube, even the original one - since TMesh.CreateCube() doesn't create a default brush. On TBrush.bmx, on CreateBrush, before the return brush, I added: brush.blend=1 brush.fx=0 (those are the default values on blitz3D, but they weren't set on miniB3D) Also, o TEntity.bmx, in the TEntity type I changed: 'Field brush:TBrush=New TBrush Field brush:TBrush=CreateBrush(255,255,255) On TMesh.bmx, before the "update matrix" comment I added: mesh.brush.CreateBrush(255,255,255) mesh.paintmesh(mesh.brush) and so far, the code below works: The only strange thing is, that if I set alpha=1 on the copied cubes, it doesn't work again. |
| ||
Ah! Thanks to Warner, there's the final piece! Edit: Nope, still bugs out the rendering order on the bird.bmx demo What worked here (for both that sample and the birds demo) was this: Change this: ' if surface contains alpha info, enable blending If surf.alpha_enable=True glEnable(GL_BLEND) glDepthMask(GL_FALSE) Else glDisable(GL_BLEND) glDepthMask(GL_TRUE) EndIf To this: ' if surface contains alpha info, enable blending If surf.alpha_enable=True glEnable(GL_BLEND) glDepthMask(GL_FALSE) Else glDisable(GL_BLEND) glDepthMask(GL_TRUE) EndIf If alpha>0 And alpha<1 Then glEnable(GL_BLEND) Edit: improved the fix, now it's faster and working as it should! |
| ||
Thank you guys! Heroes you are! This should be reported to Simon so he can include it in an update for MiniB3D. Great detective work!! |
| ||
Yes, will fix this in the main release. Good work guys. |