love2d吧 关注:553贴子:1,166
  • 5回复贴,共1

求助,图像缩放问题

只看楼主收藏回复


使用love.graphics.draw(img, x, y, 0, .1, .1)绘制的图像会出现锯齿,怎么样才能够避免这种现象,如图,上面是直接绘制的结果,下面是使用软件修改后的图像,上面的图像出现了了锯齿


IP属地:广东1楼2021-08-13 22:16回复
    自己写了一个shader,问题解决了
    extern float scale_w;
    extern float scale_h;
    extern int img_w;
    extern int img_h;
    #ifdef VERTEX
    vec4 position( mat4 transform_projection, vec4 vertex_position ) {
    return transform_projection*vertex_position;
    }
    #endif
    #ifdef PIXEL
    vec4 effect( vec4 color, Image tex, vec2 texture_coords, vec2 screen_coords ) {
    int count_w = int (1.0 / scale_w + 0.5);
    int count_h = int (1.0 / scale_h + 0.5);
    int count = 1;
    vec4 color_sum = vec4(0, 0, 0, 0);
    vec2 pos_per;
    vec4 color_per;
    for (int i = 1; i <= count_w; i++) {
    for (int k = 1; k <= count_h; k++) {
    pos_per = vec2((texture_coords.x * img_w + i-(count_w / 2)) / img_w, (texture_coords.y * img_h + k - (count_h / 2)) / img_h);
    color_per = Texel(tex, pos_per);
    if (color_per.a != 0) {
    color_sum += color_per;
    count++;
    }
    }
    }
    vec4 color_avg = color_sum / count;
    if (count_w != 20) {
    return vec4(2,2,2,2);
    }else{
    return color_avg;
    }
    }
    #endif


    IP属地:广东2楼2021-08-15 17:07
    回复
      2025-05-25 12:35:09
      广告
      不过,怎么样才能不使用extern,获得图像的尺寸信息呢


      IP属地:广东3楼2021-08-15 17:08
      回复
        两点兄还有继续使用love2d开发吗?有没有出成品?
        我看你从19年到22年都有在用love2d做开发,很厉害啊!


        IP属地:福建4楼2024-04-17 01:02
        收起回复