Question

After some help, i want to texture onto a circle as you can see below. I want to do it in such a way that the centre of the circle starts on the shared point of the triangles.

the triangles can change in size and number and will range over varying degrees ie 45, 68, 250 so only the part of the texture visible in the triangle can be seen.

its basically a one to one mapping shift the image to the left and you see only the part where there are triangles.

not sure what this is called or what to google for, can any one makes some suggestions or point me to relevant information.

i was thinking i would have to generate the texture coordinates on the fly to select the relevant part, but it feels like i should be able to do a one to one mapping which would be simpler than calculating triangles on the texture to map to the opengl triangles.

example

Was it helpful?

Solution

Generating texture coordinates for this isn't difficult. Each point of polygon corresponds to certain angle, so i'th point angle will be i*2*pi/N, where N is the order of regular polygon (number of sides). Then you can use the following to evaluate each point texture coordinates:

texX = (cos(i*2*pi/N)+1)/2
texY = (sin(i*2*pi/N)+1)/2

Well, and the center point has (0.5, 0.5). It may be even simpler to generate coordinates in the shader, if you have one specially for this: I assume, you get pos vertex position. It depends on how you store the polygon vertexes, but let the center be (0,0) and other points ranging from (-1;-1) to (1;1). Then the pos should be simply used as texture coordinates with offset:

vec2 texCoords = (pos + vec2(1,1))*0.5;

and the pos itself then should be passed to vector-matrix multiplication as usual.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top