Archived

This topic is now archived and is closed to further replies.

_Titan_

Nothing shows up!

Recommended Posts

You had it working the other day, so what have you changed? That would be the first place I would look...

Edit: Ok, I looked at your code, and I'll take a guess. You're setting your far view plane to 100, and it looks like your map can be up to 1024 units. I'd try setting your view planes further out, instead of this:
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

Maybe try this:
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1500.0f);

[edited by - yakuza on June 7, 2002 1:53:04 PM]

Share this post


Link to post
Share on other sites
I had problems with your LoadMap function. I modified it, and here is the new version:


  
int ReadMap() {

GLfloat tmpX,tmpZ;

ifstream InFile;
InFile.open("./map.txt");

GLfloat x;

InFile>>MAP_WIDTH;
InFile>>MAP_HEIGHT;
InFile>>START_X;
InFile>>START_Y;

//tX = START_X;

//tZ = START_Y;


tmpX=0;
tmpZ=0;

for(int z=0;z<MAP_HEIGHT;z++) {
for(int i=0;i<MAP_WIDTH;i++) {
InFile>>x;
MapCoord[i][z].x = (GLfloat)i;
MapCoord[i][z].y = x / 64;
MapCoord[i][z].z = (GLfloat)z;
tmpX+=0.5;
}
tmpZ+=0.5;
}
InFile.close();

return true;
}



I also moved the glBegin() and glEnd() out of the for loop (a bit more efficient)

Finally, the only translations/rotations used are:

  
glRotatef(Degree, 0.0f, 1.0f, 0.0f);
glTranslatef(tX,tY,tZ);

These were placed straight after the LoadIdentity(), and all other translations removed.

The result is far from perfect, but the terrain appears. You'll still need to get rid of the strange mess of polys meeting at (0,0,0).

Hope this helps.

[edited by - sibbo2001 on June 7, 2002 3:05:06 PM]

Share this post


Link to post
Share on other sites
I appriciate the new readmap function, i just changed my map file format this morning and it was still working with my old fucntion so i did not change it yet.

Anyways, I made the changes you suggested, and i still see nothing. Did you have to move left/rigth up/down? I know in my last code i had to move a little to the left before i saw anything.

I tried to change my method to reading the info from a raw file, liek in the tutorials yakuza gave me. I coudlnt get that to work, i kept getting memory errors, so i just modified my method and now i cant seem to get ti working. I did not change anything, i deleted the raw file mthod code and un commented my old code. The only major change i made was the way the map file was written. It still read the same and should have been displayed the same. But somethign went wrong.

So any other suggestions? I will re-upload my code with the changes. Maybe i forgot something?

Really appriciate your help.

Share this post


Link to post
Share on other sites
Sorry it took so long, I''ve been real busy with exams, but I think I''ve finally spotted the main problem.

Basically, your map file doesn''t seem to be as big as it says it is. In the file it claims to be 256 x 256, but the end of the file is reached before this.

Try adding this to your ReadMap function:

  
for(int z=0;z<MAP_HEIGHT;z++) {
for(int i=0;i<MAP_WIDTH;i++) {

// This is the added bit

// Checks to see if the end of the file has been reached.

// If it has, stops reading.

if (InFile.eof())
{
MAP_HEIGHT = z - 1;
MAP_WIDTH = i - 1;
break;
}
// End of the added bit

InFile>>x;
MapCoord[i][z].x = (GLfloat)i;
MapCoord[i][z].y = x / 64;
MapCoord[i][z].z = (GLfloat)z;
tmpX+=0.5;
}
tmpZ+=0.5;
}



It sorts out the mess of polygons meeting near the origin at least.

Also, you should use this drawing code for correct texture coords (looks much nicer )

  
SetTextureCoord( (float)x, (float)y ); glVertex3f(MapCoord[x][y].x,MapCoord[x][y].y,MapCoord[x][y].z); // Top Right


SetTextureCoord( (float)x, (float)y+1 ); glVertex3f(MapCoord[x][y+1].x,MapCoord[x][y+1].y,MapCoord[x][y+1].z); // Top Left


SetTextureCoord( (float)x+1, (float)y ); glVertex3f(MapCoord[x+1][y].x,MapCoord[x+1][y].y,MapCoord[x+1][y].z); // Bottom Right


SetTextureCoord( (float)x+1, (float)y+1 ); glVertex3f(MapCoord[x+1][y+1].x,MapCoord[x+1][y+1].y,MapCoord[x+1][y+1].z); // Bottom Left

Share this post


Link to post
Share on other sites