简体   繁体   English

在OpenGL ES 3.0或2.0 Android中渲染立体3D

[英]Rendering stereoscopy 3D in OpenGL ES 3.0 or 2.0 Android

I am working with 3D objects and I'm using OpenGL ES for Android. 我正在使用3D对象,并且正在使用Android的OpenGL ES。 What I am trying to do is to implement two GLES20.glViewport() so I can have the same object twice, one in the left and one in the right. 我想做的是实现两个GLES20.glViewport()这样我可以使同一个对象两次,一次在左边,一次在右边。 I've seen tutorials for OpenGL and C++, and this is possible. 我看过OpenGL和C ++的教程,这是可能的。 But in Android it is different, because I need to call GLES20.glViewport() in the onSurfaceChanged() method. 但是在Android中则有所不同,因为我需要在onSurfaceChanged()方法中调用GLES20.glViewport() Can someone help me please? 有人能帮助我吗? Thanks. 谢谢。

Well, I know now how to do this. 好吧,我现在知道该怎么做。 If someone wants to implement this then here is my solution. 如果有人想实现这一点,那么这就是我的解决方案。

1.- Define your glViewPort() in onSurfaceChanged() method. 1.-在onSurfaceChanged()方法中定义glViewPort()。 This can have the full resolution of your screen. 这可以具有屏幕的完整分辨率。

2.- In the method that draws your left object put at the top of it: 2.-在绘制左对象置于其顶部的方法中:

GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
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. 然后进行绘图所需的所有操作,最后在方法结束时禁用剪刀测试。

GLES20.glDisable(GLES20.GL_SCISSOR_TEST);

3.- You do the same for the right object, but changing the parameters of the functions. 3.-对正确的对象执行相同的操作,但是更改函数的参数。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM