简体   繁体   English

我的Galaxy S4屏幕边缘点精灵消失(不在Nexus 7上)

[英]Point sprite disappears at edge of screen on my Galaxy S4 (not on Nexus 7)

I am experimenting with a particle emitter based on this code: https://code.google.com/p/sravan-work/source/browse/trunk/OpenGL+ES2/es2particles/src/es2/learning/ParticleRenderer.java 我正在尝试基于此代码的粒子发射器: https//code.google.com/p/sravan-work/source/browse/trunk/OpenGL+ES2/es2particles/src/es2/learning/ParticleRenderer.java

Currently, the particle emitter works great on my Nexus 7; 目前,粒子发射器在我的Nexus 7上运行良好; the point sprites are generated in the center of the screen and either 1) fade out or 2) fly past the edge of the screen. 点精灵在屏幕中心生成,1)淡出或2)飞过屏幕边缘。

Unfortunately, on my Galaxy S4, the point sprites disappear from the display as soon as their mid-point reaches the edge of the screen. 不幸的是,在我的Galaxy S4上,一旦它们的中点到达屏幕边缘,点精灵就会从显示屏上消失。 This causes a really unpleasant visual effect. 这会导致非常不愉快的视觉效果。

Both devices are running Android 4.3 这两款设备都运行Android 4.3

Question : Why is it that the sprites will glide off the screen on the (Asus) Nexus 7, but on the Galaxy S4 they suddenly disappear ? 问题:为什么精灵会从(华硕)Nexus 7的屏幕上滑落,但是在Galaxy S4上它们会突然消失? Is there anything that can be done to prevent the sudden disappearance ? 有什么办法可以防止突然失踪吗?

Additional notes: 补充笔记:

For the Galaxy S4 the following is printed in logcat: 对于Galaxy S4,以下内容以logcat格式打印:

12-03 00:29:15.288: I/Adreno-EGL(31137): <qeglDrvAPI_eglInitialize:316>: EGL 1.4 QUALCOMM build:  (CL4169980) 
12-03 00:29:15.288: I/Adreno-EGL(31137): OpenGL ES Shader Compiler Version: 17.01.10.SPL 
12-03 00:29:15.288: I/Adreno-EGL(31137): Build Date: 09/26/13 Thu

For the Nexus 7, the following is printed in logcat: 对于Nexus 7,以下内容以logcat格式打印:

12-03 00:14:38.144: D/libEGL(25303): loaded /system/lib/egl/libEGL_tegra.so
12-03 00:14:38.154: D/libEGL(25303): loaded /system/lib/egl/libGLESv1_CM_tegra.so
12-03 00:14:38.174: D/libEGL(25303): loaded /system/lib/egl/libGLESv2_tegra.so
12-03 00:14:38.194: D/OpenGLRenderer(25303): Enabling debug mode 0

The sprites are based on a single point in their centre, around which a texture is drawn. 精灵基于其中心的单个点,围绕该点绘制纹理。 If this point goes outside the rendering area, they are clipped, since their entire geometry is technically outside the view. 如果此点超出渲染区域,则会剪切它们,因为它们的整个几何体在技术上位于视图之外。

There might be a few workarounds to avoid the sudden dissapearance: 可能有一些解决方法可以避免突然消失:

  1. Manually fade the sprites as they approach the edge of the screen. 当精灵接近屏幕边缘时,手动淡化精灵。
  2. Extend the view/render area so that it goes "outside" the screen (not sure if this is possible). 扩展视图/渲染区域,使其“在屏幕外”(不确定是否可行)。
  3. Use squares with four vertices instead of sprites (as long as a vertex is on screen, the related triangles are not clipped) 使用具有四个顶点而不是精灵的正方形(只要顶点在屏幕上,相关三角形不会被剪裁)

For option 3: 对于选项3:
First you will have to define a square instead of a single point per particle: 首先,您必须为每个粒子定义一个正方形而不是单个点:

float verts[] = {-1, 1, 0,  1, 1, 0,  1,-1, 0,  -1,-1, 0};

Depending on how you want your particles to behave, you could remove the third coordinate of each vertex and set it to an appropriate value in the vertex shader too. 根据您希望粒子的行为方式,您可以移除每个顶点的第三个坐标,并将其设置为顶点着色器中的适当值。

Second, instead of drawing GLES20.GL_POINTS , you will have to draw triangles, with the array I posted, GLES20.GL_TRIANGLE_FAN will create a square. 其次,不是绘制GLES20.GL_POINTS ,而是必须绘制三角形,使用我发布的数组, GLES20.GL_TRIANGLE_FAN将创建一个正方形。

You will also have to set the position and size of the particle in the vertex shader. 您还必须在顶点着色器中设置粒子的位置和大小。 Something like this a_Position*size*0.5 + translate should do the trick. 这样的事情a_Position*size*0.5 + translate应该可以解决问题。 You can of course avoid the halving of the size if you either use smaller sizes or make the vertex values smaller in the verts[] array. 如果您使用较小的尺寸或在verts[]数组中使顶点值更小,您当然可以避免尺寸减半。 translate would be the calculated position of the particle. translate将是粒子的计算位置。

Note1: remember that glPointSize sets the size in pixels, but in this example the size is in world-space units. 注意1:请记住glPointSize以像素为单位设置大小,但在此示例中,大小以世界空间为单位。 A size of 10 would probably be larger than the screen in this example 大小为10可能会大于此示例中的屏幕

Note2: since you are using actual geometry instead of points now, you can use a perspective matrix to make particles that are further away appear smaller. 注意2:由于现在使用实际几何而不是点,您可以使用perspective matrix使更远的粒子看起来更小。

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

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