iDevGames Forums
Height Map Loader, problem - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Height Map Loader, problem (/thread-4930.html)

Pages: 1 2


Height Map Loader, problem - nahid - Oct 9, 2005 10:47 AM

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


Height Map Loader, problem - AnotherJake - Oct 9, 2005 01:39 PM

Change GLbyte to GLubyte.


Height Map Loader, problem - nahid - Oct 9, 2005 02:08 PM

AnotherJake,

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

Thanks


Height Map Loader, problem - nahid - Oct 9, 2005 02:23 PM

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


Height Map Loader, problem - socksy - Oct 9, 2005 02:28 PM

Have a look at this tutorial: http://gpwiki.org/index.php/OpenGL_3D_Textures


Height Map Loader, problem - nahid - Oct 10, 2005 08:31 AM

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


Height Map Loader, problem - nahid - Oct 10, 2005 04:34 PM

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


Height Map Loader, problem - Zwilnik - Oct 10, 2005 05:12 PM

3D Textures don't work on older cards such as the GForce 4 etc. so they're not necessarily a great way to go


Height Map Loader, problem - nahid - Oct 10, 2005 05:15 PM

Oh thats bad, so how else can i texture my terrain different textures?

please some one lead me the righ way
thansk


Height Map Loader, problem - OneSadCookie - Oct 10, 2005 05:46 PM

you could try using (*gasp*) different textures for different parts of the terrain!


Height Map Loader, problem - nahid - Oct 10, 2005 05:49 PM

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.


Height Map Loader, problem - aarku - Oct 10, 2005 05:53 PM

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.


Height Map Loader, problem - OneSadCookie - Oct 10, 2005 05:56 PM

um, I don't think that'll work, aarku.

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


Height Map Loader, problem - aarku - Oct 10, 2005 05:58 PM

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


Height Map Loader, problem - Zwilnik - Oct 10, 2005 06:07 PM

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.