Labels and Anti-Aliasing in 3.2

Hi everyone,

To avoid anti-aliasing in a pixel based game I used to do this in Cocos2D-x 2.2:

CCLabelBMFont *bmLabel = CCLabelBMFont::create(ss.str().c_str(), “myBMFont.fnt”, 128, kCCTextAlignmentLeft);

bmLabel->getTexture()->setAliasTexParameters();

same on CCLabelTTF: ttfLabel->getTexture->setAliasTextureParameters();

Is there any way of achieving the same in cocos2d-x 3.2 ?

Thanks!

I believe it’s basically the same.

auto lbl = Label::createWithBMFont(...);
lbl->getTexture()->setAliasTexParameters();

However, if you want everything in your game to be aliased (pixellated) then you may also be interested in setting it globally by changing the constructor property default of the engine’s CCFontAtlas.cpp and CCTexture2D.cpp from , _antialiasEnabled(true) to , _antialiasEnabled(false)

Odd, why would they remove it from the deprecated CCLabelTTF and CCLabelBMFont classes and then support the same calls on the new Label class? Didn’t even come to my mind to test this :smiley:

Thanks for the solution and thanks also for the great tip on how to globally disable anti-aliasing!

You can force Alias Rendering by setting the MSAA Lvl to 0.

@Packora have never thought about messing with the MSAA, is there any performance gain to set MSAA to 0 over having all textures set to render aliased?

Yeah, for sure, specialy on old devices, on modern devices you won’t notice any deference in performance but you will get an aliased render :

bool GLView::initWithRect(const std::string& viewName, Rect rect, float frameZoomFactor)
{
    setViewName(viewName);

    _frameZoomFactor = frameZoomFactor;

    glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
    glfwWindowHint(GLFW_SAMPLES, 0);// Add this COOL line!
    ......