PDA

View Full Version : MDL(half-life models) and textures



nukem
01-28-2003, 06:51 PM
Im making my own mdl engine called NuclearMDL. I got the base code of how to open all the files from the hlsdk, from a guy that put it all together its called hlload. What Im trying to do is make it alot less complex and have it alot smaller. Everything works fine but displaying the textures. If you do not know, usally the textures in mdl files are stored in the mdl file itself unlike most other model files. The file loads with no errors but when it goes to displaying the model it draws the skeleton fine but with no texture. Ive done everything to find out whats wrong and I cannt figure out whats wrong. Can someone plz help me? I was wondering if there was ogl code to detect whether or not texture loading went well or not.

The Code (http://zonkbonk.virtualave.net/MDL.zip)


Thanks,
Nuke

[This message has been edited by nukem (edited 01-28-2003).]

Coriolis
01-28-2003, 07:03 PM
glGetError() will tell you if there was an error since the last time glGetError() was called. So, call it before a function to clear out the last error code, and call it after the function to see if it succeeded.

nukem
01-28-2003, 07:25 PM
I did this




if(glGetError() != GL_NO_ERROR)
{
cout << "error\n";
}

Right before and after it sends the texture data to ogl in UpLoadTexture and in the main file before and after mdl.DrawModel() nothing came up.

[This message has been edited by nukem (edited 01-28-2003).]

jwatte
01-29-2003, 07:28 AM
Try replacing parts of your code with known-working code. Replace geometry drawing with a cube (or a simple quad). Replace TexImage() with something that points at a black-and-white checker square. Replace all camera code with identity, and offset the geometry. Keep making one thing work at a time, and then put back in the next step, and make that work, until you're done.

If it's something hairy like the thing draws un-skinned, but not skinned, then you might need to put a breakpoint and examine your animation->matrix->skinning code by single-stepping, looking at input and output data, and following along with paper and pencil.

nukem
01-29-2003, 02:13 PM
Im not sure I understand what your saying. My program draws the model animates and does all that just fine it just wont display the texture.

Here are some screen shots of both engines using the same model

NuclearMDL the model is 3D but since you cannt see the texture you cannt notice it with out rotating it (http://zonkbonk.virtualave.net/NMDL.jpg)
HLLoad run via winex (http://zonkbonk.virtualave.net/HLL.jpg)

Note: since there diffrent engines/programs there rendered at a diffrent angle but they are the same model.

[This message has been edited by nukem (edited 01-29-2003).]

rgpc
01-29-2003, 02:21 PM
Try drawing the texture on a quad to see if the texture is even getting to opengl. If it isn't trace back from there (ie. Why is it not getting to opengl?)

Is the data being read correctly? Is it being sent to Opengl in the correct format (ie. GL_UNSIGNED_BYTE, GL_RGBA?)

nukem
01-29-2003, 03:05 PM
I drew a cube with this code




void Cube()
{
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
// Top Face
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
// Bottom Face
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
// Right face
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
// Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glEnd();
}


In the display funtion and NuclearMDL I added some code to get the texture number thats being used.




glPushMatrix();
glBindTexture(GL_TEXTURE_2D, mdl.extracttext);
glTranslatef(-3.0, 0.0, -10.0);
Cube();
glPopMatrix();


Well apprently its not being passed to OGL all im seeing is a black cube. How would I go about fixing this?

secnuop
01-29-2003, 03:32 PM
I found several errors. Some of them I'm a bit surprised gcc didn't flag.

* line 981, tmp is not initialized
* line 1357, check your semicolons

I also kept crashing in glTexImage. This usually means that the pointer you pass in is bogus or that your dimensions are wrong. In this case it looks like the former. If you're going to increment the pointer ("tex+=4"), make sure that you don't pass in the incremented pointer to glTexImage. http://www.opengl.org/discussion_boards/ubb/smile.gif

With these errors fixed I see a textured model!

nukem
01-29-2003, 06:53 PM
Im a bit surprised as well. I still cannt get it to work though. I zeroed out tmp and took out the semicolon. I cannt beleve I missed thoses to many late nights I guess hehehee. What I think the error is is with the pointer. Im not sure whats wrong though I passed it to another pointer and still nothing. Here take a look




void UpLoadTexture(Texture* text, BYTE* data, BYTE* pal)
{
int i;
int row1[256];
int row2[256];
int col1[256];
int col2[256];
BYTE* pix1;
BYTE* pix2;
BYTE* pix3;
BYTE* pix4;
BYTE* tex;
BYTE* out;
int outwidth;
int outheight;
static int gtexnum = 1;

for(outwidth=1;outwidth<text->width;outwidth<<=1);

if(outwidth > 256)
{
outwidth = 256;
}

for(outheight=1;outheight<text->height;outheight<<=1);

if(outheight > 256)
{
outheight = 256;
}

out = tex = new BYTE[outwidth * outheight * 4];
//out = tex = (BYTE*)malloc(outwidth * outheight * 4);

for(i=0;i<outwidth;i++)
{
col1[i] = (int)((i + 0.25) * (text->width / (float)outwidth));
col2[i] = (int)((i + 0.75) * (text->width / (float)outwidth));
}

for(i=0;i<outheight;i++)
{
row1[i] = (int)((i + 0.25) * (text->height / (float)outheight)) * text->width;
row2[i] = (int)((i + 0.75) * (text->height / (float)outheight)) * text->width;
}

for(i=0;i<outheight;i++)
{
for(int j=0;j<outwidth;j++,tex+=4)
{
pix1 = &amp;pal[data[row1[i] + col1[j]] * 3];
pix2 = &amp;pal[data[row1[i] + col2[j]] * 3];
pix3 = &amp;pal[data[row2[i] + col1[j]] * 3];
pix4 = &amp;pal[data[row2[i] + col2[j]] * 3];

tex[0] = (pix1[0] + pix2[0] + pix3[0] + pix4[0]) >> 2;
tex[1] = (pix1[1] + pix2[1] + pix3[1] + pix4[1]) >> 2;
tex[2] = (pix1[2] + pix2[2] + pix3[2] + pix4[2]) >> 2;
tex[3] = 0xFF;
}
}

glBindTexture(GL_TEXTURE_2D, gtexnum);
glTexImage2D(GL_TEXTURE_2D, 0, 3, outwidth, outheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, out);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

text->index = gtexnum;
gtexnum++;
}


Im not sure what other way to pass it. Can you please tell me whats wrong?

Thanks for all your help so far!!!

secnuop
01-29-2003, 07:39 PM
That's weird. I just cut / pasted your code into my file and it also worked fine.

You didn't change anything else other than the errors I mentioned that might cause things to stop working?

nukem
01-29-2003, 08:29 PM
heh thanks it works now!!! Its something with my main program, I only posted the MDL engine since the hole thing is over 5k lines http://www.opengl.org/discussion_boards/ubb/wink.gif. Ill fix it later tonight. I got it working in the demo I posted though. Do the models seem a little quaded to you using my engine? Take a look at this comparision screenshot I took. Note: its an uncompressed bmp(354.1kb) (http://zonkbonk.virtualave.net/compare.bmp)

Thanks!!

Nuke