简体   繁体   English

Android OpenGL ES错误地渲染compex对象

[英]Android OpenGL ES render compex object incorrectly

I'm trying to write program that draws complex non-convex object. 我正在尝试编写绘制复杂的非凸对象的程序。 But I have problem - some faces appear to be transparent. 但我有问题-有些面孔似乎是透明的。 I partially solved this by adding GLES20.glEnable(GLES20.GL_CULL_FACE); 我通过添加GLES20.glEnable(GLES20.GL_CULL_FACE);部分解决了这个问题GLES20.glEnable(GLES20.GL_CULL_FACE);

But after that I found out that it doesn't work if there are two faces with the same direction of their normals and one placed behind the other. 但是在那之后,我发现如果有两个面的法线方向相同并且一个面位于另一面后面,则该面不起作用。 In this case Open GL renders incorrectly. 在这种情况下,Open GL渲染不正确。 Also I tried to add GLES20.glEnable(GLES20.GL_DEPTH_TEST) 我也尝试添加GLES20.glEnable(GLES20.GL_DEPTH_TEST)

but I didn't attain the aim. 但是我没有达到目标。 Moreover, a half of the object vanished. 此外,一半的物体消失了。 Could you please explain me, where am I wrong? 你能解释一下我,我哪里错了?

PS To get object vertices I used Blender(I exported its data into obj file). PS为了获得对象顶点,我使用了Blender(我将其数据导出到obj文件中)。 Also I checked this data - there is right order of vertices(CCW). 我也检查了此数据-顶点的顺序正确(CCW)。

I faced the same problem. 我遇到了同样的问题。 The problem is you are not allocating size of the buffer for depth and stencil in configAttribslist. 问题是您没有在configAttribslist中为深度和模板分配缓冲区的大小。 So its not calculating the depth even when you specify DepthTest. 因此,即使您指定DepthTest,它也不计算深度。

solution: add the following lines to eglChooseConfig attribs list. 解决方案:将以下行添加到eglChooseConfig属性列表。 EGL10.EGL_DEPTH_SIZE, 8, EGL10.EGL_STENCIL_SIZE, 8, this fixed the issue for me. EGL10.EGL_DEPTH_SIZE,8,EGL10.EGL_STENCIL_SIZE,8,这为我解决了此问题。

Code: 码:

private static int[] s_configAttribs2 = { 
   EGL10.EGL_RED_SIZE, 4, 
   EGL10.EGL_GREEN_SIZE, 4, 
   EGL10.EGL_BLUE_SIZE, 4, 
   EGL10.EGL_DEPTH_SIZE, 8, 
   EGL10.EGL_STENCIL_SIZE, 8, 
   EGL10.EGL_SAMPLE_BUFFERS, 1,
   EGL10.EGL_RENDERABLE_TYPE, 
   EGL_OPENGL_ES2_BIT, 
   EGL10.EGL_NONE 

};

egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config);

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

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