Most file format are built for efficiency. Often times they will define all of the unique vertices, unique normals, unique texture coordinates and then give you faces which have pointers to the 3 vertices, normals and texture coordinates for that face. That's ideal because it's the smallest possible file size containing the correct information. The only issue is that someone has to write the importer to create the arrays that opengl can use out of it. It's actually not that hard if you just sit down and spend a few hours on it. BTW - if you're ever dealing with meshes larger than say 50 verts or so, consider using degenerate triangle strips. Supposedly they work great on the qualcomm chips.
On Mar 24, 12:59 pm, Perty <pertyj...@gmail.com> wrote: > Ok, > > So the conclution is that it's not working the way I thought it > would :-) > > I'm importing the vertex, colors and normals from a collada.xml and > it's build in a nice way with indices so I assumed they had OpenGL in > mind when they developed the format and therefore pursued with the > glDrawElement... > > I'll go with the glDrawArrays which working really nice, but this > issue really annoyed me. > > Thanks both Robert and Mario. > > /Perty > > On 24 mar, 18:37, Robert Green <rbgrn....@gmail.com> wrote: > > > > > In short, what mario is saying is that if you have the same vertex and > > you want different texture coordinates for it (like if you want to > > display the same texture on each side of a cube, the verts each need 3 > > different texture coordinates), it's no longer the same vertex but a > > different vertex with a different texture coordinate at the same > > location. > > > A cube is one of the most extreme examples of inefficiencies as far as > > that goes because it has those hard edges and generally you want the > > texture to not wrap around it but instead to be face-aligned, which is > > why you must duplicate each vertex 3 times. Your indices will still > > save you a little duplication because you still need 2 triangles per > > side and those CAN share 2 vertices, like in my example above. > > > a better example of efficiency is with characters. Textures tend to > > wrap around them nicely and they are usually smooth for most of the > > top so you get very good vertex sharing on them. > > > On Mar 24, 10:45 am, Mario Zechner <badlogicga...@gmail.com> wrote: > > > > You can't specify that with indices. Instead you will have to > > > duplicate those vertices which share the same position but have > > > different normals, colors and texture coordinates. Think of it this > > > way: You have an array of vertices, each defined by a position, color, > > > normal and texture coordinates. When you specify the different > > > glXXXPointers you simply tell OpenGL where to look for the position, > > > normal, color and texture coordinates of a single vertex. The pointers > > > you give OpenGL point to the first vertex' attributes. When you then > > > specify your indices later on when invoking glDrawElements the indices > > > map to that vertices array. An index of 0 will take the first position > > > from the pointer you passed to glVertexPointer, the first color from > > > the pointer you passed to glColorPointer and so on. You can not say: > > > use the position at index 0 in the vertex position array and the color > > > from position 3 in the color array for this vertex. Thus the 1:1:1:1 > > > mapping. > > > > On 24 Mrz., 10:11, Perty <pertyj...@gmail.com> wrote: > > > > > Hi Robert, thanks for your help. > > > > > Yes, thats makes sense and it's exactly how I do it I think. > > > > > But does the relationship (1 to 1 to 1 to 1, > > > > vertexarray,colorarray,normalarrat, textmaparray) still apply when you > > > > use glDrawElements ? > > > > > For example a when creating a 3D cube, the same vertex could have > > > > three different colors and three different normals depending on the > > > > triangle it belongs to, so the arrays can't have (?) the same one to > > > > one relationship. > > > > > So, the question is how do I map the colors to the indexed vertex? > > > > > /Perty > > > > > On 24 mar, 06:00, Robert Green <rbgrn....@gmail.com> wrote: > > > > > > Vertices, Texture coordinates, Normals and Colors have a 1 to 1 to 1 > > > > > to 1 relationship. That means that for any given vertex, you can > > > > > define: > > > > > > The vertex's location > > > > > The texture coordinate > > > > > The normal > > > > > The color > > > > > > If you define 4 vertices (with or without any of the other attributes, > > > > > doesn't matter), you can draw 2 triangles using drawElements. > > > > > > Let's say that your verts define the following for a 2d square: > > > > > > top left, top right, bottom right, bottom left > > > > > > Easy enough, clockwise rotation. > > > > > > Your indices would look like: 0,1,2, 0,2,3 > > > > > > let's say you put that into a directly-allocated ShortBuffer called > > > > > indexBuffer. > > > > > You'd then just call glDrawElements(GL10.GL_TRIANGLES, 6, > > > > > indexBuffer); > > > > > which says, "draw triangles using 6 points indexed by this index > > > > > buffer" > > > > > > Make sense? > > > > > > On Mar 23, 6:09 pm, Perty <pertyj...@gmail.com> wrote: > > > > > > > Hi, > > > > > > > If I use a glColorPointer together with a glVertexPointer and a > > > > > > glNormalPointer the vertex is all in the same position in the array > > > > > > (taking into accont the stride). > > > > > > > Thats working fine. > > > > > > > But if I want to use the glDrawElement to save some memory > > > > > > (performance?) I do not understand how I should map > > > > > > the normals and the colors. > > > > > > > How does the vertexIndex lookup table relates to the colors and > > > > > > normals? > > > > > > > The glDrawElements is rendering the triangles fine but the normals > > > > > > and > > > > > > colors is all messed up. So I manually traverse the the index and > > > > > > creates a vertexArray now. > > > > > > > It feels like I have just made a simple error. > > > > > > > /Regards Perty -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to email@example.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.