使用抗锯齿的OpenGLES消除我的绳索锯齿状边缘 [英] removing jagged edges of my ropes using antialiasing of OpenGLES

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

问题描述

我已经实施绳索,其中我使用Revolute关节连接动态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 .

my Rope是多边形动态体,这样
b2BodyDef bodyDef;
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).

找到CCGLView在AppDelegate中实例化的行,并启用多取样并将样本数设置为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设备上,因为他们即将离开。

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.

Btw,CCTexture2D混叠和抗锯齿方法被混淆命名,它们不执行全屏或纹理边缘混叠或抗锯齿。他们改变纹理的线性(antialias,模糊)和最近(别名,没有过滤)之间的过滤模式。

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).

效果是纹理内的像素被线性过滤,因此各个像素颜色逐渐变化,而最近的过滤不执行此类过滤。对像素艺术和tilemap tileset纹理最通常需要最近的滤波。两者只改变纹理的像素的滤波模式,而不是它们的边缘。因此,您需要多重采样。

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消除我的绳索锯齿状边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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