Is that possible for NME to not fill the background so that I can use camera preview instead

360 views
Skip to first unread message

Rocks Wang

unread,
Dec 16, 2012, 1:45:09 PM12/16/12
to haxe...@googlegroups.com
Hi folks,
I am doing the study about how to embed the camera preview in NME app (Android), I was tried the approach to add the camera preview SurfaceView into GameActiviy (with addContentView method), under the MainView, I am sure the camera preview is working good, however since NME always fill the whole screen, so I cannot see it, I've tried SurfaceHolder.setFormat(PixelFormat.TRANSLUCENT) on NME MainView, but made no difference.
So my question is, can I do some modifications to let NME not to fill the screen with opaque background?
BTW, I was also tried using PreviewCallback to transfer raw preview image data to haxe with JNI, it's does work, however the YUV2RGB (NV21 is the only mode supported by my phone) is very costly and the performance is poor.

Regards,
Rocks

Hugh

unread,
Dec 16, 2012, 11:49:48 PM12/16/12
to haxe...@googlegroups.com
Hi,
You may also need to select a RGBA_8888 PixelFormat for your config, using:

 "EGL10.EGL_ALPHA_SIZE, 8," in the "attrs" array in org/haxe/nme/MainView.java


The clear call comes from AutoStageRender in Display.cpp, into the "HardwareSurface" header, and then into "Clear" in OpenGLContext.cpp.
This last call hardwires alpha = 1.0.  So you could edit this file and use alpha=0.0.
The best fix would be to chase the values though with a correctly set alpha value, but you could probably get away with a small change.

Hugh

Rocks Wang

unread,
Dec 18, 2012, 8:22:48 AM12/18/12
to haxe...@googlegroups.com
Hi Hugh,

Thanks a lot for your help!
Yes finally I get the camera preview displaying under the NME MainView according to your guideline, it's really cool! This will give NME the capability writing fantastic camera-based apps!
Here's my (tiny) modification to make this happen:
1. In MainView.ctor, add "setEGLConfigChooser(8, 8, 8, 8, 16, 0);" before setRenderer(), I don't know what is stencil, but this just works
2. In OGLContext.Clear, change the alpha component from 1.0 to 0.0
3. In MainActivity or GameActivity, use addContentView to add a normal camera preview SurfaceView to the activity.
BTW, I guess a similar approach should be also working on iOS target, isn't it?

Regards,
Rocks


在 2012年12月17日星期一UTC+8下午12时49分48秒,Hugh写道:

Joshua Granick

unread,
Dec 18, 2012, 8:05:45 PM12/18/12
to haxe...@googlegroups.com, Rocks Wang
Would you mind seeing if these changes also make it possible to have a transparent background on the desktop?

Add <window borderless="true" /> to your NMML, then try building for your desktop OS. If it works, it would be great to try and integrate transparency support officially
--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
 
 
 



--
Using Opera's mail client: http://www.opera.com/mail/

Hugh

unread,
Dec 19, 2012, 12:03:26 AM12/19/12
to haxe...@googlegroups.com
Hi,
I have not though too much about the ios target, but this approach should work for a VideoView to get video in NME on android.
I think that extensions should somehow be able to register native 'Views' and we could then have something like:

nme.Lib.setNativeView("CameraPreview", true /* keep haxe as overlay */, [ 640, 480 ] );
nme.Lib.setNativeView("WebView", false, ["someurl.html"] );
nme.Lib.setNativeView("VideoView", true, ["myFile.mp4"] );

And then we may be able to use the same syntax for ios.
It should not be too much work - just need to find some time.

Hugh

Rocks Wang

unread,
Dec 19, 2012, 11:21:09 AM12/19/12
to haxe...@googlegroups.com, Rocks Wang
Hi Joshua, I just tested this on windows XP, the app window became borderless, but the background was still opaque.

Rocks

在 2012年12月19日星期三UTC+8上午9时05分45秒,Joshua Granick写道:
Reply all
Reply to author
Forward
0 new messages