vujadin / BabylonHx

Port of Babylon.js 3D engine to Haxe.
http:/paradoxplay.com/babylonhx
Apache License 2.0
189 stars 43 forks source link

Rendering is broken for raw texture creation #98

Closed tcaf closed 8 years ago

tcaf commented 8 years ago

Using openfl 2.6.1 and lime 2.9.1, osx/cpp target, with babylonhx-openfl setup,

Texture being used: Image of sample

Code to generate material:

var bmp:BitmapData = Assets.getBitmapData('sample.jpg');
var tex:RawTexture = RawTexture.CreateRGBATexture(bmp.image.data, bmp.width, bmp.height, scene);
var materialMesh = new StandardMaterial("sample", scene); 
materialMesh.diffuseTexture = tex; 

gives black texture,

Image of sample

if I disable mipmap, at least I get the texture but yellows seem blue: Image of sample

I tried several different raw texture calls (rgb, rgba, alpa etc) all gives weird results. I don't use any openfl functionality (no addchild or draw). Regular Texture renders fine. But raw texture fails so...

tcaf commented 8 years ago

Seems like an openfl issue, switched to lime asset loading and it just got fixed:

import lime.Assets in LMAssets;
...
var bmp = LMAssets.getImage('sample.jpg');
var tex:RawTexture = RawTexture.CreateRGBATexture(bmp.data, bmp.width, bmp.height, scene);

It would be cool if rawtexture would do the same with regular texture while loading bitmapdata so no need to hack around.

vujadin commented 8 years ago

Blue texture is openfl issue as every once in a while they change internal format of image. Its not RGB/RGBA by default anymore so you have to set it before using it: bmp.image.format = PixelFormat.RGBA32;

Regarding mipmaps, it is bhx problem and its inherited from original (bjs) code (mipmap flag is not passed properly). I'll fix this in next update (later today or tomorrow)

tcaf commented 8 years ago

That is helpful, thank you, I will use the PixelFormat for convenience. I understand the problem should stay in openfl side. Maybe there can be another static function in raw texture (CreateBGRA if order is different for e.g.) I guess we can keep this issue until mipmap implementation is recovered.

vujadin commented 8 years ago

This should be fixed now. You can use Tools.LoadImage() to get correct image data, it will always return image in RGBA format (creating mipmaps is also fixed):

var bmp:Image = null; com.babylonhx.tools.Tools.LoadImage("assets/tex.jpg", function(img:Image) { bmp = img; }); var tex = RawTexture.CreateRGBATexture(bmp.data, bmp.width, bmp.height, scene, true/false);

tcaf commented 8 years ago

Mipmap flag is working now, thank you.