开发者

Open GL Es 2.0 Textured Points, Code Works on XOOM, Broken on Nexus S, any thoughts?

Here is a shot of it working on a Xoom (Sorry for the sideways)

And what it looks like on a Nexus S

My best guess at the moment is that I'm not enabling something that needs to be enabled on the nexus s, but is not necessary on the xoom (or automatically enabled by the tegra opengl driver). I can tell you it's definitely not TEXTURE_2D or GL_BLEND, I'm not sure what else it could be.

I'm also disabling the depth test, for these sprites, if that's relevant.

As for relevent code, I'll do my best.

Vertex Shader

precision highp float;
attribute vec4 aPosition;
uniform mat4 uProjection;
uniform mat4 uView;

void main() {                                   
    gl_Position = uView*aPosition*uProjection;
    gl_PointSize = 100.0;
}   

Fragment Shader

precision mediump float;
uniform sampler2D sTexture;
void main() {                   
    gl_FragColor = texture2D(sTexture, gl_PointCoord);      
}   

Render Routine for the Point Sprites (obviously the geometry is kosher)

    GLES20.glEnable(GLES20.GL_TEXTURE_2D);
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    Matrix.setIdentityM(model, 0);
    mProgram.LoadProg开发者_JS百科ram();
    GLES20.glEnableVertexAttribArray(mProgram.getHandle("aPosition"));      
    GLES20.glVertexAttribPointer(mProgram.getHandle("aPosition"), 3, GLES20.GL_FLOAT, false, 0, mPoints);       
    GLES20.glUniformMatrix4fv(mProgram.getHandle("uView"), 1, false, App.getInstance().currentGameState.mCamera.view, 0);       
    TextureManager.loadTexture(mTexture, 0);
    GLES20.glDrawArrays(GLES20.GL_POINTS, 0, (int) currentMarkers);

    Es2Utils.checkGlError("Error With renderMarkers");
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glDisable(GLES20.GL_BLEND);

The mProgram.LoadProgram() is the wrapper for my shader, it's used on like 5 other shaders and not really a problem, in this case it also does this.

    if (programID != 0)  {
        GLES20.glUseProgram(programID);
    }
    Es2Utils.checkGlError("1");

    if (Es2Utils.checkGlError("GLES20.glUseProgram();") || programID == 0) {
        CompileProgram();
        GLES20.glUseProgram(programID);         
    }       
    Es2Utils.checkGlError("2");

    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
    Es2Utils.checkGlError("3");
    GLES20.glUniformMatrix4fv(getHandle("uProjection"), 1, false, Projections.getPerspective(), 0);
    Es2Utils.checkGlError("4");


Divide the problem up into two possible conditions:

a) The texture2D call is returning vec4(0.,0.,0.,1.)

b) ...somewhere after the fragment shader...

You can rule out b by changing your shader to "gl_FragColor = vec4(1.,0.,0.,1.);" or something. This case is less likely, but it's worth a try, just to make sure you're looking in the right spot.

Are your textures for the point power of 2? If not, are your wrapping modes set to GL_CLAMP_EDGE? On the SGX540 you can't wrap non-PoT textures. Also, I think you need to set the wrap mode before calling glTexImage2d.

Just a heads up, phones with qualcomm chips clip points when the center goes offscreen. So when the center of your target goes off the screen the entire target will disappear. For this reason I avoid using large points.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜