如何摆脱 Android OpenGL ES 中的锯齿状边缘? [英] How to get rid of Jagged edges in Android OpenGL ES?

查看:16
本文介绍了如何摆脱 Android OpenGL ES 中的锯齿状边缘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glClearDepthf(1.0f);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glDepthFunc(GL10.GL_LEQUAL);
    //gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
    gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST);
}

public void onDrawFrame(GL10 gl) {
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();

但在 Android Emulator 中,边缘仍然严重锯齿.解决办法是什么?

But still the edges are severely jagged in Android Emulator. What is the solution?

推荐答案

最好的方法是使用多重采样(抗锯齿).由于您使用模拟器,这不是您的选择.(OpenGL ES 2.0 支持多重映射,但模拟器不支持 2.0)根据 OpenGL 规范,设备可以忽略你设置的 glHint,所以不要期望太多.GL_DITHER 是一种从 16 位颜色深度伪造"24 位颜色深度的方法,基本上它与边缘无关.

Well the best way is to use Multisampling ( Antialiasing ). Since you use the emulator this is not an option for you. ( Multismapling supported in OpenGL ES 2.0 but the emulator does not support 2.0 ) According to the OpenGL specification, the device can ignore the glHint you set, so don't expect to much from it. The GL_DITHER is a way to 'fake' 24bit color depth from 16bit color depth basically it has nothing to do with the edges.

虽然有一种伪造"抗锯齿的旧方法,但我从未使用过,所以我不能告诉你如何,但你可以在网上找到一些提示.

Altho there is an old method to 'fake' antialiasing, its a same that I never used so I cant tell you how, but you can find some hints on the web.

来自 OpenGL 文档

混合函数(GL_SRC_ALPHA、GL_ONE_MINUS_SRC_ALPHA)对于以任意顺序渲染抗锯齿点和线也很有用.

Blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) is also useful for rendering antialiased points and lines in arbitrary order.

使用混合函数 (GL_SRC_ALPHA_SATURATE, GL_ONE) 优化多边形抗锯齿,多边形从最近到最远排序.

Polygon antialiasing is optimized using blend function (GL_SRC_ALPHA_SATURATE, GL_ONE) with polygons sorted from nearest to farthest.

这篇关于如何摆脱 Android OpenGL ES 中的锯齿状边缘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆