MD2 Problems

Ive been having this problem with my MD2 class based off of NeHe’s Lesson 4 Ive gone threw everything and I cannt see why its not displaying the MD2. Ive read threw everything on the net and have tryed a million ways of displaying it but none of them work. Can someone please take a look at my code.

Thanks
Nuke

P.S: This code was developed on linux using kdevelop. This code is also alpha alpha code so I know there are some things wrongs with it(dont worry no errors or warnings)

[This message has been edited by nukem (edited 10-19-2002).]

Hehe, your interpolation percentage code is exactly like mine. I guess it can’t very much if it ends up working.

Did you try drawing a simple shape to make sure that all the OpenGL stuff is set up right?

Did you step through your code with the debugger to make sure that the model was opened correctly?

md2 character models have 198 frames, did 198 frame get loaded?

LOL, that alien model was so cool I decided to use my GDK to animate him fer ya!

Alien Md2 -> s3d animation 1MB <IMG SRC="http://www.opengl.org/discussion_boards/ubb/eek.gif">

Spider3D saves the model as floating points so the animation is quit large :/. No matter what I did I couldn’t preserve the normals when scaling down from float to char.

Yes, I had other shapes on the screen and they still work, my bmp and tga loading code works because Ive tested both on a cube. According to my debuging code everything loaded perfectly. When I did
cout << md2.Frames;

Nothing came up, Im assuming that means it has 0 frames. If it dose what am I doing wrong?

Heh you should make your project open source or at least port it to linux, had to run it threw wine

[This message has been edited by nukem (edited 10-20-2002).]

I used the MD2 tutorial on http://www.gametutorials.com to help me learn the MD2 format and it works great! The only problem I had at first was I forgot that john carmack likes the winding of his polys to be CW for front facing, whereas I use CCW so my model looked a bit wierd at first. I suggest taking a look at that tut on that site there. If all else fails just use the code he provides which works for sure.

-SirKnight

The alien md2 has 198 frames so something should come up when you call cout << md2.Frame;

Try stepping through your code with the debugger and carefully match it up with the file format specs.

I would LOVE to port Spider3D to Linux. That would be soooooo cool. However, I don’t know how to use Linux and right now I don’t have the time to .

Hmmmmmm, I would have to fall back into console mode I think…I certainly don’t know how to init a Linux window.

For now it is Win32 only. One day it will be cross platform.

[This message has been edited by WhatEver (edited 10-21-2002).]

I looked at your code a bit right now. I can’t really see your rendering code having a problem…you’ll have to step through your code and see if everything loaded in correctly.

I do have a suggestion. You should do the scale and translate once to your vertices when you load in the model. It would surely speed up rendering time…that is, when you get it to render .

I noticed that Linux C/C++ uses the same headers as Win32 C/C++. That means whenever I do port Spider3D to Linux it’ll be a cake walk .

You need to change the following struct:-

struct VERTEX
{
//unsigned char Vertex[3];
float Vertex[3];
unsigned char LightNormalIndex;
};

to this…

struct VERTEX
{
unsigned char Vertex[3];
unsigned char LightNormalIndex;
};

and then change line # 1266 (in your render loop) from…

glVertex3fv(v1.vertex);

to…

glVertex3fv(&vertlist[loop].X);

[Edit - add some bold…]

[This message has been edited by rgpc (edited 10-22-2002).]

Whatever: I dont think its in my loading that seems prefect, I do think it is in the rendering. For Spider3D look into QT they have some stuff so you can have OpenGL in a window with some other stuff, or you could always do it in glut Thanks for the suggestion about the vertices ill do it as soon as I get this thing working.

rgpc: I did what you said and nothing happened. The compiler gave me a few warnings since I was doing

v1.Vertex[0] = vertlist[loop].X;
//I changed it to
v1.Vertex[0] = (char)vertlist[loop].X;

I also noticed that you told me to do glVertex3fv(&vertlist[loop].X); but what about Y and Z? I put them in and still nothing happened. Can you please explain more?

Thanks for all your help!

Nuke

Sorry, forgot the most important change of all…

Line 1208 reads…

currentframe = (FRAME*) ((char*)Frames + FrameSize * NumFrames);

Change this to…

currentframe = (FRAME*) ((char*)Frames + FrameSize * Frame);

You can get rid of the following code…

v1.Vertex[0] = vertlist[loop].X;
v1.Vertex[1] = vertlist[loop].Y;
v1.Vertex[2] = vertlist[loop].Z;

as the call…

glVertex3fv(&vertlist[loop].X);

Passes the pointer to the “X” component of your vertex. The reason you don’t need “Y” and “Z” is because you are passing a pointer to a 3 component vertex. So it assumes that (&vertlist[loop].X)[0] = “X” and (&vertlist[loop].X)[1] = “Y” and so on.

[This message has been edited by rgpc (edited 10-22-2002).]

Talking about the md2 format. Has anyone ever tried to read the GL command list instead of the triangle list and use that for rendering? Either there’s a massive bug in my reader that I can’t find (very likely :wink: or a lot of md2 models store the GL command list incorrectly. It seems that some triangles are missing and for some vertices the texture co-ordinates are incorrect, when I read the info out of the GL command list. Reading the regular triangle list and the texture co-ordinates list from the same model file gives the expected results.

Take a look at the Quake 2 engine source about loading the GL commands. I didn’t have a thorough look at it but I do remember seeing the GL command loading code.

-SirKnight

Originally posted by Asgard:
Talking about the md2 format. Has anyone ever tried to read the GL command list instead of the triangle list and use that for rendering? Either there’s a massive bug in my reader that I can’t find (very likely :wink: or a lot of md2 models store the GL command list incorrectly. It seems that some triangles are missing and for some vertices the texture co-ordinates are incorrect, when I read the info out of the GL command list. Reading the regular triangle list and the texture co-ordinates list from the same model file gives the expected results.

yes ive written a parser which seems to handle all md2 models ive thrown at it, i can post the source code if u wish?

Originally posted by zed:
i can post the source code if u wish?

I’d be very grateful if you do, so I can find the bug in my reader. Cheers.

BTW can anyone tell me why it’s possible to have multiple textures (skins as they call them) in an md2 file? I mean, in the format there’s no way of specifying which texture to use for which triangles, so what are they for?

rgpc: Thanks you sooooo much it finally works!!!

There is one problem though the texture dosnt get painted onto the model. Can someone please take a look at that? I put the new code here.

Asgard: Im pretty sure my code loads the glCommands correctly. The q2 source code can be found here at idsoftware or here

Thanks for all your help so far!!!

Well, I’m not familiar with the MD2 format and the use of the glCommands but I would guess the problem is in their somewhere.

You don’t use the NumTextcoords or OffSetTexCoords components of the Header record at all. You are trying to get your TexCoords out of the glCommands list (which seems wrong to me). In an example of an MD2 loader I have, they read the TexCoords using the above two variables and don’t seem to read the glCommands at all (not that I can see at any rate).

The example I am referring to can be found at…
http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg4.htm

He has it right. Each vertex has a uv coordinate.

I read in a targa file with my source code and it worked perfectly. You’ll need to check out your image reading routines.

You are correct. I just looked at a specification and found that the TexCoords are not used at all (which is odd because they are used by the example I gave the link too…

Anyway…

If you change your Texture creation to use…

gluBuild2DMipmaps(GL_TEXTURE_2D, 3, x, y, GL_RGB, GL_UNSIGNED_BYTE, data);

it should work.

It’s either a MipMapping problem or you’re using the same rotten version of MS-OpenGL my Laptop runs.

[This message has been edited by rgpc (edited 10-23-2002).]

i ripped this out of one of my old programs (hopefully its all the info u need) if not ill email more code

struct Tri_group
{
enum { STRIP, FAN };
int type;

int			num_indices;
int			*indices;
TEXCOORD	*texcoords;

int			*tri_indices;
int			num_tri_indices;

int		feed_data		( int *data );
void	convert_to_tris	( void );

};

// returns number of data, zero if thats all folks
int Tri_group::feed_data( int *data )
{
num_indices = abs( data[0] );
// printf("%d ", num_indices );
if ( num_indices )
{
if ( data[0] < 0 )
type = FAN;
else
type = STRIP;

	indices = new int[ num_indices ];
	//texcoords = new TEXCOORD[ num_indices ];
	int current_indice_count=0;

	while ( current_indice_count &lt; num_indices )
	{
	//	texcoords[ current_indice_count ].s = float(data[current_indice_count*3+1]);
	//	texcoords[ current_indice_count ].t = float(data[current_indice_count*3+2]);
	//	indices[ current_indice_count ] = data[current_indice_count*3+3];

		md2_vert temp;
		temp.texcoord = TEXCOORD( int_to_float(data[current_indice_count*3+1]), int_to_float(data[current_indice_count*3+2]) );
		temp.indice = data[current_indice_count*3+3];

		indices[ current_indice_count ] = return_this_verts_indice_number( temp );
	//	printf("%d ", indices[ current_indice_count ] );

		++current_indice_count;
	}
}

// printf("
");
return num_indices;
}

void Tri_group::convert_to_tris( void )
{
int i;
if ( type == STRIP )
{
num_tri_indices = (num_indices-2)*3;
tri_indices = new int[ num_tri_indices ];

	for ( i=0; i&lt;num_tri_indices; i+=3 )
	{
		// 0 3 6 9 12
		if ( i%6==0)
		{
			tri_indices[i+0] = indices[i/3+0];
			tri_indices[i+1] = indices[i/3+1];
			tri_indices[i+2] = indices[i/3+2];
		}
		else
		{
			tri_indices[i+0] = indices[i/3+1];
			tri_indices[i+1] = indices[i/3+0];
			tri_indices[i+2] = indices[i/3+2];
		}
	}
}
else if ( type == FAN )
{
	num_tri_indices = (num_indices-2)*3;
	tri_indices = new int[ num_tri_indices ];

	for ( i=0; i&lt;num_tri_indices; i+=3 )
	{
		tri_indices[i+0] = indices[0];
		tri_indices[i+1] = indices[i/3+1];
		tri_indices[i+2] = indices[i/3+2];
	}
}

}

Thanks, guys. I found the problem in my code (didn’t correctly change the orientation of the fans from clockwise to counter-clockwise).
Cheers.