Android OpenGL纹理在Sprint三星Galaxy s2 Epic Touch 4g上看起来很糟糕

时间:2011-09-19 09:28:31

标签: android opengl-es textures

让我开始承认我是一个开放的新手 - 这简直就是一个奇迹我已经用我一直在开发的游戏做到了这一点。

HTC Evo 3d,Droid Bionic和霹雳上的纹理看起来很好。我刚买了Sprint三星Galaxy s2,纹理看起来很糟糕 - 我的理论是更大的屏幕,导致纹理磁贴过滤的dpi效果更低(我的其他理论是我不知道我在做什么)。

屏幕截图#1 Galaxy S2HTC Evo 3d的对比 屏幕截图#2 Galaxy S2HTC Evo 3d

我已经尝试启用/禁用抖动,使用16位,24位和32位纹理,将选项传递给android BitmapFactory解码方法以防止缩放,在下面的片段中禁用我的opengl设置中的每个人,设置不同的自定义组合使用setEGLConfigChooser的eglconfig值,我现在只是在黑暗中拍摄。

所以我的问题是:哪些opengl函数可以负责产生这些屏幕截图中看到的色带(?)/看起来很差的纹理?

另外值得注意的是:

  • 没有开放的错误(我记录每次开放的电话)
  • 当我添加更多光源时,应用程序性能会大幅下降(而htc evo 3d,仿生和霹雳在多个光源下的工作效果非常好)。
  • OpenGL ES 1.1(我的应用中没有GLES20)
  • 我使用min 3d framework
  • Screen&决议:
  • HTC Evo 3d:4.3“屏幕540x960分辨率
  • Samasung Sprint Galaxy s2:4.52“屏幕800x480分辨率
getWindowManager().getDefaultDisplay().getPixelFormat();
// HTC Evo 3d: 1 (PixelFormat.RGBA_8888)
// Sprint Samsung Galaxy s2: 5 (???)

我过去三天疯狂地搜索了一下,看看是否还有其他人遇到类似的问题并且什么都没发现。谢谢你的时间。

//##################        
//# setup (one time calls)
//##################

_gl.glEnable(GL11.GL_DITHER);
_gl.glEnable(GL10.GL_DEPTH_TEST);
_gl.glClearDepthf(1.0f);
_gl.glDepthFunc(GL10.GL_LESS);
_gl.glDepthRangef(0, 1f);
_gl.glDepthMask(true);
_gl.glShadeModel(GL10.GL_SMOOTH);

// Alpha enabled
_gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
_gl.glAlphaFunc(GL10.GL_GREATER, 0.1f);

// CCW frontfaces only, by default
_gl.glFrontFace(GL10.GL_CCW);
_gl.glCullFace(GL10.GL_BACK);
_gl.glEnable(GL10.GL_CULL_FACE);


//##################        
//# onSurfaceCreated
//##################

// build the lights - note this is specific to the min3d framework but 
// its pretty straightforward - if a change is made to a light source the dirty flag     is set
// and calls will be made to opengl to udpate accordingly in the onDrawFrame method
Light light1 = new Light();
light1.position.setAll(0, 10, 0);
light1.ambient= new Color4Managed(255, 255, 255, 255, light1);
light1.diffuse = new Color4Managed(255, 255, 255, 255, light1);
light1.specular = new Color4Managed(255, 255, 255, 255, light1);
light1.type(LightType.DIRECTIONAL);    
_scene.lights().add(light1);


//##################        
//# onSurfaceChanged
//##################

public void onSurfaceChanged(GL10 gl, int w, int h) {
    this.w = w;
    this.h = h;
    _surfaceAspectRatio = (float) w / (float) h;
    _gl.glViewport(0, 0, w, h);

    // all the following updates the frustum
    FrustumManaged vf = _scene.camera().frustum;
    float n = vf.shortSideLength() / 2f;
    float lt, rt, btm, top;
    lt = vf.horizontalCenter() - n * _surfaceAspectRatio;
    rt = vf.horizontalCenter() + n * _surfaceAspectRatio;
    btm = vf.verticalCenter() - n * 1;
    top = vf.verticalCenter() + n * 1;

    if (_surfaceAspectRatio > 1) {
        lt *= 1f / _surfaceAspectRatio;
        rt *= 1f / _surfaceAspectRatio;
        btm *= 1f / _surfaceAspectRatio;
        top *= 1f / _surfaceAspectRatio;
    }

    _gl.glFrustumf(lt, rt, btm, top, vf.zNear(), vf.zFar());

    Util.out("UPDATE VIEW FRUSTUM _surfaceAspectRatio: " + this._surfaceAspectRatio +     " w: " + this.w + " h: " + this.h);
    Util.out("UPDATE VIEW FRUSTUM lt: " + lt + " rt: " + rt + " btm: " + btm + " top:     " + top + " vf.zNear(): " + vf.zNear() + " vf.zFar(): " + vf.zFar());

    // sprint samsung galaxy 2s epic touch 4g
    // 09-18 23:41:31.255: INFO/System.out(14069): 2011-09-18 23:41:31> UPDATE VIEW     FRUSTUM _surfaceAspectRatio: 0.97959185 w: 480 h: 490
    // 09-18 23:41:31.255: INFO/System.out(14069): 2011-09-18 23:41:31> UPDATE VIEW     FRUSTUM lt: -0.48979592 rt: 0.48979592 btm: -0.5 top: 0.5 vf.zNear(): 1.0     vf.zFar(): 30.0

    // htc evo 3d 
    // 09-18 23:46:16.744: INFO/System.out(7958): 2011-09-18 23:46:16> UPDATE VIEW FRUSTUM _surfaceAspectRatio: 0.83076924 w: 540 h: 650
    // 09-18 23:46:16.754: INFO/System.out(7958): 2011-09-18 23:46:16> UPDATE VIEW FRUSTUM lt: -0.41538462 rt: 0.41538462 btm: -0.5 top: 0.5 vf.zNear(): 1.0 vf.zFar(): 30.0
}


//##################        
//# upload texture
//##################

int[] a = new int[1];
_gl.glGenTextures(1, a, 0); // create a 'texture name' and put it in array element 0
_gl.glBindTexture(GL10.GL_TEXTURE_2D, a[0]);

if ($generateMipMap && _gl instanceof GL11) {
    _gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
}else {
    _gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_FALSE);
}

GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, $bitmap, 0);    


//##################        
//# onDrawFrame
//##################

// draw setup
_gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);        

// enable or disable lights
if(_scene.lights().isDirty()){
    for (int glIndex = 0; glIndex < NUM_GLLIGHTS; glIndex++) {
        if (_scene.lights().glIndexEnabledDirty()[glIndex] == true) {
            if (_scene.lights().glIndexEnabled()[glIndex] == true) {
                _gl.glEnable(GL10.GL_LIGHT0 + glIndex);
                    _scene.lights().getLightByGlIndex(glIndex).setAllDirty();
                } else {
                    _gl.glDisable(GL10.GL_LIGHT0 + glIndex);
                }
                _scene.lights().glIndexEnabledDirty()[glIndex] = false; //     clear dirtyflag
            }
        }
    _scene.lights().clearDirtyFlag();
}

// handle individual light settings
Light[] lights = _scene.lights().toArray();
for (int i = 0; i < lights.length; i++) {
    Light light = lights[i];
    if (light.isDirty()) // .. something has changed
    {
        int glLightId = GL10.GL_LIGHT0 + _scene.lights().getGlIndexByLight(light);

        if (light.position.isDirty()) {
            light.commitPositionAndTypeBuffer();
            _gl.glLightfv(glLightId, GL10.GL_POSITION, light.positionAndTypeBuffer());
            light.position.clearDirtyFlag();
        }

        if (light.ambient.isDirty()) {
            light.ambient.commitToFloatBuffer();
            _gl.glLightfv(glLightId, GL10.GL_AMBIENT, ligh    t.ambient.floatBuffer());
            light.ambient.clearDirtyFlag();
        }

        if (light.diffuse.isDirty()) {
            light.diffuse.commitToFloatBuffer();
            _gl.glLightfv(glLightId, GL10.GL_DIFFUSE, light.diffuse.floatBuffer());
            light.diffuse.clearDirtyFlag();
        }

        if (light.specular.isDirty()) {
            light.specular.commitToFloatBuffer();
            _gl.glLightfv(glLightId, GL10.GL_SPECULAR, light.specular.floatBuffer());
            light.specular.clearDirtyFlag();
        }

        if (light.isVisibleBm().isDirty()) {
            if (light.isVisible()) {
                _gl.glEnable(glLightId);
            } else {
                _gl.glDisable(glLightId);
            }
            light.isVisibleBm().clearDirtyFlag();
        }

        if (light.attenuation().isDirty()) {
            _gl.glLightf(glLightId, GL10.GL_CONSTANT_ATTENUATION, light.attenuation().getX());
            _gl.glLightf(glLightId, GL10.GL_LINEAR_ATTENUATION, ligh    t.attenuation().getY());
            _gl.glLightf(glLightId, GL10.GL_QUADRATIC_ATTENUATION, light.attenuation().getZ());
        }

        light.clearDirtyFlag();
    }
}

// finally draw objects (see definition below)
foreach(Object3d $o : _scene.children()){
    drawObject($o);
}


//##################        
//# draw 3d object
//##################

_gl.glEnable(GL10.GL_LIGHTING);
_gl.glEnable(GL10.GL_TEXTURE_2D);
_gl.glEnable(GL10.GL_ALPHA_TEST);
_gl.glEnable(GL10.GL_BLEND);
_gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
_gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
_gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

$o.vertices().normals().buffer().position(0);
_gl.glNormalPointer(GL10.GL_FLOAT, 0, $o.vertices().normals().buffer());

_gl.glEnable(GL10.GL_CULL_FACE);

// draw texture function info below
drawObject_textures($o);

_gl.glTranslatef($o.position().x, $o.position().y, $o.position().z);
_gl.glRotatef(($o.rotation().x), 1, 0, 0);
_gl.glRotatef(($o.rotation().y), 0, 1, 0);
_gl.glRotatef(($o.rotation().z), 0, 0, 1);

_gl.glScalef($o.scale().x, $o.scale().y, $o.scale().z);

$o.vertices().points().buffer().position(0);
_gl.glVertexPointer(3, GL10.GL_FLOAT, 0, $o.vertices().points().buffer());

$o.faces().buffer().position(pos);

_gl.glDrawElements($o.renderTypeInt(), $o.faces().size() *    FacesBufferedList.PROPERTIES_PER_ELEMENT, GL10.GL_UNSIGNED_SHORT,$o.faces().buffer());


//##################        
//# draw texture
//##################

int minFilterType = ZoneActivity.mipmap ? GL10.GL_NEAREST_MIPMAP_NEAREST :     GL10.GL_NEAREST;

$o.vertices().uvs().buffer().position(0);

_gl.glActiveTexture(GL10.GL_TEXTURE0 );
_gl.glClientActiveTexture(GL10.GL_TEXTURE0);
_gl.glBindTexture(GL10.GL_TEXTURE_2D, $o.glTextureId);
_gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, $o.vertices().uvs().buffer());
_gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, minFilterType);
_gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);     
_gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
_gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);    
编辑:事实证明这是我。看起来像纹理问题是将不正确的值传递给雾函数的副作用(我自然从代码示例中省略了这些函数)。

// I was not converting my rgba shorts to the expected range (0.0f, 1.0f).
// the evo 3d, bionic, etc. must compensate for people like me and translate
// this to white so i never knew there was a problem
_gl.glFogfv(GL10.GL_FOG_COLOR, [255f,255f,255f,255f]);

_gl.glFogfv(GL10.GL_FOG_COLOR, [1.0f, 1.0f, 1.0f, 1.0f]);

关闭它可能是安全的。

1 个答案:

答案 0 :(得分:1)

这是一个黑暗中的刺,(我已经很久没用过GL了)但是从你发布的图片和“GL10.GL_NEAREST_MIPMAP_NEAREST”的代码行或者(甚至更糟!)“GL10.GL_NEAREST”判断,你将得到丑陋的纹理过滤。请尝试使用“LINEAR”过滤器。