WrapMode (列挙)
public WrapMode
パッケージ: CURL.GRAPHICS.RENDERER3D
要素リスト:
wrap
clamp

範囲外のテクスチャ座標、つまり 0 より小さいか 1 より大きいテクスチャ座標を解釈するメソッドを示します。テクスチャ ラップ モードは、Texture 作成時に指定されます。

説明



次の例では、Pixmap に色づけされたチェッカーボードを生成し、その後 2 つの異なるラップ モードを使用して Pixmap をレンダリングする例をそれぞれ示します。ラップされた Texture の 2 つの例では、白い四角形がテクスチャの内部に描画されています。ここでは、テクスチャ座標が範囲内にあるため、ラップ モードが有効になっている場所が簡単にわかるようになっています。


例: WrapMode を使用したレンダリング
{import * from CURL.GRAPHICS.RENDERER3D}

{define-proc package {render-a-rectangle
                         drawable:Drawable, 
                         renderer:Renderer3d,
                         texture:Texture,
                         uv0:Fraction2d = {Fraction2d -1, -1},
                         uv1:Fraction2d = {Fraction2d 2, 2}
                     }:void

    || Clear the whole Drawable to black.
    {renderer.clear color = {Palette.get-black}}

    || Set our texture as the current one.
    set renderer.texture = texture

    let constant x1:Distance = 0.1in
    let constant y1:Distance = 0.1in
    let constant x2:Distance = drawable.width - 0.1in
    let constant y2:Distance = drawable.height - 0.1in

    || Render a rectangle using that texture.
    {render-primitive primitive, type="quads" on renderer do
        {primitive.texture-coord2 uv0.u, uv0.v}
        {primitive.vertex2 x1, y1}

        {primitive.texture-coord2 uv0.u, uv1.v}
        {primitive.vertex2 x1, y2}

        {primitive.texture-coord2 uv1.u, uv1.v}
        {primitive.vertex2 x2, y2}

        {primitive.texture-coord2 uv1.u, uv0.v}
        {primitive.vertex2 x2, y1}
    }

    || outline the inner rectangle
    let inner-x1:Distance = ((x2 - x1) / 3) + x1
    let inner-x2:Distance = ((x2 - x1)* (2 / 3)) + x1
    let inner-y1:Distance = ((y2 - y1) / 3) + y1
    let inner-y2:Distance = ((y2 - y1)* (2 / 3)) + y1
    set renderer.texture = {Palette.get-white}
    {render-primitive primitive, type="line-loop" on renderer do
        {primitive.vertex2 inner-x1, inner-y1}
        {primitive.vertex2 inner-x1, inner-y2}
        {primitive.vertex2 inner-x2, inner-y2}
        {primitive.vertex2 inner-x2, inner-y1}
    }
}


|| create the Pixmap
{let pixmap:Pixmap = {Pixmap 64, 64}}
{do
    || Fill the pixmap
    {for-pixel pixel at x, y in pixmap do
        {if {bit-and 8, x} != {bit-and 8, y} then
            || black square
            set pixel = {Pixel.from-float 0f, 0f, 0f}
         else
            || colored square -- create using a gradient color
            || (x determines red, y determines blue)
            set pixel = {Pixel.create x / 64, 0, y / 64}
        }
    }
}

{let texture-1:Texture =
    {Texture
        pixmap,
        wrap-s = WrapMode.wrap,
        wrap-t = WrapMode.wrap
    }
}

{let texture-2:Texture =
    {Texture
        pixmap,
        wrap-s = WrapMode.clamp,
        wrap-t = WrapMode.clamp
    }
}

{VBox
    {HBox
        valign = "center",
        {Frame width = 1in, height = 1in, background = pixmap},
        {Fill width = 0.25in},
        "The pixmap alone, without any out of range texturing."
    },
    {Fill height = 0.25in},
    {HBox
        valign = "center",
        {Renderer3dGraphic
            width = 3in,
            height = 3in,
            repaint-handler =
                {proc {rg:Renderer3dGraphic,
                       r:Renderer3d,
                       area:#RectangleSet
                      }:void
                    {render-a-rectangle {non-null rg.drawable}, r, texture-1}
                }
        },
        {Fill width = 0.5in},
        "A texture rendered from texture coordinates -1, -1 to 2, 2, " &
        "with wrap-s and wrap-t set to WrapMode.wrap"
    },
    {Fill height = 0.25in},
    {HBox
        valign = "center",
        {Renderer3dGraphic
            width = 3in,
            height = 3in,
            repaint-handler =
                {proc {rg:Renderer3dGraphic,
                       r:Renderer3d,
                       area:#RectangleSet
                      }:void
                    {render-a-rectangle {non-null rg.drawable}, r, texture-2}
                }
        },
        {Fill width = 0.5in},
        "A texture rendered from texture coordinates -1, -1 to 2, 2, " &
        "with wrap-s and wrap-t set to WrapMode.clamp"
    }
}