Jump to content
  • Advertisement
Sign in to follow this  
Endar

md2 texturing

This topic is 4862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
Could trying to load an 8-bit bitmap with a loader that is written for 24-bit bitmaps be the problem?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
*bump bump bump*

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
*bump bump bump*


We're still having some logout problems I see.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 0
tempst[0] = ((float)stPtr[indexList.stIndex[0]].s) / (float)modelHeader->skinwidth;
tempst[1] = 1 - ((float)stPtr[indexList.stIndex[0]].t) / (float)modelHeader->skinheight;
// point 1
tempst[2] = ((float)stPtr[indexList.stIndex[1]].s) / (float)modelHeader->skinwidth;
tempst[3] = 1 - ((float)stPtr[indexList.stIndex[1]].t) / (float)modelHeader->skinheight;
// point 2
tempst[4] = ((float)stPtr[indexList.stIndex[2]].s) / (float)modelHeader->skinwidth;
tempst[5] = 1 - ((float)stPtr[indexList.stIndex[2]].t) / (float)modelHeader->skinheight;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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[i * 3 + j] = stream->read16();
// for each indice, store its texture coordinate index
for (int j = 0; j < 3; j++) texture_coords_index_vector.push_back(stream->read16());
}



And finally the code to put them all in the right order:

// make space for it all
texcoords.resize(numTriangles * 3);

// fill it all in, in the correct order
for (long i = 0; i < numTriangles * 3; i++)
{
texcoords[ indices ] = texture_coords_vector[ texture_coords_index_vector ];
}




There. Now "texcoords" is a vector comprising of the texture coordinates (in the right order) for each corresponding vertice. Hope that helps.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!