SDL2 OpengGL抗锯齿无效

德米特里

我想用SDL2绘制平滑的填充椭圆。我有以下代码

#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL2_gfxPrimitives.h>
#include <GL/gl.h>

void init()
{
   SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
   SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);
   glEnable(GL_MULTISAMPLE);
}

int main()
{
   SDL_Init(SDL_INIT_EVERYTHING);
   init();

SDL_Window* window = SDL_CreateWindow("Anti-aliasing test",
                                      SDL_WINDOWPOS_CENTERED,
                                      SDL_WINDOWPOS_CENTERED,
                                      100, 100,
                                      SDL_WINDOW_RESIZABLE);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);

int Buffers, Samples;
SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &Buffers );
SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &Samples );
std::cout << "buf = " << Buffers << ", samples = " << Samples;
std::cout.flush();


SDL_Event e;
int x, y;
while(true)
{
    SDL_WaitEvent(&e);
    if (e.type == SDL_QUIT)
        break;

    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
    SDL_RenderClear(renderer);
    SDL_GetWindowSize(window, &x, &y);
    filledEllipseRGBA(renderer, x / 2, y / 2, 50, 50,  255, 0, 0, 255);
    SDL_RenderPresent(renderer);
}
}

我原本希望使用抗锯齿功能进行绘制,但是实际上我对OpenGL没有任何影响。

我们可以看到我的圈子没有使用AA所必需的Alpha通道。但是控制台输出是“ buffer = 0,samples = 4”。

关于如何在SDL2(带或不带OpenGL)中激活(修复)AA的任何想法。

下一个屏幕截图演示了我所拥有的和我想要的。底部图片是在Pinta软件中绘制的。

在此处输入图片说明

米尼姆

您正在尝试使用OpenGL窗口提示进行抗锯齿,但这仅在创建带有OpenGL上下文的窗口时才起作用,这将禁用所有SDL渲染。

SDL2/SDL2_gfxPrimitives.h您用来绘制填充椭圆库具有多个抗锯齿功能,但没有填充椭圆的解决方法,一种解决方法是每次绘制抗锯齿椭圆时都在内部绘制填充椭圆的未填充抗锯齿椭圆。

void aafilledEllipseRGBA(...) {
    aaellipseRGBA(...);
    filledEllipseRGBA(...);
}

或编写自己的抗锯齿填充椭圆渲染代码。您可以通过在此处查看其开源代码库的代码来使用它

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章