md2 texturing

Started by
14 comments, last by Endar 18 years, 4 months ago
And here's a new thread about my md2 texturing problem. I was under the impression, from info gotten from my fellow gamedevers that my model wasn't texturing properly because my texture coords were wrong. Here's a pic of what mine currently looks like. Now, here's what a pic of the loader I got from "OpenGL Game Programming" looks like when I give it the model and texture I'm using. They look almost exactly the same. Does this imply that the bitmap I'm using is the wrong format? Or is the model file dodgy?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Advertisement
You can allways go to Polycount and download a few Quake 2 MD2 models to veridy that you're working with valid data.

Here's a list of files.
Could trying to load an 8-bit bitmap with a loader that is written for 24-bit bitmaps be the problem?
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
*bump bump bump*
Quote:Original post by Anonymous Poster
*bump bump bump*


We're still having some logout problems I see.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
SUCCESS!!!

It was the fact that I was trying to load an 8-bit bitmap image with a loader that was written to read 24-bit bitmaps. Guess I'll have to work on that pcx loader.

Anyway, this is what I've come up with.

I'm not sure if you can really understand just from the picture, but when the model rotates, you can see that when the back of the model is facing towards you, you see the front of the texture and vice versa.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Congrats! Nothing like the taste of a successful compile... [wink]
Thanks.

Now, I just have the slightly smaller problem of the backwards looking texture, and getting the animation to run at the right speed, and I'm completely home free, never to touch the md2 code that has been so painful over the last couple of weeks. [smile]

So, has anyone come across this before? Looking at the front of the model and seeing the back texture and vice versa?



This is what I've got, and I'm assuming that I have to mess around with some "- 1" or "1 - "

// point 0tempst[0] = ((float)stPtr[indexList.stIndex[0]].s) / (float)modelHeader->skinwidth;tempst[1] = 1 - ((float)stPtr[indexList.stIndex[0]].t) / (float)modelHeader->skinheight;// point 1tempst[2] = ((float)stPtr[indexList.stIndex[1]].s) / (float)modelHeader->skinwidth;tempst[3] = 1 - ((float)stPtr[indexList.stIndex[1]].t) / (float)modelHeader->skinheight;// point 2tempst[4] = ((float)stPtr[indexList.stIndex[2]].s) / (float)modelHeader->skinwidth;tempst[5] = 1 - ((float)stPtr[indexList.stIndex[2]].t) / (float)modelHeader->skinheight;
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Okay, well, I've come back to this problem.

I'm looking for any ideas.

The problem again: when the back of the model is visible, you see the part of the texture that should be overlaid on the front of the model, and when you see the front of the model, you see the part of the texture that should be overlaid on the back of the model.

The actual model render's normally, so its confusing when you see the texture of the model's face and the geometrey of hey pony-tail at the same spot.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
Your model is very tall! Maybe perspective. Anyway:

Image hosted by Photobucket.com

And yes, that's a crazy spaceship (.3ds). Now, I didn't have to muck around with 1.0f -, etc. Here's the code:

To read the texture coordinates into a vector:
	//=====================================================================	// Read the model texture coordinates	//=====================================================================	// a buffer or our texture coordinates	vector<SVector2> texture_coords_vector(numTexCoords);		for(long i = 0; i < numTexCoords; i++)	{		SVector2 p;		p.x = float(stream->read16() + 0.5f) / float(skinWidth); 		p.y = float(stream->read16() + 0.5f) / float(skinHeight);		texture_coords_vector = p;	}


Then I'm going to show you my code to read the triangle information in:
	//=====================================================================	// Read the model triangles	//=====================================================================	stream->seek(offsetTriangles);	mesh->mMeshDescriptor.UseIndexBuffer = true;	mesh->mMeshDescriptor.Indices = numTriangles * 3;		// create buffer	mesh->mIndexBuffer = silk::createIndexBuffer(numTriangles * 3 * sizeof(short), new CIndexDescriptor16, false, DYNAMIC);	// lock buffer	unsigned short * indices = reinterpret_cast<unsigned short*>(mesh->mIndexBuffer->lock(silk::NORMAL));		// a buffer of indices to texture coordinates	vector<unsigned short> texture_coords_index_vector;		for(long i = 0; i < numTriangles; i++)	{		// for each indice, read it		for (int j = 0; j < 3; j++) indices = stream-&gt;read16();<br>		<span class="cpp-comment">// for each indice, store its texture coordinate index</span><br>		<span class="cpp-keyword">for</span> (<span class="cpp-keyword">int</span> j = <span class="cpp-number">0</span>; j &lt; <span class="cpp-number">3</span>; j++) texture_coords_index_vector.push_back(stream-&gt;read16());<br>	}<br><br></pre></div><!–ENDSCRIPT–><br><br>And finally the code to put them all in the right order:<br><!–STARTSCRIPT–><!–source lang="cpp"–><div class="source"><pre><br>	<span class="cpp-comment">// make space for it all</span><br>	texcoords.resize(numTriangles * <span class="cpp-number">3</span>);<br>	<br>	<span class="cpp-comment">// fill it all in, in the correct order</span><br>	<span class="cpp-keyword">for</span> (<span class="cpp-keyword">long</span> i = <span class="cpp-number">0</span>; i &lt; numTriangles * <span class="cpp-number">3</span>; i++)<br>	{<br>		texcoords[ indices<span style="font-weight:bold;"> ] = texture_coords_vector[  texture_coords_index_vector<span style="font-weight:bold;">  ];<br>	}<br><br></pre></div><!–ENDSCRIPT–><br><br><br>There. Now "texcoords" is a vector comprising of the texture coordinates (in the right order) for each corresponding vertice. Hope that helps.
[ search: google ][ programming: msdn | boost | opengl ][ languages: nihongo ]

This topic is closed to new replies.

Advertisement