让我先言承认我是一个开放的新手 – 这简直就是一个奇迹我已经用我一直在开发的游戏做到了这一点.
纹理在HTC Evo 3d,Droid Bionic和霹雳上看起来很好.我刚刚购买了Sprint三星Galaxy s2,纹理看起来很糟糕 – 我的理论是更大的屏幕,并产生了更低的dpi效果纹理mag过滤(我的另一个理论是我不知道我在做什么).
截图#1 Galaxy S2与HTC Evo 3d
屏幕截图#2 Galaxy S2 vs. HTC Evo 3d
我尝试使用16位,24位和32位纹理启用/禁用抖动,将选项传递给android BitmapFactory解码方法以防止缩放,在下面的片段中禁用我的opengl设置中的每个人,设置自定义eglconfig值的不同组合setEGLConfigChooser,我现在只是在黑暗中拍摄.
所以我的问题是:哪些opengl函数可以负责产生这些屏幕截图中看到的色带(?)/看起来很差的纹理?
另外值得注意的是:
>没有开放的gl错误(我记录每个open gl调用)
>当我添加更多光源时,应用程序性能会大幅下降(而htc evo 3d,仿生和霹雳在多个光源下的工作效果非常好).
> OpenGL ES 1.1(我的应用程序中没有GLES20是)
>我使用min 3d框架
>屏幕&解析度:
> HTC Evo 3d:4.3“屏幕540×960分辨率
> Samasung Sprint Galaxy s2:4.52“屏幕800×480分辨率
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]);
关闭它可能是安全的.
解决方法:
这是在黑暗中刺伤,(我没有使用GL多年)但从你发布的图像和代码行判断“GL10.GL_NEAREST_MIPMAP_NEAREST”或(甚至更糟!)“GL10.GL_NEAREST”,你是会得到丑陋的纹理过滤.请尝试使用“LINEAR”过滤器.
标签:android,opengl-es,textures 来源: https://codeday.me/bug/20190709/1418322.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。