Archived

This topic is now archived and is closed to further replies.

dopeflow

Rendering a .md2 via vertex array, texturing problem

Recommended Posts

K so Ive managed to render a md2 animated mesh using a vertex array with no problem at all, but Im running into some problems with the texturing. Basically Im just not sure how to load the texture array that you pass to glTexCoordPointer(2, GL_FLOAT, 0, texVB); every frame. I thought it would be something like: texVB= new float[2*m_numVertices]; and then for each vertices load the (s,t) values but apparently the number of texture coord can be different than the number of vertices? Anyway just looking for some pointers, right now I can texture the mesh but its just textured badly. Like not the right uv values for sure.

Share this post


Link to post
Share on other sites
You want to have 6 values for each poly. One (s,t) for each (triangular) Facet's corner. A mesh does have more Texture vertices than geometry vertices because the same Vertex can be "attached" to more than one part of the skin. For example, two contiguous poly's are mapped to different parts of the skin, the two vertices that they share can't have the same texture coords for both polys.

M


--------------------------------------------------
"I have never let my schooling interfere with my education. " --- M.Twain
Marcus Hays
www.phrenicgames.com

[edited by - mhays on May 4, 2003 6:07:32 PM]

Share this post


Link to post
Share on other sites
K well i mean what i do seems logical to me....
I load the md2 header and get the number of st''s from that.

Then create a "buffer" to the texture info in the file.

stIndex_t *stPtr;
stPtr = (stIndex_t*)&buffer[modelHeader->offsetST];
texVB= new float[2*m_numST];

and load up the st''s into my array which is the array i pass
to glTexCoordPointer(2, GL_FLOAT, 0, texVB);

for (t = 0; t < m_numST; t++)
{
texVB[2*t+0]= (float)stPtr[t].s / (float)m_modelTex->width;
texVB[2*t+1]= (float)stPtr[t].t / (float)m_modelTex->height;
}

That should work no?

Share this post


Link to post
Share on other sites
i think u load the texcoords right but how do u render the object?

btw if ur using a vertex array, how do u do the animation between keyframes (do u load another array with interpolated values? )

Share this post


Link to post
Share on other sites
I just render using glDrawElements, calling glTexCoordPointer before... its textured, just badly textured.

As for how I use vertex arrays with animation,
its simple you create an array
float *vertexB[number_of_frames];
then you load all the arrays for all the frame like this

for(int f= 0; f < number of_frames; ++f)
{
vertexB[f]= new float[number of vertices of mesh];
for(int v= 0; v < number of vertices; ++v)
{
load up vertices...
}
}

This makes up for a pretty big array im aware , but I have a mesh manager that makes sure each mesh is only loaded once so its not too bad.

[edited by - dopeflow on May 5, 2003 6:50:34 PM]

Share this post


Link to post
Share on other sites
mhays what you said could be right I think, I tried though but its not working either.

Heres how I load the texture array now:


  
texVB= new float[6*m_numTriangles];
for(int t = 0; t < m_numTriangles; t++)
{
texVB[6*i+0]= m_st[m_triIndex[t].stIndex[0]].s;
texVB[6*i+1]= m_st[m_triIndex[t].stIndex[0]].t;
texVB[6*i+2]= m_st[m_triIndex[t].stIndex[2]].s;
texVB[6*i+3]= m_st[m_triIndex[t].stIndex[2]].t;
texVB[6*i+4]= m_st[m_triIndex[t].stIndex[1]].s;
texVB[6*i+5]= m_st[m_triIndex[t].stIndex[1]].t;
}


This is after I load up the tri index obviously, which I know is right because when i rendered vertex per vertex it was working perfectly.

Just need to get that damn texture array working hehe
im doing 0 - 2 - 1 order because thats how it was in the book, but I also tried 0 - 1 - 2, not working either. Texture is still badly applied.

[edited by - dopeflow on May 6, 2003 7:35:08 PM]

Share this post


Link to post
Share on other sites
Been trying the same thing.
ran into the same problem.

to draw it I simply loaded the vertex(s) into the card,
Then called them glDrawElements.

the problem is the one vertex can be use for many triangles.
as well as one vertex can have many texture points.

If you want to do all the drawing in one call then you need to make the vertex to texture arrays a one to one relationship and ajust the calling list to suit.

this has the virtue of speed, but the problem of more memory needing to be both allocated and then pushed across the buffers.

my 2cents.



Armand
-------------------------
It is a good day to code.

Share this post


Link to post
Share on other sites
hmm there has to be a way around this, the quake2 models arent perfectly fit (the number of STs can be different than the number of vertices) and im sure they render via vertex arrays too.

I know theres a way

Share this post


Link to post
Share on other sites

make an indexed vertex array with the vertices and the respective texcoords.

in md2 numTexCoords != numVertices so u''ll have to get the texcoords for each vertex.

the md2face has 6 indices, 3 for vertices and 3 for texcoords so use those

remember that only the first frame has tex coords so u''ll make only one tex coord array.

Share this post


Link to post
Share on other sites
hm are you sure you want to animate your models that way?

id further more interpolate between the current and the last/next frame
since vertex arrays store the geometry in your RAM you can easily apply the transformations
and probably you should use 1 big texture 1024*1024
that contains all your skin parts

once you got that you should be able to render your animated mode with one single call to glDrawArrays


thx for listening

Share this post


Link to post
Share on other sites
Sorry to bring back an old thread to life but I still have the same problem

Basiror : i implemented vertex interpolation now and it works real good

But I still cant get the mesh properly textured. I noticed that the md2 mesh had a index list for both the vertices and the texture coordinates.

Im thinking maybe this could be my problem, since when you call glDrawElement you only pass the triangle index list....

So somehow I would have to build my texture array so that every texture coord matches the correct vertice, I just dont know how to do it.

Share this post


Link to post
Share on other sites