Closed ramsestom closed 8 years ago
you'll have to set rgba format on your bitmapdata (it used to be default in openfl, not anymore) bmp.image.format = PixelFormat.RGBA32;
was reported here also https://github.com/vujadin/BabylonHx/issues/98
I set bmp.image.format = PixelFormat.RGBA32; alrady but it doesn't change the result. The texture still appear black
are you sure you generate correctly your bitmapdata ? is it power of 2 ?
Yes it is a power of 2 and I am pretty sure the texture is correct (I used the same code with away3D before babylonHx). Anyway, as said, I have the same problem if I use a texture asset. For eample, if you modify one of the babylonHx sample using a texture and modify part of the code loading the the texture so that you have:
var bmp:BitmapData = Assets.getBitmapData("asset_texture_path"); bmp.image.format = PixelFormat.RGBA32; var tex:Texture = RawTexture.CreateRGBATexture(bmp.image.data, bmp.width, bmp.height, scene);
rather than
var tex:Texture = new Texture("asset_texture_path", scene);
you can reproduce the issue. The texture will render black (whereas it is ok when loaded by directly creating a texture with an url). So I think the problem is with RawTexture and the createRawTexture function of the Engine class (you probably made some change into the createTexture function of the Engine class that you did not do into the createRawTexture function. Maybe would it be a good idea to have a shared and unique function to create texture from url or from raw data?)
EDIT: the problem seems to be linked to mipmaps. If I set the "generateMipMaps" parametter of the createRawTexture() function to false (it is true by default), the texture renders correctly!
The only thing which is different in your code and the one in Tools.LoadImage is that you don't create BHX Image object: https://github.com/vujadin/BabylonHx/blob/master/com/babylonhx/tools/Tools.hx#L655 but this shouldn't be a problem as you're passing correct data to createRGBATexture method... But the mipmaps problem was solved in https://github.com/vujadin/BabylonHx/issues/98 (and confirmed by user)... I'll look at this issue in a few days when I finish with adding Bullet physics to BHx :)
@ramsestom are you using the latest code? Mipmaps are fixed by https://github.com/vujadin/BabylonHx/commit/33e89af01cf43c986de4f6030746545752e78831 weeks ago.
Yes I use latest code
EDIT: I actually just realized that my forked version wasn't in sync (I thought it was). I updated to the latest version and the mipmap issue is fixed. Sorry for the inconvenience
I am trying to create a RawTexture from a BitmapData using openfl next version (so not legacy one) but I always obtain a black texture. Here is the code I use:
var bmp:BitmapData = my_function_to_create_bitmap(); var tex = RawTexture.CreateRGBATexture(bmp.image.data, bmp.width, bmp.height, scene);
I thinks the problem might have something to do with the format of pixels returned by "bmp.image.data" because I am not sure they are in RGBA format (might be ARGB one). Did anyone else succed to create a RawTexture from a generated bitmapdata using openfl next?
EDIT: I tested with an asset texture and I have the same problem if I use RawTexture. So if I do: var bmp:BitmapData = Assets.getBitmapData("assets/images/plastic.png"); var tex:Texture = RawTexture.CreateRGBATexture(bmp.image.data, bmp.width, bmp.height, scene);
the rendered texture is black
But if I load the texture using: var tex:Texture = new Texture("assets/images/plastic.png", scene);
everything is fine So how can I use RawTexture (because I need to use as texture a bitmapdata generated on the fly and not an asset)? How is the Texture class loading external assets? Did it use lime Image or its own image handler (which could explain why it works when loading an asset texture using the Texture class)?