2
\$\begingroup\$

I need to map texture to shape. Texture:

Example texture in diamond shape

This is a example of shapes I need to map texture to:

Mesh example

Notice that each piece in mesh has exactly 4 point to map texture. Logic is pretty straight forward: Top center edge to top in mesh etc.

I found some methods on Graphics object like texture(...) however these methods cannot handle diamond texture properly..?

I found this method:

ShapeRenderer.texture(shape, image, generator)

Where generator is:

org.newdawn.slick.geom.TexCoordGenerator

However I don't understand How It can be used to map the image to the shape.

How to use it? Is there other way?

\$\endgroup\$
1
  • \$\begingroup\$ If you're not dead set on using Slick, take a look at libGDX; its status is active as opposed to Slick. \$\endgroup\$
    – driima
    Jul 10 '15 at 20:05
2
\$\begingroup\$

I didn't found an API for this in Slick library. So I wrote a class which does it for me (groovy code):

class Stretched {

    Shape shape
    Image image

    Stretched(Shape shape, Image image) {
        this.shape = shape
        this.image = image
    }

    void render() {

        TextureImpl.bindNone()
        image.getTexture().bind()
        SGL GL = Renderer.get()

        GL.glEnable(SGL.GL_TEXTURE_2D)
        GL.glBegin(SGL.GL_QUADS)

        GL.glTexCoord2f(0.5f, 0f)
        GL.glVertex2f(shape.points[0], shape.points[1])

        GL.glTexCoord2f(1f, 0.5f)
        GL.glVertex2f(shape.points[2], shape.points[3])

        GL.glTexCoord2f(0.5f, 1f)
        GL.glVertex2f(shape.points[4], shape.points[5])

        GL.glTexCoord2f(0f, 0.5f)
        GL.glVertex2f(shape.points[6], shape.points[7])

        GL.glEnd()
        GL.glDisable(SGL.GL_TEXTURE_2D)
    }
}

This takes a Shape (polygon w/ 4 vertexes) and map diamond texture to it.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.