mesh / msashape3d for newbies

hi all,

I am a completely newbie at mesh formatting and using textures in opengl so wanted to ask some basic advice.

  1. Firstly, I have a list of triangles that make up a polygon shape. Right now I am created the vertices like this…

(using MSAShape3d by the way)

  
  
shape.begin(GL_TRIANGLES);  
	  
for(int i=0; i<triangles.size(); i++){  
	  
	shape.addVertex(triangles[i].points[0].x, triangles[i].points[0].y, 0);  
	  
	shape.addVertex(triangles[i].points[1].x, triangles[i].points[1].y, 0);  
	  
	shape.addVertex(triangles[i].points[2].x, triangles[i].points[2].y, 0);  
	  
}  
  
shape.end()  
  

Should I be creating the vertices in a certain order? The mesh draws as I expect it to look, but can’t help feeling it was too easy.

  1. Texturing. I grab a region of the screen like this

texture.allocate(640, 480, GL_RGB);
texture.loadScreenData(0,0,640,480);

Then in the above code I have …

  
  
for(int i=0; i<triangles.size(); i++){  
		  
	shape.addVertex(triangles[i].points[0].x, triangles[i].points[0].y, 0);  
	shape.setTexCoord(triangles[i].points[0].x, triangles[i].points[0].y);  
		  
	shape.addVertex(triangles[i].points[1].x, triangles[i].points[1].y, 0);  
	shape.setTexCoord(triangles[i].points[1].x, triangles[i].points[1].y);  
		  
	shape.addVertex(triangles[i].points[2].x, triangles[i].points[2].y, 0);  
	shape.setTexCoord(triangles[i].points[2].x, triangles[i].points[2].y);  
}  
  
texture.bind();  
shape.end();  
texture.unbind();  
  

This is where I fall down with lack of opengl knowledge. How does/should setTexCoord work?

The polygon shape should almost sit on top of the texture at 0,0 so that when I warp the mesh, the texture warps with the triangles in the mesh.

Any advice would be greatly appreciated.

Thanks

Progress of sorts.

setTexCoord() needs to go before addVertex()

at the moment grabbing the screen, the texture is upside down when i bind it and show with the mesh.

I am using triangles from ofxDelaunay and it seems to work now, however the problem I have now is that instead of having a clever mesh of vertex points that make up the triangles (so a point is only used once, one index), i have separate triangles. that means when I move a triangle within the mesh, its not attached to the other vertices, does that make sense?