Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ SDL2 OpengGL抗锯齿无效_C++_Opengl_Sdl 2 - Fatal编程技术网

C++ SDL2 OpengGL抗锯齿无效

C++ SDL2 OpengGL抗锯齿无效,c++,opengl,sdl-2,C++,Opengl,Sdl 2,我想用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_MULTI

我想用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);
}
}
#包括
#包括
#包括
#包括
void init()
{
SDL_GL_SetAttribute(SDL_GL_多采样缓冲区,1);
SDL_GL_SetAttribute(SDL_GL_多样本样本,2);
glEnable(GL_多样本);
}
int main()
{
SDL_Init(SDL_Init_EVERYTHING);
init();
SDL_Window*Window=SDL_CreateWindow(“抗锯齿测试”,
SDL_窗口位置居中,
SDL_窗口位置居中,
100, 100,
SDL_窗口(可调整大小);
SDL_渲染器*渲染器=SDL_CreateRenderer(窗口,-1,SDL_渲染器加速);
int缓冲区、样本;
SDL_GL_GetAttribute(SDL_GL_多采样缓冲区和缓冲区);
SDL_GL_GetAttribute(SDL_GL_多样本样本和样本);

std::cout您正在尝试使用OpenGL窗口提示进行抗锯齿,但这仅在您创建具有OpenGL上下文的窗口时有效,这将禁用所有SDL渲染

用于绘制填充椭圆的
SDL2/SDL2\u gf xprimitives.h
库具有多个抗锯齿功能,但对于填充的eclipse,解决方法可能是每次绘制抗锯齿椭圆时都在内部绘制填充eclipse的非填充抗锯齿椭圆

void aafilledEllipseRGBA(...) {
    aaellipseRGBA(...);
    filledEllipseRGBA(...);
}
或者编写您自己的抗锯齿填充椭圆渲染代码。您可以根据您正在使用的开源库的代码查看它们的代码。

我找到了一些“解决方案”.在调用filledEllipseRGBA之前添加具有相同参数的aaellipseRGBA使circle变得非常漂亮。但我认为这不是一个好方法。如果采样缓冲区的数量为0,则这是您应该期望的行为。这至少需要为1才能进行多重采样。