Jump to content
  • Advertisement
Sign in to follow this  
Nickolas Hu

OpenGL odd question when i draw a MD2 model

This topic is 3003 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

I wanna render a MD2 model using OpenGL. i load MD2 file and a texture. But the result is so weird. The vertices seem to be right, but the texture on the model is wrong.It looks like the texture coordinates are incorrect. But i test the same method of loading MD2 file using DirectX. It works correctly! So, the data are right. And it isn't the BMP file's problem , i test it as well. Thank you for your help. I'm really confused. Here goes some critical part of my program. //The method set the texture void ARModel::setTexture( void ) { glEnable(GL_TEXTURE_2D); glGenTextures(1, &mTexId); glBindTexture(GL_TEXTURE_2D, mTexId); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, (int)(texture.getWidth()), (int)(texture.getHeight()), 0, GL_RGB, GL_UNSIGNED_BYTE, texture.getData()); } //The method render the model void ARModel::renderModel(void) { //buffer has all the MD2 data mMd2Model.updateBuffer(); VERTEX_XYZ_NORMAL_TEX0 *pRenderBuffer = mMd2Model.getRenderBuffer(); glEnable(GL_NORMALIZE); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, mTexId); glBegin(GL_TRIANGLES); for (size_t i=0; i< 3 * mMd2Model.getTrianglesNumber();) { glNormal3fv(&pRenderBuffer.nx); glTexCoord2f(pRenderBuffer.coordX,pRenderBuffer.coordY); glVertex3fv(&pRenderBuffer.x); i++; glNormal3fv(&pRenderBuffer.nx); glTexCoord2f(pRenderBuffer.coordX,pRenderBuffer.coordY); glVertex3fv(&pRenderBuffer.x); i++; glNormal3fv(&pRenderBuffer.nx); glTexCoord2f(pRenderBuffer.coordX,pRenderBuffer.coordY); glVertex3fv(&pRenderBuffer.x); i++; } glEnd(); glDisable(GL_NORMALIZE); glDisable(GL_TEXTURE_2D); }

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!