Skip to main content
gamedev.net
🔒 Locked

MD2 loader texture problem

Started by bjmumblingmiles Jul 21, 2003 at 9:48 PM 2 replies 500+ views
Original Post
bjmumblingmiles
bjmumblingmiles
I have everything working on my MD2 loader (using vertex streams and tweening)...except the tex coords don't line up correctly...they look very funny. Here's my decompression code:
md2::tex_coord* c_buffer = new md2::tex_coord[header.num_st];
MD2_TEXTURE_VERTEX* tex_buffer = new MD2_TEXTURE_VERTEX[header.num_st];

md2_stream.seekg(header.ofs_st, std::ios::beg);
md2_stream.read((char*)c_buffer, sizeof(md2::tex_coord)*header.num_st);

for (int i = 0; i < header.num_st; i++)
{
	tex_buffer[i].s = ((float)c_buffer[i].s / (float)(header.skinwidth));
	tex_buffer[i].t = ((float)c_buffer[i].t / (float)(header.skinheight));
	}

device->CreateVertexBuffer(sizeof(MD2_TEXTURE_VERTEX)*header.num_st,0,0,D3DPOOL_MANAGED,&texture_VB,0);
See anything? This is my first time writing a loader, and I am ignorant about the format, so thanks! EDIT: fix formatting in source box
Brian J
DL Vacuum - A media file organizer I made | Mumbling Miles - A band I was the guitarist/vocalist for [edited by - bjmumblingmiles on July 21, 2003 11:32:06 PM]
Brian J
Pipo DeClown
Pipo DeClown
How do you set the texcoords? (in the function that you call to update the mesh)

.lick
bjmumblingmiles
bjmumblingmiles
I''m using vertex declarations:

D3DVERTEXELEMENT9 ve0[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{1, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 1},
{2, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};


then:


device->SetVertexDeclaration(vDecl);
device->SetIndices(model.GetModelIB());
device->SetStreamSource(0, model.GetModelVB(f_start),0,sizeof(MD2_POSITION_VERTEX));
device->SetStreamSource(1, model.GetModelVB(f_end),0,sizeof(MD2_POSITION_VERTEX));
device->SetStreamSource(2, model.GetTextureVB(),0,sizeof(MD2_TEXTURE_VERTEX));

device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, model.GetVertCount(), 0, model.GetTriangleCount());

For rendering...the animation works perfectly. With tweening, interpolation couldn''t be easier...but the tex coords are never in the right place...
Brian J
bjmumblingmiles
bjmumblingmiles
Ok, nevermind...I wasn''t getting indices for the tex coords, as I figured they would be in the same order as the vert indices...but for some odd reason they aren''t! thanks anyway
Brian J

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.