Texture mapping problem of shared vertex when drawing elements?

Started by
1 comment, last by ZHAO Peng 13 years, 11 months ago
Hello, I am working hard at the OpenGL 3.2 core profile and try to write a function like glutSolidSphere. I put the vertex coordinates, normals and texture coordinates in different VBOs and draw all the triangles using glDrawElements. However, there is a problem for texture mapping. In common, sphere surface is cut into several slices using parallel planes. And each slice is approximated using a circular triangle strip. For example, i1_ i2_ i3_ i4 ..... in _ i1 .|\ | \ | \ |..........| \ | j1_\j2_\j3_\j4 ..... jn _\j1 And I allocate the texture coordinates as followed i1....... ...... in i1 (0,vi) ...... (un,vi) (1,vi) j1 ....... jn j1 (0,vj) ...... (un,vj) (1,vi) Among these vertexes, i1 and j1 are used when draw the first and last triangle. For the first triangle, their texture coordinate should be (0,vi) and (0,vj) and for the last one they should be (1,vi) and (1,vj). If I don't want to add two reduplicate vertexes and use the same indices for two triangles, one glDrawElement call could not draw them. Are there some smart ways to deal with this problem? Thank you!
Advertisement
Just duplicate the vertices, its the common solution and relatively inexpensive. You're going to have to do this anyway anytime you want to have two textures bordering each other.

Also I might point out that I think triangle strips have fallen out of favor these days, so it might not be worth your trouble to try to make lists instead of just plain triangles. I don't have a great explanation, it has something to do with triangles being more cache friendly, but I don't know for sure.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Actually, as you mentioned I just draw plain triangles with duplicate vertexes. Thanks for your quick reply, karwosts.

This topic is closed to new replies.

Advertisement