opengl, Black lines in-between tiles

前端 未结 3 2033
粉色の甜心
粉色の甜心 2021-01-02 03:40

When its translated in an integral value (1,2,3, etc....), there are no black lines in-between the tiles, it looks fine. But when it\'s translated to a non-integral (1.1, 1.

3条回答
  •  臣服心动
    2021-01-02 04:16

    Another problem if you have transparent pixel in your texture:

    When OpenGL use linear filter to scale your texture, it blend some pixels with transparent pixel, but in most of the cases, the transparent pixel color is white so the result blended pixel haven't the expected color. To fix this, a solution is to create pre-multiplied alpha. I've created a script for achieve this on Gimp:

    (define (precompute-alpha img color)
    
      (define w (car (gimp-image-width img)))
      (define h (car (gimp-image-height img)))
    
      (define img-layer (car (gimp-image-get-active-layer img)))
    
      (define img-mask (car (gimp-layer-create-mask img-layer ADD-ALPHA-TRANSFER-MASK)))
      (gimp-layer-add-mask img-layer img-mask)
      (define alpha-layer (car (gimp-layer-new img w h RGBA-IMAGE "alpha" 100 NORMAL-MODE)))
      (gimp-image-insert-layer img alpha-layer 0 -1)
      (gimp-edit-copy img-mask)
      (define floating-sel (car (gimp-edit-paste alpha-layer TRUE)))
      (gimp-floating-sel-anchor floating-sel)
    
      (define bg-layer (car (gimp-layer-new img w h RGBA-IMAGE "bg" 100 NORMAL-MODE)))
      (gimp-image-insert-layer img bg-layer 0 2)
      (gimp-context-set-background color)
      (gimp-drawable-fill bg-layer BACKGROUND-FILL)
    
      (set! bg-layer (car (gimp-image-merge-down img img-layer 0)))
      (define bg-mask (car (gimp-layer-create-mask bg-layer ADD-WHITE-MASK)))
      (gimp-layer-add-mask bg-layer bg-mask)
    
      (gimp-edit-copy alpha-layer)
      (set! floating-sel (car (gimp-edit-paste bg-mask TRUE)))
      (gimp-floating-sel-anchor floating-sel)
    
      (gimp-image-remove-layer img alpha-layer)
    )
    
    (script-fu-register "precompute-alpha"
        "Precompute Alpha"
        "Automatically precompute alpha"
        "Thomas Arbona"
        "2017"
        "2017"
        "*"
        SF-IMAGE    "Image"         0
        SF-COLOR    "Alpha Color"   '(0, 0, 0)
    )
    
    (script-fu-menu-register "precompute-alpha" "/Alpha")
    

    Just open your image in Gimp, open Alpha > Precompute Alpha and pick a color to pre-compute the alpha on your image with this color.

提交回复
热议问题