Choris
Choris

Reputation: 57

how to draw 3d object with opengl es in android ,with org.opencv.android.javacameraview as background

i want to use org.opencv.android.javacameraview as background in android phone. then i wish to use opengl es to draw some augmented reality 3d model above it. Anyone know how to implemente this. The opengl es is drived from GLSurfaceView.

Upvotes: 0

Views: 2918

Answers (2)

Howe J
Howe J

Reputation: 1

You can do it like this in your onCreate() method. Remember to setFormat(PixelFormat.TRANSLUCENT) in MyGLSurfaceView constructor:

    mGLView = new MyGLSurfaceView(this);
    setContentView(mGLView);

    mOpenCvCameraView = (CameraBridgeViewBase) new JavaCameraView(this, -1);
    mOpenCvCameraView.setCvCameraViewListener(this);
    addContentView(mOpenCvCameraView, new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

Upvotes: 0

timegalore
timegalore

Reputation: 731

I use Rajawali which is an overlay for OpenGL.

http://www.rozengain.com/blog/2011/08/23/announcing-rajawali-an-opengl-es-2-0-based-3d-framework-for-android/

I would strongly recommend you use it too as it takes a lot of the pain of OpenGL away. Anyway, what I've put below does involve some Rajawali code but the principles should be similar and you should be able to pick out what you need. If you have a look here to see the results of my work:

http://www.youtube.com/watch?v=yEioXZT-lv0

to do this I create the camera view programatically rather than in the layout xml. I had to play about a bit but the following worked for me - this goes in your onCreate method of your Activity:

mOpenCvCameraView = (CameraBridgeViewBase) new JavaCameraView(this, -1);
    mOpenCvCameraView.setCvCameraViewListener(this);

    mLayout.addView(mOpenCvCameraView);

    mSurfaceView.setZOrderMediaOverlay(true);
    setGLBackgroundTransparent(true);
    mRenderer = new OpenGLRenderer(this);
    mRenderer.setSurfaceView(mSurfaceView);
    super.setRenderer(mRenderer);

mRenderer.setCameraPosition(0, 0, 20);

OpenGLRenderer here extends RajawaliRenderer, which in turn extends GLSurfaceView.Renderer. Probably best to look at the source code for the latter two rather than reproduce here. In my OpenGLRenderer I set up the objects, camera etc. in the initScene() method. I also added a number of methods that can be called from the Activity to control the object movement etc.

My activity extends the RajawaliActivity with the key elements of that class laid out below:

public class RajawaliActivity extends Activity {
protected GLSurfaceView mSurfaceView;
protected FrameLayout mLayout;
protected boolean mUsesCoverageAa;
private RajawaliRenderer mRajRenderer;
protected boolean checkOpenGLVersion = true;
protected boolean mDeferGLSurfaceViewCreation = false;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(!mDeferGLSurfaceViewCreation)
        createSurfaceView();
}

protected void createSurfaceView()
{
    mSurfaceView = new GLSurfaceView(this);

    ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);

    mSurfaceView.setEGLContextClientVersion(2);

    mLayout = new FrameLayout(this);
    mLayout.addView(mSurfaceView);


    setContentView(mLayout);
}

I hope this helps - good luck!

Upvotes: 1

Related Questions