Rendering a .md2 via vertex array, texturing problem

Started by
12 comments, last by dopeflow 20 years, 11 months ago
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.
Advertisement
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]
--------------------------------------------------"I have never let my schooling interfere with my education. " --- M.TwainMarcus Hayswww.phrenicgames.com
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?
Still looking for help on this, cant figure this out
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? )
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]
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]
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.
Armand -------------------------It is a good day to code.
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
Anyone has been able to render a md2 with vertex arrays, using glVertexPointer
and
glTexCoordPointer

with correct texturing??

This topic is closed to new replies.

Advertisement