c – SDL2 AntiAliasing

c – SDL2 AntiAliasing,第1张

概述使用SDL_RenderCopyEx时,如何在SDL2中打开抗锯齿功能? 我发现一些建议使用的文章: SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2); 和 glEnable(GL_MULTISAMPLE); 但这没有任何效果.有任何想法吗? in 使用SDL_RendercopyEx时,如何在SDL2中打开抗锯齿功能?

我发现一些建议使用的文章:

SDL_GL_SetAttribute(SDL_GL_MulTISAMPLEBUFFERS,1);SDL_GL_SetAttribute(SDL_GL_MulTISAMPLESAMPLES,2);

glEnable(GL_MulTISAMPLE);

但这没有任何效果.有任何想法吗?

int Buffers,Samples;SDL_GL_GetAttribute( SDL_GL_MulTISAMPLEBUFFERS,&Buffers );SDL_GL_GetAttribute( SDL_GL_MulTISAMPLESAMPLES,&Samples );cout << "buf = " << Buffers << ",samples = " << Samples;

回报

buf = -858993460,samples = -858993460.

编辑:代码:

#include <windows.h>#include <iostream>#include <SDL2/include/SDL.h>#include <SDL2/include/SDL_image.h>using namespace std;int main( int argc,char * args[] ){    // Inicjacja SDL'a    SDL_Init(SDL_INIT_EVERYTHING);    SDL_GL_SetAttribute(SDL_GL_MulTISAMPLEBUFFERS,1);    SDL_GL_SetAttribute(SDL_GL_MulTISAMPLESAMPLES,8);    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,1);     // TworZenIE okna    SDL_Window *win = nullptr;    win = SDL_CreateWindow("abc",100,800,600,SDL_WINDOW_FulLSCREEN | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);    if (win == nullptr)     {        std::cout << SDL_GetError() << std::endl;        system("pause");        return 1;    }    int Buffers,Samples;    SDL_GL_GetAttribute( SDL_GL_MulTISAMPLEBUFFERS,&Buffers );    SDL_GL_GetAttribute( SDL_GL_MulTISAMPLESAMPLES,&Samples );    cout << "buf = " << Buffers << ",samples = " << Samples << ".";    // Create Renderer    SDL_Renderer *ren = nullptr;    ren = SDL_CreateRenderer(win,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);    if (ren == nullptr)    {        std::cout << SDL_GetError() << std::endl;        return 1;    }    // Create texture    SDL_Texture *tex = nullptr;    tex = img_LoadTexture(ren,"circle.png");    SDL_SetTextureAlphaMod(tex,100);    SDL_Rect s,d;    SDL_Point c;    s.x = s.y = 0;    s.w = s.h = 110;    d.x = 320;    d.y = 240;    d.w = d.h = 110;    c.x = c.y = 55;    // Event Queue    SDL_Event e;    bool quit = false;    int angle = 0;    while(!quit)    {        while (SDL_PollEvent(&e)){            //If user closes he window            if (e.type == SDL_KEYDOWN)                quit = true;        }        angle += 2;        float a = (angle/255.0)/M_PI*180.0;        // Render        SDL_RenderClear(ren);        SDL_RendercopyEx(ren,tex,&s,&d,a,&c,SDL_FliP_NONE);        SDL_RenderPresent(ren);    }    // Release    SDL_DestroyTexture(tex);    SDL_DestroyRenderer(ren);    SDL_DestroyWindow(win);    // Quit    SDL_Quit();    return 0;}

不要担心与内存释放等相关的样式或错误.这是一个快速草图来测试SDL’a的可能性

解决方法 如果您正在寻找不需要使用opengl的答案,那么这可能是有用的:

SDL_SetHint( SDL_HINT_RENDER_SCALE_QUAliTY,"1" );

https://wiki.libsdl.org/SDL_HINT_RENDER_SCALE_QUALITY

总结

以上是内存溢出为你收集整理的c – SDL2 AntiAliasing全部内容,希望文章能够帮你解决c – SDL2 AntiAliasing所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1215539.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存