Height Map Loader, problem

Member
Posts: 36
Joined: 2004.10
Post: #1
Hello,

I made a height map loader using the NEHE tutorial and when i load there tutorial the height map is all connected meaning that its 1 WHOLE mountain, but whne i load mine i always get 4 different parts which should be attached, so instead of 1 whole mountain i have 4 different parts to it.

here is my code:

#define MAP_SIZE 1024
#define STEP_SIZE 16
#define HEIGHT_RATIO 1.5f

static bool bRender = TRUE;
static GLbyte g_HeightMap[MAP_SIZE*MAP_SIZE];
static float scaleValue = 0.15f;



// HEIGHT MAP LOADER


void LoadRawFile(char *strName, int nSize, GLbyte *pHeightMap)
{

FILE *pFile = NULL;

pFile = fopen( strName, "rb" );
fread( pHeightMap, 1, nSize, pFile );
fclose(pFile);
}



int Height(GLbyte *pHeightMap, int X, int Y)
{
int x = X % MAP_SIZE;
int y = Y % MAP_SIZE;

if(!pHeightMap) return 0;

return pHeightMap[x + (y * MAP_SIZE)];
}

void SetVertexColor(GLbyte *pHeightMap, int x, int y)
{
if(!pHeightMap)
return;

else
{
float fColor = -0.15f + (Height(pHeightMap, x, y ) / 256.0f);
glColor3f(fColor, 0, 0 );
}
}

void RenderHeightMap(GLbyte pHeightMap[])
{

int X = 0, Y = 0;
int x, y, z;

if(!pHeightMap) return;

if(bRender) // What We Want To Render
glBegin( GL_QUADS ); // Render Polygons
else
glBegin( GL_LINES ); // Render Lines Instead


// for ( X = 0; X < (MAP_SIZE-STEP_SIZE); X += STEP_SIZE )
// for ( Y = 0; Y < (MAP_SIZE-STEP_SIZE); Y += STEP_SIZE )
for ( X = 0; X < MAP_SIZE; X += STEP_SIZE )
for ( Y = 0; Y < MAP_SIZE; Y += STEP_SIZE )
{
x = X;
y = Height(pHeightMap, X, Y );
z = Y;

SetVertexColor(pHeightMap, x, z);
glVertex3i(x, y, z);
x = X;
y = Height(pHeightMap, X, Y + STEP_SIZE );
z = Y + STEP_SIZE ;

SetVertexColor(pHeightMap, x, z);
glVertex3i(x, y, z);
x = X + STEP_SIZE;
y = Height(pHeightMap, X + STEP_SIZE, Y + STEP_SIZE );
z = Y + STEP_SIZE ;

SetVertexColor(pHeightMap, x, z);
glVertex3i(x, y, z);
x = X + STEP_SIZE;
y = Height(pHeightMap, X + STEP_SIZE, Y );
z = Y;

SetVertexColor(pHeightMap, x, z);

glVertex3i(x, y, z);


}
glEnd();

glColor4f(1.0f, 1.0f, 1.0f, 1.0f);


}



// END HEIGHT MAP LOADER




THEN in the drawglscene I HAVE:

glScalef(scaleValue, scaleValue * HEIGHT_RATIO, scaleValue);
RenderHeightMap(g_HeightMap);



and i Load the .RAW file in like this:

LoadRawFile("Data/Terrain.raw", MAP_SIZE*MAP_SIZE , g_HeightMap);


So instead of getting 1 mountain i get 4 different parts, so please someone please help me.

thanks
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #2
Change GLbyte to GLubyte.
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #3
AnotherJake,

THANK YOU SO MUCH, i cant believe i didnt realize that. It works perfectly now.

Thanks
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #4
Hello, i have another question

well i got my height map loaded now i would like to make some parts of the map different textures.

How would i go about doing this?

please help me
thanks
Quote this message in a reply
Member
Posts: 168
Joined: 2004.10
Post: #5
Have a look at this tutorial: http://gpwiki.org/index.php/OpenGL_3D_Textures
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #6
Hey nice tutorial.

So are they saying that its like this diagram:

A texture 1
B texture 2
C texture 3

then say I need texture 2 i would call somehow variable B and thats what i would get?

And from my understanding i could think this as stacked each on top of each other and i just call which one i want?

So i get what this is doing and it is a very good way to do this, but is there a Mac tutorial for this because i cant use this tutorial for my work because there are different commands.

thanks
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #7
PLease someone help me. Is there any other way to do this? and if i do it the 3d texture way, the tutorial says that there is no glTexImage3d how would i get that because the way they got it doesnt work when i try it.

thanks
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #8
3D Textures don't work on older cards such as the GForce 4 etc. so they're not necessarily a great way to go
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #9
Oh thats bad, so how else can i texture my terrain different textures?

please some one lead me the righ way
thansk
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #10
you could try using (*gasp*) different textures for different parts of the terrain!
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #11
well its a height map i can only texture it as 1 and the whole terrain will be that one texture, i dont know how i will break it up into peices.
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #12
Have two texture maps. One is for height, one is for texture index. So each color on the texture index map corresponds to a specific texture map.

Then when you find the height of a particular vertex, find the texture of it too. Then set it, then draw it.

Don't ask me about specific implementation details. I won't be able to answer. At some point you'll need to take that step.

I would wager something like GL Golf does this. It was a uDG entry, so the source should be somewhere.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #13
um, I don't think that'll work, aarku.

nahid: draw your terrain in several different parts, each with a different texture.
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #14
OneSadCookie Wrote:um, I don't think that'll work, aarku.

nahid: draw your terrain in several different parts, each with a different texture.

Why not?

Find the texture, set the texture, draw a polygon at the right coordinates, repeat.

-Jon
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #15
Jon's method would work, but would be slower than drawing the terrain in several parts (especially if each part was pre-compiled), but that would assume that the terrain isn't going to be modified.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Finding the height of a point on a given list of vertexes? mikey 10 5,389 Jan 4, 2010 05:36 AM
Last Post: mikey
  Texturing height map problems nahid 6 4,287 Oct 14, 2005 10:24 PM
Last Post: hangt5
  Trouble Calculating Height Field Normals Nick 15 6,257 Jul 21, 2005 07:27 AM
Last Post: Nick