We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › calculating texture coords for multiple vertices
Page Index Toggle Pages: 1
calculating texture coords for multiple vertices (Read 520 times)
calculating texture coords for multiple vertices
Sep 15th, 2009, 7:07am
 
Hej,

I have a problem calculating texture coordinates.

Here is what I want to do:

farm3.static.flickr.com/2669/3923137706_a3e91e513b.jpg

(Sorry, I am not allowed to include the image directly.)

I have a texture to the left and a (2d) shape with multiple vertices to the right. The shape should function like a mask for the texture.

I try to draw the shape with the correct texture coordinates but it seems that I am too stupid to get the calculations right.

If the texture would be rectangular as shown in the image it would be easy ... something like this I suppose:

Code:
for (int i = 0; i < 5; i++) {
       vertex(p[i].x, p[i].y,(p[i].x-k[0].x)/(k[1].x-k[0].x),(p[i].y-k[1].y)/(k[2].y-k[1].y));
 }

Where 5 is the amount of vertices and p[] are the vertices of the (mask)shape and k[] are the imaginary coordinates of the texture around the shape. I tried it and it seems to work.

But when it comes to a not rectangular shape I am helpless.

I would really appreciate some hints (or code ... or formulas).

Thanks!

P.S.: In case you are wondering: I want to render some animation offscreen and then draw shapes for projection mapping with the mouse (while projecting on geometry) and afterwards add four points around each shape for an imaginary texture frame. The shapes then should be drawn with a texture. At the end I have serveral non rectangular canvases to display the offscreen animation.
Page Index Toggle Pages: 1