Shared information between vertices on a same triangle

Hello guys,

I have a question about sharing information between vertices on a same triangle when writing GLES 2 shaders.

before, when we use Opengl, sharing an information between vertices on a same triangle is very easy.

for example, if we want the normal of the three vertices of the triangle be the same, we can simply do this:

glBegin(GL_TRIANGLES);
glNormal3f();
glVertex3f();
glVertex3f();
glVertex3f();
glEnd();

the three points will have the same normal inside the shader program.

but as for GLES2 (and i guess the new opengl standard), we are forced to use vertex attributes.

so how do i share an information between points on the same triangle.

the normal case is one example. another example is the texture coordinate case.

for example, if i want to texture map a ball. there must be some points that are on the seam of the texture. in other words, those points must have two sets of texture coordinates or even more.

depending on which triangle you are drawing, you assign difference texture coordinates to the point.

but with gles 2 shader, i don’t know how to do this, because it seems that a vertex always maps to a single texture coordinate:

attribute vec4 vertex;
attribute vec4 texcoord;

of course, duplicating points is a solution, but in the facet normal case, you need to duplicate a lot of points in order to use different normals on different facet.

i would like to give another example:

suppose we have a geometry object formed by triangles.

now, i need to write a gles 2 shader that color different triangle with different color.

how do i do that?

Yes, you’ll have to duplicate the data. glBegin(); glNormal3f();…; glEnd(); is simply duplicating the data for you.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.