我想用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软件中绘制的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句