Skip to content Skip to sidebar Skip to footer

How To Load A Texture Onto A Circle With Opengl Es

I am facing problems on loading a texture onto a circle. My circle is made with a triangle fan. It gives a bad output. Original Image: The Result : My code: public class MyO

Solution 1:

For starters, you need to have the same number of texcoord pairs in your texcoord array as you have vertex tuples in your vertex array.

It looks like you've just got 3 pairs of texture coordinates, and 360 vertices.

You need to have a texcoord array that has 360 texture coordinates in it. Then when the vertices are drawn, vertex[0] gets texcoord[0], vertex[1] gets paired with texcoord[1], etc.

===EDIT===

You just have to define the texture coordinates in a similar manner to how you define your vertices: in a loop using mathematical formulas.

So for example, your first vertex of the triangle fan is at the center of the circle. For the center of your circle, you want the texcoord to reference the center of the texture, which is coordinate (0.5, 0.5).

As you go around the edges, just think about which texture coordinate maps to that part of the circle. So lets assume that your next vertex is the rightmost vertex of the circle, that lies along the same y value as the center of the circle. The texcoord for this one would be (1.0, 0.5), or the right edge of the texture in the vertical middle.

The top vertex of the circle would have texcoord (0.5, 1.0), the leftmost vertex would be (0.0, 0.5), etc.

You can use your trigonometry to fill in the rest of the vertices.

Post a Comment for "How To Load A Texture Onto A Circle With Opengl Es"