Filling a polygon with a repeating texture

Hi guys,

I’m playing with openGL for the first time on the Android platform.

I’m wanting to draw a polygon filled with a repeating texture. (It will represent 2d landscape i.e. http://www.blogcdn.com/www.joystiq.com/media/2009/08/gentlemenplatformer580.jpg)

The reason I’m using a polygon is I’m using the same shape to create a box2d physics object…

So my question is, how do I fill a polygon with a repeating texture?

Also can anybody recommend a good book on openGL?

Many thanks!

In order to have a repeating texture over an arbitrary surface you need only two things:

  • set texture wrap mode to GL_REPEAT
  • set texture coordinates appropriately (so use values outside the [0,1] interval) or alternatively use the texture matrix (or equivalent shader) to scale the texture coordinates

Can you recommend any articles/books which would help me understand what you just said!! Cheers :slight_smile:

http://www.opengles-book.com

I’m not sure what it really worth, I don’t have it, I sound quite a beginner book, but the OpenGL samples are available for the Android platform which could be great for you.

library.nu, register, then search a little for OpenGL.