0

I have not done much maths in my high school but after much research I understand that to draw a polygon we need to define an array of float as its vertices. However I don't understand how to get the polygon to fit the texture.

I did a lot of research but couldn't find answer or simple demonstration as to how as to how do people map their texture so that the polygon fits right. All I can see is direct demonstration of array of float but not how they got each point.

As for now I am using about 8 rectangles to fill my texture for collision detection which is not very efficient.

halfer
  • 19,824
  • 17
  • 99
  • 186
Deeyo
  • 27
  • 3
  • 9
  • You may want to check out this related question: http://stackoverflow.com/questions/5532595/how-do-opengl-texture-coordinates-work. – Reto Koradi Oct 01 '14 at 17:07

1 Answers1

0

This is a comment from some code I wrote a long time ago for binding a texture to a rectangle using lwjgl (which uses Java OpenGL)

/* For each corner of the quad we define the coordinates of both the texture
             * and the vertex. 
             * 
             * -    The vertex coordinates are the coordinates on the screen that
             *      they are drawn to. 
             * -    The texture coordinates tell which portion of the texture is used.
             * 
             * Texture coordinates are represented in the textureBounds array as follows:
             * [<leftmost x>, <bottommost y>, <rightmost x>, <topmost y>]
             * 
             * -    Texture coordinates [0.0, 0.0, 1.0, 1.0] mean the whole texture is drawn.
             * 
             * -    [0.0f, 0.0f, 0.5f, 1.0f] means that only the left half of texture is drawn. 
             * 
             * -    [0.0f, 0.5f, 2.0f, 1.0f] means that the top half (y is from 0.5 to 1.0)
             *      of the texture is drawn side-by-side twice (x is from 0.0 to 2.0)
             * 
             * */
Atuos
  • 501
  • 3
  • 12