CCDrawNode Antialiasing problem


I’m using CCDrawNode in my project, but there are some difference between cocos2d and cocos2d-x.

Attached file shows that just draw circle using following code.

CCDrawNode* dNode = CCDrawNode::create();
dNode->drawDot(ccp(1024/2, 768/2), 100, ccc4f(1.0, 0, 0, 1.0));

In cocos2d(Right Circle in attached file), it is very clear and antialiased circle but in cocos2d-x(Left Circle in attached file), it seems that Antialiasing parameter is not reflected in the circle.
They were also captured in IOS Simulator and also use cocos2d 2.1 version.
Is there any way to fix this problem?

circle.png (42.3 KB)

Cocos2d-x v3 Anti-Aliasing for Primitives
How to draw anti-aliased line in cocos2d-x for android games?

i got the same issue :frowning:


I got the same issue too. I used CCDrawNode::drawPolygon method to draw a polygon, the edge effects are bad.
Any solutions?

Final topic about Anti-Aliasing disease

Help me. I have the same problem!!! My polygon can’t go antialiased :frowning:


I found a kind of solution- use CCRenderTexture and convert your poly to CCSprite- it is antialiased by default.


I have the same problem.

I’ve tried to restore the commented code in ccShader_PositionColorLengthTexture_frag.h, but there’s no effect.

There’s some way to draw antialiased primitives with DrawNode without using a RenderTexture?


In fact, I’m not able to draw an antialiased image of the layer using a RenderTexture either.
The image quality using a RenderTexture is low, and I don’t get a quality antialiasing if I scale down the node.

I have attached some images to show the problem.

void HelloWorld::update(float delta)
    Size visibleSize = Director::getInstance()->getVisibleSize();
    mRenderTexture = RenderTexture::create(visibleSize.width, visibleSize.height, Texture2D::PixelFormat::RGBA8888);
    auto finalTexture = mRenderTexture->getSprite()->getTexture();
    Rect rect = Rect::ZERO;
    rect.size = finalTexture->getContentSize();


I found it!:slight_smile:

In order to draw antialiased primitives, you have to force smoothstep:

"																															\n\
#ifdef GL_ES																												\n\
// #extension GL_OES_standard_derivatives : enable																			\n\
varying mediump vec4 v_color;																								\n\
varying mediump vec2 v_texcoord;																							\n\
#else																														\n\
varying vec4 v_color;																										\n\
varying vec2 v_texcoord;																									\n\
#endif																														\n\
void main()																													\n\
{																															\n\
// #if defined GL_OES_standard_derivatives																						\n\
	// gl_FragColor = v_color*smoothstep(0.0, length(fwidth(v_texcoord)), 1.0 - length(v_texcoord));							\n\
// #else																														\n\
	// gl_FragColor = v_color*step(0.0, 1.0 - length(v_texcoord));																\n\
// #endif																														\n\
    gl_FragColor = v_color*smoothstep(0.0, length(fwidth(v_texcoord)), 1.0 - length(v_texcoord));																\n\
}																															\n\

Final topic about Anti-Aliasing disease

I tried the code on iOS device and I got this error :
cocos2d: cocos2d: ERROR: 0:29: Call to undeclared function 'fwidth'


It seems on iOS you have to enable GL_OES_standard_derivatives.
I don’t have an iOS device to test it, but probably if you uncomment all the commented code in the shader fwidth will work:


This helped me in iOS, but the anti-alias issues persists on Mac desktop (Mavericks). Any further ideas?


Correction, it worked in the simulator, not in an ipad mini retina, for instance. =/


Weird, I tested it some time ago on a Mac Mini with Mountain Lion and it worked without problems.


@Chano I overlooked your actual code, i.e., the gl_FragColor definition is outside the conditional blocks. I see it working now, thanks! Will have to test it in Android now.



I think I jumped the gun again, this worked in the Mac build, and never in the iOS device. Still sifting through options.


I have it working on Windows and some Android devices like the Nexus 4 (in other Android devices the app is aborted because this:

As I said, I tested it on a Mac Mini too. But I haven’t tested it on an iOS device because I don’t have one :stuck_out_tongue:


I will check it on Android, just for kicks now.


It works on iOS, OSX, win32 and Android. Am using v2.2.2.


@IslandPlaya it didn’t work for me in iOS 7.1.1. Works in the simulator, not in the actual device. I’ve tried an iPhone 5s and iPad Mini Retina.

@Chano Android worked too.


Thanks for the info hcabral.
I don’t have a 7.1.1 device to test on, but I will be sure to look into this before my game is released.
Many thanks.