سؤال

I was looking at this tutorial : http://www.raywenderlich.com/32954/how-to-create-a-game-like-tiny-wings-with-cocos2d-2-x-part-1

And couldn't understand what some of the calculations are for:

        _hillVertices[_nHillVertices] = CGPointMake(pt0.x, 0 + minY);
        _hillTexCoords[_nHillVertices++] = CGPointMake(pt0.x/512, 1.0f);
        _hillVertices[_nHillVertices] = CGPointMake(pt1.x, 0 + minY);
        _hillTexCoords[_nHillVertices++] = CGPointMake(pt1.x/512, 1.0f);

        _hillVertices[_nHillVertices] = CGPointMake(pt0.x, pt0.y);
        _hillTexCoords[_nHillVertices++] = CGPointMake(pt0.x/512, 0);
        _hillVertices[_nHillVertices] = CGPointMake(pt1.x, pt1.y);
        _hillTexCoords[_nHillVertices++] = CGPointMake(pt1.x/512, 0);

How does openGl use the vertices and texture coords ? From the tutorial, I understand that you need the vertices of the the triangles that you intend to draw that make up the boundary of the image, and that seems to make sense.

But what are the texture coords for, and how does OpenGL use them ? Why is the order important ?

هل كانت مفيدة؟

المحلول

Texture coordinates tell OpenGL which area of a given flat image is to be mapped to the defined triangles. There's no way to figure that out automatically. Normally artists will define texture coordinate mappins while creating the 3D model.

Recently Disney Animation developed a new texturing scheme called PTex where each triangle holds its very own texture; apart from relieving the artist caring about texture coordinates it also eliminates the mathematical problems when trying to map a topologically flat image onto geometries of different topology.

نصائح أخرى

Looks like the calculation of additional vertices and texture coordinates are for smoothing out the terrain contour.

The tutorial does that by generating triangle strips with the newly created vertices. And for the triangle strips, the order of the vertices are important.

The textures are like colors. For each vertex, you either need a color value or texture coordinate to interpolate and fill-in the pixel values between vertices. If the texture coordinate is not set properly for each vertex, you'll see distorted texture rendered on the screen.

You may use that to your advantage for other visual effects, but maybe not in this case for the tutorial.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top