3D Stereoscopy rendering in OpenGL ES 2.0 and 3.0 for Android

Hey, I am new with OpenGL and I am trying to make an app for Android. The app is for the ODG R7 glasses, and I want to render an object twice, in order to have the left view and the right view for stereoscopy rendering. My problem is that I don´t know how to implement the glViewport() in Android (using JAVA) twice in the same GLSurfaceView. I’ve seen tutorials and posts solving this problem, but it is for OpenGL in C++ or C, which is totally different. In those forums and tutorials I can see that glViewport() is called more than once, and that they can have different views in the same GLSurfaceView. What I find problematic, is that in Android, glViewport() must be called in the onSurfaceChanged() method once, and that’s it. If I called again glViewport() later in my code, then it delets the previous object, and I end up with just one object, instead of two.

I already tried using glScissor(), but that’s not what I want. I also tried to render the same object twice and then do a translation, but it doesn’t work the way I want, the object ends with a different perspective, and also it’s hard to know the exact value for translation. I need to use glViewport() because I can render the object in half the width of the screen and have the object centered in each half, which is very important for the stereoscopy rendering.

The other solution I already tried was to make two different GLSurfaceViews, and I can see both objects, in the left of the screen and in the right. The big problem is that they are not synchronized because they are different java objects, and that’s important also.

P.D. Sorry for my english, it is not my native lenguage. Thanks

Well, this was a little bit funny. I was trying to solve this problem since two days and I couln’t. Now, after I already asked in this forum, I finally could do it. The way I did, if you are interested:

1.- Define you glViewPort() in onSurfaceChanged() method.
2.- In the method that draws your left object put at the top of it:

GLES20.glScissor(0, 0, width/2, height);
GLES20.glViewport(0, 0, width/2, height);

Then all that is needed for drawing, and finally at the end of the method you disable the scissor test.


3.- You do the same for the method that draws your right object, but change the parameters:

GLES20.glScissor(width/2, 0, width/2, height);
GLES20.glViewport(width/2, 0, width/2, height);

code for drawing right object


That’s all!