使用 OpenGLES 的抗锯齿去除绳索的锯齿状边缘

removing jagged edges of my ropes using antialiasing of OpenGLES(使用 OpenGLES 的抗锯齿去除绳索的锯齿状边缘)

本文介绍了使用 OpenGLES 的抗锯齿去除绳索的锯齿状边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了绳索,其中我使用旋转关节连接动态 b2bodied,现在我成功地创建了这条绳索,但我的绳索看起来并不光滑,我希望它们像丝带一样光滑.任何对此有想法的人!我发现它可以通过openGLES使用抗锯齿来实现,但仍然不知道究竟如何实现这一点..任何形式的帮助都将不胜感激.

i have implemented ropes in which i have used Revolute joints to connect dynamic b2bodied , now i successfully created this ropes but my ropes not looking smoothy , i want them smooth just like ribbons . anyone having idea on this !! i found that it could be achieved by openGLES using anti-aliasing but still not getting idea that exactly how to achieve this .. any kind of help would be appreciated .

我的绳子是多边形的动态体,这样b2BodyDef 身体定义;bodyDef.type = b2_dynamicBody;bodyDef.position = currentPos;

my Rope is polygon shaped dynamic body , this way b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position = currentPos;

b2PolygonShape polygonShape;
polygonShape.SetAsBox(linkWidth,linkHeight);

b2FixtureDef fixtureDef;
fixtureDef.density =20.0;

fixtureDef.shape = &polygonShape;

b2Body* link = world->CreateBody( &bodyDef );
link->CreateFixture( &fixtureDef );

旋转关节:

b2RevoluteJointDef revoluteJointDef;
revoluteJointDef.localAnchorA.Set( 0,  linkHeight);
revoluteJointDef.localAnchorB.Set( 0, -linkHeight);            
revoluteJointDef.bodyA = link;
revoluteJointDef.bodyB = lastLink;
world->CreateJoint( &revoluteJointDef );

请帮忙.

我希望我的绳索更顺畅,就像最右边的图片一样

i want my ropes smoother just like right most image

我的输出看起来像这样

my output looks like this

推荐答案

如果你想去除纹理的边缘,你必须启用多重采样.多重采样将作用于整个屏幕,启用它会带来性能损失,在旧设备 (iPhone 3GS) 上最为严重.

You will have to enable multisampling if you want to get rid of the edges of textures. Multisampling will act on the entire screen and enabling it will have a performance penalty, most severely on older devices (iPhone 3GS).

在AppDelegate中找到CCGLView实例化的那一行,开启多重采样,设置采样数为2或4.

Locate the line where CCGLView is instantiated in AppDelegate, and enable multi sampling and set the number of samples to 2 or 4.

CCGLView *glView = [CCGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGBA8    // <-- use whichever is your default
depthFormat:GL_DEPTH_COMPONENT24_OES // <-- use whichever is your default
preserveBackbuffer:NO
sharegroup:nil
multiSampling:YES    // <-- enable
numberOfSamples:4];  // <-- set to 2 or 4

要记住的一件事:在 Retina 设备上,由于显示屏的高分辨率,您将无法看到锯齿状边缘.在 2D 应用程序中对 Retina 设备进行多重采样可能会浪费性能,并且几乎不会提高图像质量.这给您留下了另一种选择:考虑只支持 Retina 设备,或者干脆忽略非 Retina 设备上存在的问题,因为它们无论如何都会消失.

One thing to keep in mind: on Retina devices you won't be able to see the jagged edges due to the high resolution of the display. Multisampling on Retina devices in a 2D app is likely a waste of performance and hardly increases image quality. That leaves you with another option: consider to just support Retina devices, or simply ignore that the issue exists on non-Retina devices because they're about to go away anyway.

顺便说一句,CCTexture2D 锯齿和抗锯齿方法名称容易混淆,它们不执行全屏或纹理边缘锯齿或抗锯齿.它们在线性(antialias",模糊)和最近(alias",无过滤)之间更改纹理的过滤模式.

Btw, the CCTexture2D aliasing and antialiasing methods are confusingly named, they do not perform full-screen or texture-edge aliasing or antialiasing. They change the texture's filtering mode between linear ("antialias", blurry) and nearest ("alias", no filtering).

效果是纹理中的像素要么被线性过滤,因此单个像素的颜色逐渐变化,而最近过滤不执行此类过滤.像素艺术和瓦片地图瓦片集纹理最常需要最近过滤.两者都只改变纹理像素的过滤模式,而不是它们的边缘.为此,您需要多重采样.

The effect is that pixels within a texture are either linear filtered and thus individual pixel colors gradually change, whereas nearest filtering does not perform such filtering. Nearest filtering is most commonly needed for pixel art and tilemap tileset textures. Both only change filtering modes of the texture's pixels and not their edges. For that you need multisampling.

这篇关于使用 OpenGLES 的抗锯齿去除绳索的锯齿状边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用 OpenGLES 的抗锯齿去除绳索的锯齿状边缘

基础教程推荐