   help debugging a MD2 display function with Dev-C++
  Hi thereI am trying to get some code for a frustum Culling program working the one in Beginning OpenGL Games programming.The problem I want to be able to rotate from 0 to 360 deg in a world with a terrain and a basic skybox and while doing so viewing enemies which are randomly scattered in the world to save processing only the models in the view will be rendered.What I have workingI have the terrain and the skybox and the viewing and rotation working properlyWhats wrong. The code for displaying the MD2 models seems to be the fault I use the following initialise function/////////////////////////////////////////////////////////////////////////////bool CGfxOpenGL::InitializeCreatures(){srand(27);m_rhinoModel.Load("rhino//tris.md2","rhino//rhino.tga",0.1);if(m_centaurModel.Load("centaur//tris.md2","centaur//centaur.tga",0.1)==false)//exit(0);if(m_demonModel.Load("nemocromicus//tris.md2","necromicus//necromicus.tga",0.1)==false)//exit(0);for(int i=0;i<NUM_CREATURES;++i){   GLfloat x,z;   do{ x = FRAND() + (float)TERRAIN_SIZE/2*CREATURE_SCALE; z = FRAND() + (float)TERRAIN_SIZE/2*CREATURE_SCALE; }while(x*x+z*z < CREATURE_MIN_DISTANCE*CREATURE_MIN_DISTANCE);  m_rhinos[0] =x; m_rhinos[1] = GetHeightAt(x,z); m_rhinos[2] =z; m_rhinos[3] =FRAND()*360.0f;    do{ x=FRAND() * (float)TERRAIN_SIZE/2*CREATURE_SCALE; z=FRAND()*(float)TERRAIN_SIZE/2 *CREATURE_SCALE; }while (x*x + z*z<CREATURE_MIN_DISTANCE*CREATURE_MIN_DISTANCE);  m_centaurs[0] = x; m_centaurs[1] =GetHeightAt(x,z)+100; m_centaurs[2] = z; m_centaurs[3] = FRAND()*360.0f;    do{ x=FRAND()*(float)TERRAIN_SIZE/2 * CREATURE_SCALE; z=FRAND()*(float)TERRAIN_SIZE/2 * CREATURE_SCALE; }while (x*x+z*z<CREATURE_MIN_DISTANCE*CREATURE_MIN_DISTANCE);  m_demons[0] =x; m_demons[1] =GetHeightAt(x,z)+100; m_demons[2] = z; m_demons[3] = FRAND() * 360.0f; }m_centaurModel.SetAnimation(CMD2Model::RUN,CMD2Model::IDLE);m_demonModel.SetAnimation(CMD2Model::IDLE,CMD2Model::IDLE);m_rhinoModel.SetAnimation(CMD2Model::IDLE,CMD2Model::IDLE);return true;}///////////////////////////////////////////////where the Load function is//////////////////////////////////////////////////////////////////bool CMD2Model::Load(char *modelFile,char *skinFile,GLfloat scale){FILE *pFile = fopen(modelFile,"rb");if(pFile == NULL){//fprintf(stderr,"oh");return false;} //    modelHeader_t tmp;fread(&m_info,sizeof(modelHeader_t),1,pFile);m_verts = new xyz_t[m_info.numXYZ * m_info.numFrames];char *buffer = new char[m_info.numFrames * m_info.framesize];fseek(pFile,m_info.offsetFrames,SEEK_SET);fread(buffer,m_info.numFrames,m_info.framesize,pFile);int i,j;frame_t *frame;xyz_t *pVerts;m_miny = FLT_MAX;GLfloat maxy = FLT_MIN;for(j=0;j<m_info.numFrames;++j){ frame =(frame_t*)&buffer[m_info.framesize*j]; pVerts = (xyz_t*)&m_verts[m_info.numXYZ*j]; for(i=0;i<m_info.numXYZ;i++) {    pVerts.x = scale*(frame->scale[0]*frame->fp.v[0]+frame->translate[0]);    pVerts.x = scale*(frame->scale[1]*frame->fp.v[1]+frame->translate[1]);    pVerts.x = scale*(frame->scale[2]*frame->fp.v[2]+frame->translate[2]);   if(j==0)    {  if(pVerts.y<m_miny)    m_miny = pVerts.y;  if(pVerts.y > maxy)  maxy = pVerts.y;    } }}CalculateBoundingSphere(m_boundingSphere,m_miny,maxy);//Move(0,0,0);m_tris = new mesh_t[m_info.numTris];fseek(pFile,m_info.offsetTris,SEEK_SET);fread(m_tris,m_info.numTris,sizeof(mesh_t),pFile);stIndex_t *stTemp = new stIndex_t[m_info.numST];m_texCoords = new texCoord_t[m_info.numTris*3];fseek(pFile,m_info.offsetST,SEEK_SET);fread(stTemp,m_info.numST,sizeof(stIndex_t),pFile);int index =0;for(i=0;i<m_info.numTris;i++){  m_texCoords[index].s = (float)stTemp[m_tris.stIndex[0]].s / m_info.skinwidth;  m_texCoords[index++].t = 1.0f - (float)stTemp[m_tris.stIndex[0]].t / m_info.skinheight;  m_texCoords[index].s = (float)stTemp[m_tris.stIndex[1]].s / m_info.skinwidth;  m_texCoords[index++].t = 1.0f -(float)stTemp[m_tris.stIndex[1]].t / m_info.skinheight;  m_texCoords[index].s = (float)stTemp[m_tris.stIndex[2]].s / m_info.skinwidth;  m_texCoords[index++].t = 1.0f - (float)stTemp[m_tris.stIndex[2]].s / m_info.skinheight;}m_currentVerts = new xyz_t[m_info.numTris * 3];//close file and free memfclose(pFile);delete[]buffer;CTargaImage image;image.Load(skinFile);glGenTextures(1,&m_texID);glBindTexture(GL_TEXTURE_2D,m_texID);gluBuild2DMipmaps(GL_TEXTURE_2D,3,image.GetWidth(),image.GetHeight(),GL_RGB,GL_UNSIGNED_BYTE,image.GetImage());image.Release();m_currentFrame = 0;m_nextFrame = 1;m_interpol = 0.0;//animate least  1 frame to make sure m_currentVerts get initedSetAnimation(IDLE,IDLE);Animate(0);return true;}/////////////////////////////////////////////////////////As can be seen this Load function loads the MD2 and skinfile where the skinfile is Targa and binds the texture to it? and builds a mipmapNow here is the DrawCreatures function//////////////////////////////////////////////////////////////void CGfxOpenGL::DrawCreatures(){//iterate through all the creatures checking to see if the creatures bounding sphere//intersects the view volume when frustum culling is enabledfor(int i=0;i<NUM_CREATURES;++i){   m_rhinoModel.Rotate(m_rhinos[3]);   m_rhinoModel.Move(m_rhinos[0],m_rhinos[1],m_rhinos[2]);   if(!m_useCulling || SphereInFrustum(m_rhinoModel.GetBoundingSphere(),m_frustum))   {m_rhinoModel.Render();   }   m_centaurModel.Rotate(m_centaurs[3]);   m_centaurModel.Move(m_centaurs[0],m_centaurs[1],m_centaurs[2]);   if(!m_useCulling || SphereInFrustum(m_centaurModel.GetBoundingSphere(),m_frustum))   {m_centaurModel.Render();   }   m_demonModel.Rotate(m_demons[3]);   m_demonModel.Move(m_demons[0],m_demons[1],m_demons[2]);   if(!m_useCulling || SphereInFrustum(m_demonModel.GetBoundingSphere(),m_frustum))   {m_demonModel.Render();   }}}//////////////////////////////////////////////////////////////////////As can be seen this uses a bounding sphere and if in it draws the model (supposed to??)My render function is as follows////////////////////////////////////////////////////////////////void CGfxOpenGL::Render(){glClearColor(0.7f,0.7f,0.9f,1.0);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//setup viewglLoadIdentity();//xyz_t eye = {0,0,0};//i defined globallyeye.y = GetHeightAt(eye.x,eye.z)+EYE_HEIGHT+100;gluLookAt(eye.x,eye.y,eye.z,0.0,eye.y,-1.0,0.0,1.0,0.0);glRotatef(m_angle,0,1,0);//determine the frustum for cullingCalculateFrustum();//draw the worldm_skybox.Render(eye.x,eye.y,eye.z);DrawTerrain();DrawCreatures();}/////////////////////////////////////////////////////////////As you can imagine I have spent days on this to get it working in DEV-C++; I have searched the internet for an answer but have found lots of information and code but it still baffles me can anyone help or even suggest a way of debugging it in order to narrow down what might be wrong.What else is included in this projectwinmain.cppCGfxOpenGL.cpp/.hCtarga.h/.cppGlee.h/.cMD2.h/.cppskybox.cpp/.htimer.hThe problem might be in my MD2 files or in the code given above how can I narrow this down.Many ThanksMichael2006you may ask why didnt I just copy and paste the files and run it well tried that and got errors. Different compiler??
if(m_centaurModel.Load("centaur//tris.md2","centaur//centaur.tga",0.1)==false)//exit(0);if(m_demonModel.Load("nemocromicus//tris.md2","necromicus//necromicus.tga",0.1)==false)//exit(0);for(int i=0;i<NUM_CREATURES;++i)I don't know, that seems like a logical error. This is what I think the compiler is interpreting it as:if(m_centaurModel.Load("centaur//tris.md2","centaur//centaur.tga",0.1)==false)   if(m_demonModel.Load("nemocromicus//tris.md2","necromicus//necromicus.tga",0.1)==false) for(int i=0;i<NUM_CREATURES;++i) {    // all the code here }In other words, it's doing the for loop stuff only if the first and second conditional statements evaluate to true. My advice is uncomment the exit(0) calls after each, or comment both if statements completely.I don't know, just a thought.   ;  Hithe reason for the if(........)exit(0);was to ensure the files were being loaded and if so continue else exit my application and when they are uncommented the application exits. Which means that there is a problem with the loading function but I cant see anything wrong!   ;  Is there any reason you're separating your paths with double forward slashes?  That could be why the files don't load.  Try using single forward slashes or double backslashes.   ;  HiI have tried using backslashes forward slashes and doubles but no joy.I have <cstdio> included and have changed the definition for bool CMD2Model::Load(char *modelFile,char *skinFile,GLfloat scale) to bool CMD2Model::Load(const char *modelFile,const char *skinFile,GLfloat scale)but still no joy.Can anyone help??   ;  I have ported some of the functionality to linux because I have a better tool set there and when I comment out this linegluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB,image.GetWidth(),image.GetHeight(),GL_RGB,GL_UNSIGNED_BYTE,image.GetImage());of the bool CMD2Model::Load(const char *modelFile,const char *skinFile,GLfloat scale)function I get a display of terrain and skybox but if I leave it in I get a segmentation fault reported by gdb.I do a backtrace and it basically reports the glubuild2DMipmaps as suspicious.now I have tried changing the parameters of this function for 64,32,16,8 etc but nothing works still a fault.In Linux under properties for this skinfile there is information like for Meta Infodimensions 432*142 pixels24bppRGBRunlength encodedwould this cause the fault??should the image be smaller ie 64x64 or 32x32 etc