Archived

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

Kris2456

Heightfield terrain problem

Recommended Posts

Kris2456    100
Hello, i am trying to get NeHes terrain engine to work. But i am having problems. Hereis my code:
#define MAP_SIZE 1024
#define STEP_SIZE 16
#define HEIGHT_RATIO 1.5f
BYTE g_HeightMap[MAP_SIZE*MAP_SIZE];
float scaleValue = 0.15f;

//.RAW texture loading

//**************************/

//THIS IS LINE 18

//**************************/

void LoadRawFile(LPSTR strName, int nSize, BYTE *pHeightMap)
{
    FILE *pFile = NULL;
    pFile = fopen( strName, "rb" );
    
    //Check to see if file was found

    if(pFile== NULL)
    {
        MessageBox(NULL, "Could not open .RAW file!", "Error", MB_OK);
        return;
    }
    
    //Read data in

    fread(pHeightMap,1,nSize,pFile);
    
    //Check for errors while reading

    int result = ferror( pFile );
    if(result)
    {
        MessageBox(NULL, "Error reading .RAW file!", "Error", MB_OK);
    }
    
    //Close the file

    fclose(pFile);
}


//Load .Raw file for Terrain

//**************************/

//THIS IS LINE 45

//**************************/

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



//Height finding

int Height(BYTE *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)];
}


//Vertex color calculations

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

	float fColor = -0.15f + (Height(pHeightMap, x, y ) / 256.0f);

	glColor3f(0.0f, fColor, 0.0f );
}


//HEIGHTMAP RENDERING FUNCTION

void RenderHeightMap(BYTE pHeightMap[])	
{
    int X=0;
    int Y=0;
    int x, y, z;
    //If there is no data return

    if(!pHeightMap) return;
    
    //Beign drawing the quads for the heightmap

    glBegin(GL_QUADS);
    
    //For loops

    for ( X = 0; X < (MAP_SIZE-STEP_SIZE); X += STEP_SIZE )
		for ( Y = 0; Y < (MAP_SIZE-STEP_SIZE); Y += STEP_SIZE )
		{
			// Get The (X, Y, Z) Value For The Bottom Left Vertex

			x = X;							
			y = Height(pHeightMap, X, Y );	
			z = Y;							

			// Set The Color Value Of The Current Vertex

			SetVertexColor(pHeightMap, x, z);

			glVertex3i(x, y, z);			// Send This Vertex To OpenGL To Be Rendered


			// Get The (X, Y, Z) Value For The Top Left Vertex

			x = X;										
			y = Height(pHeightMap, X, Y + STEP_SIZE );  
			z = Y + STEP_SIZE ;							
			
			// Set The Color Value Of The Current Vertex

			SetVertexColor(pHeightMap, x, z);

			glVertex3i(x, y, z);			// Send This Vertex To OpenGL To Be Rendered


			// Get The (X, Y, Z) Value For The Top Right Vertex

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

			// Set The Color Value Of The Current Vertex

			SetVertexColor(pHeightMap, x, z);
			
			glVertex3i(x, y, z);			// Send This Vertex To OpenGL To Be Rendered


			// Get The (X, Y, Z) Value For The Bottom Right Vertex

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

			// Set The Color Value Of The Current Vertex

			SetVertexColor(pHeightMap, x, z);

			glVertex3i(x, y, z);
		}
		//End

		glEnd();
		//Set color to white, so other stuff dosnt go bright blue, etc.

		glColor4f(1,1,1,1);
}
It gives me these errors: 18 previous declaration of `void LoadRawFile(CHAR*, int, BYTE*)'' 45 initializer list being treated as compound expression 45 invalid conversion from `BYTE*'' to `int'' thx for any help in advance ---------- "Here lies a toppled God, His fall was not a small one, We but built his pedastle, A narrow, and a tall one" Frank Herbert (Dune:Messiah)

Share this post


Link to post
Share on other sites
Chupacabra    122
Line 45 is a function call to LoadRawFile and it''s placed between 2 functions, seems like that isn''t legal to do. I think the compiler treats the line 45 as a function prototype for the actual function and those doesn''t match. (I never tried this, so I''m not sure)

Try calling it from another function, for example where you set up Open GL or your main function.

Share this post


Link to post
Share on other sites