Antialiased rendering to Framebuffer object

Hi there!

I’m trying to incorporate a post processing shader in my first project. So I set up a FrameBuffer, drawing onto it, and then drawing a texture from it onto screen.

But when I render directly on screen, I get this:

https://thumb.ibb.co/h4i1Jb/cool.jpg

When I render using FrameBuffer, I get this:

https://thumb.ibb.co/gdgz4G/shit.jpg

Notice how different edges of bricks look. As far as I understand, in the second case there is no texture filtering? Or what is causing this is more tricky?

I’m using LibGdx.

Textures are loaded like this:


brickTexture = new Texture(Gdx.files.internal(BRICK));

FrameBuffer setup:


        frameBuffer = FrameBuffer.createFrameBuffer(
                Pixmap.Format.RGBA8888,
                Gdx.graphics.getWidth(),
                Gdx.graphics.getHeight(),
                false);

And my render() method:


    @Override
    public void render(float delta) {
        camera.update();

        if (paused) {
            menu.act(delta);
        } else {
            game.act(delta);
        }

        frameBuffer.begin();

        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        if (paused) {
            menu.draw();
        } else {
            batch.begin();
            game.draw(batch);
            batch.end();
        }

        frameBuffer.end();
        
        viewport.apply();

        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        batch.begin();
        batch.draw(frameBuffer.getColorBufferTexture(), 0, WORLD_HEIGHT, WORLD_WIDTH, -WORLD_HEIGHT);
        batch.end();
    }

Okay, maybe my question is incorrect…

Ho do i render to FBO with multisampling?

Ok, guys, according to the link below AND official documentation for OpenGL 4.6, antialiasing is disabled by default for Framebuffer objects (i.e. created by user).
http://www.java-gaming.org/topics/libgdx-draw-with-anti-aliasing-to-a-non-default-framebuffer/36141/view.html

But is it possible to enable it via standard libGDX api? Or do I really need to somehow enable it manually for a FBO I created? I just can’t get it because when I create libGDX FBO, it is created without multisampling, right? So I can’t modify parameters of an already created FBO… And does this in turn mean that I should create an FBO manually, using Gdx.gl API calls? If yes, then it seems that I can’t, because both GL20 and GL30 classes does not contain functions mentioned in the example here: https://www.khronos.org/opengl/wiki/Multisampling

So how do I do this “simple” thing?

Have you had a look at their GitHub issues page?
MSAA for FBOs is an open feature request.
It looks like, since libGDX’s GL abstraction/interface does not yet expose OpenGL 3.2, your only option is to go directly down to LWJGL’s classes and static methods, such as org.lwjgl.opengl.GL32. Doing this will of course bind you to Desktop-only, and will not work on Android or the Web.

To add a bit, MSAA is not something that you just “enable” on a framebuffer. MSAA requires storing multiple samples for each pixel, meaning it needs more memory. A framebuffer object does not contain any actual data; it just renders to textures. If you attach an MSAA texture to the FBO, rendering to it will happen with MSAA. To actually display an MSAA image, you need to resolve it, which usually means averaging the samples of each pixel together. All of this happens automatically when you request an MSAA default framebuffer but needs to be manually taken care of when using FBOs.

KaiHH, yes, after my last post I found that information. I also had read it before, but something just didn’t switch in my had. I also had found out that GL32 class of lwjgl contains required constants. But then goes next question.
If GL ES is a subset of GL, then I can use functions from GL if I know which ones exactly are supported by specific version of GL ES running on my current device (most likely mobile). Right? E.g.: my game knows that current backend is GL ES 3.1, so it can use some specific functions from GL32 which definitely are included in GL ES 3.1. Is this assumption correct?

theagentd, so MSAA depends on the texture bound to FBO, not FBO itself, nor textures (sprites) being rendered to the texture?

No.
Like I said, when you use LWJGL, your application will ONLY work on Desktop.
This is the reason why libGDX has its own GL interface/API to be able to route the GL calls to different underlying implementations (LWJGL on Desktop, WebGL on Web, Android GL ES on Android).
Again, once you use LWJGL classes/methods directly, libGDX has no way of routing the GL calls to Android GL ES anymore and your application WILL NOT work on the Web or Android anymore. There is no way around this without hacking libGDX itself.

Oh, sorry for not understanding it for the first time.

And there is no library like lwjgl for GL ES? I mean, if lwjgl is used for Desktop, so then which library is used for Android?