justgook / webgl-shape / WebGL.Shape2d.TexturedShape

Shapes with textures

Same as ShapeSolid but also can render shapes that needs textures

toEntities : { a | width : WebGL.Shape2d.Render.Width, height : WebGL.Shape2d.Render.Height } -> TextureLoader key -> List (TexturedShape key) -> ( List WebGL.Entity, TextureLoader key )

Converts List Shape to WebGL entities

import WebGL
import WebGL.Game2d.TexturedShape exposing (toEntities)

rectangle =
    ...

textures =
    ...

screen =
    { width = 100, height = 100 }

main =
    toEntities screen textures [ rectangle red 30 30 ]
        |> Webgl.toHtml [ width 100, height 100 ]

shape : WebGL.Shape2d.Render.Width -> WebGL.Shape2d.Render.Height -> WebGL.Shape2d.Render.Render -> TexturedShape texture

Create TexturedShape from Render

rectangle : Color -> Width -> Height -> TexturedShape
rectangle color w h =
    Render.rect color |> TexturedShape.shape w h

group : List (TexturedShape key) -> TexturedShape key

Put shapes together so you can move and rotate them as a group. Maybe you want to put a bunch of stars in the sky:

shapes =
    [ star
        |> move 100 100
        |> rotate 5
    , star
        |> move -120 40
        |> rotate 20
    , star
        |> move 80 -150
        |> rotate 32
    , star
        |> move -90 -30
        |> rotate -16
    ]

star =
    group
        [ triangle yellow 20
        , triangle yellow 20
            |> rotate 180
        ]

textured : (WebGL.Texture.Texture -> TexturedShape texture) -> texture -> TexturedShape texture

Create TexturedShape that depend on texture.

textured2 : (WebGL.Texture.Texture -> WebGL.Texture.Texture -> TexturedShape key) -> key -> key -> TexturedShape key

textured3 : (WebGL.Texture.Texture -> WebGL.Texture.Texture -> WebGL.Texture.Texture -> TexturedShape key) -> key -> key -> key -> TexturedShape key

textured4 : (WebGL.Texture.Texture -> WebGL.Texture.Texture -> WebGL.Texture.Texture -> WebGL.Texture.Texture -> TexturedShape key) -> key -> key -> key -> key -> TexturedShape key

textured5 : (WebGL.Texture.Texture -> WebGL.Texture.Texture -> WebGL.Texture.Texture -> WebGL.Texture.Texture -> WebGL.Texture.Texture -> TexturedShape key) -> key -> key -> key -> key -> key -> TexturedShape key


type alias TexturedShape key =
WebGL.Shape2d.Shape.Shape (Form key)


type Form key
    = Form (WebGL.Shape2d.Shape.ShapeData WebGL.Shape2d.Render.Render)
    | Group (WebGL.Shape2d.Shape.GroupData (WebGL.Shape2d.Shape.Shape (Form key)))
    | Textured (WebGL.Shape2d.Shape.TexturedData key (TexturedShape key))

Textures


type TextureLoader key
    = TextureLoader ({ get : key -> Maybe WebGL.Texture.Texture, missing : key -> TextureLoader key, extract : () -> ( TextureLoader key, List key ), insert : key -> WebGL.Texture.Texture -> TextureLoader key })