Results 1 to 2 of 2

Thread: Help me please - heigh map problem

  1. #1
    Member Contributor
    Join Date
    Dec 2001
    Location
    Porto Velho
    Posts
    97

    Help me please - heigh map problem

    Im trying to load a height map and put everything in a matrix... but its not working, nothing its drawn.

    Code :
    GLfloat vertices_x[6][MAP_SIZE*MAP_SIZE];
    GLfloat vertices_y[6][MAP_SIZE*MAP_SIZE];
    GLfloat vertices_z[6][MAP_SIZE*MAP_SIZE];
     
    GLfloat Height(BYTE *pHeightMap, int X, int Y)  //WORKS FINE
    {
    	int x = X % MAP_SIZE;
    	int y = Y % MAP_SIZE;
    	if(!pHeightMap) return 0;
    	return pHeightMap[x + (y * MAP_SIZE)];
    }
     
    void LoadRawFile(LPSTR strName, int nSize, BYTE *pHeightMap) //WORKS FINE
    {
    	FILE *pFile = NULL;
    	pFile = fopen( strName, "rb" );
    	if ( pFile == NULL )
    	{
    		MessageBox(NULL, "Mapa nao encontrado.", "Erro", MB_OK);
    		return;
    	}
    	fread( pHeightMap, 1, nSize, pFile );
    	int result = ferror( pFile );
    	if (result)
    	{
    		MessageBox(NULL, "Erro ao carregar Mapa de terreno.", "Erro", MB_OK);
    	}
    	fclose(pFile);
    }
     
     
    void buildVertex(BYTE pHeightMap[],GLint STEP_SIZE,int QUAD_ID) //POSSIBLE PROBLEM
    {
    	int X=0,Y=0;
    	int looper;
    	if(!pHeightMap) return;
    	for ( X = 0; X < MAP_SIZE; X += STEP_SIZE ) {
    		for ( Y = 0; Y < MAP_SIZE; Y += STEP_SIZE )
    		{
    			vertices_x[0][looper]=X;
    			vertices_y[0][looper]=Height(pHeightMap, X, Y )*ELEVATION;
    			vertices_z[0][looper]=Y;
     
    			vertices_x[1][looper]=X;
    			vertices_y[1][looper]=Height(pHeightMap, X, Y + STEP_SIZE)*ELEVATION;
    			vertices_z[1][looper]=Y + STEP_SIZE;
     
    			vertices_x[2][looper]=X + STEP_SIZE;
    			vertices_y[2][looper]=Height(pHeightMap, X + STEP_SIZE, Y+ STEP_SIZE) *ELEVATION;
    			vertices_z[2][looper]=Y + STEP_SIZE;
     
    			vertices_x[3][looper]=X + STEP_SIZE;
    			vertices_y[3][looper]=Height(pHeightMap, X + STEP_SIZE, Y )*ELEVATION;
    			vertices_z[3][looper]=Y;
     
    			vertices_x[4][looper]=X;
    			vertices_y[4][looper]=Height(pHeightMap, X, Y )*ELEVATION;
    			vertices_z[4][looper]=Y;
     
    			vertices_x[5][looper]=X + STEP_SIZE;
    			vertices_y[5][looper]=Height(pHeightMap, X + STEP_SIZE, Y + STEP_SIZE) *ELEVATION;
    			vertices_z[5][looper]=Y + STEP_SIZE;
     
    			looper++;
    		}
    	}
    } 
     
    void drawQuad(int QUAD_ID,int TEX_ID,int AUTO_GEN,int START_POSIx,int START_POSIz)  //POSSIBLE PROBLEM
    {
    	glPushMatrix();
    		glBindTexture(GL_TEXTURE_2D, texture[3]);
    		glBegin(GL_TRIANGLES);
    			int i;
    			for(i=0;i<=MAP_SIZE*MAP_SIZE;i++) {
    				glTexCoord2f(0,0); glVertex3f(vertices_x[0][i],vertices_y[0][i],vertices_z[0][i]);
    				glTexCoord2f(1,0); glVertex3f(vertices_x[1][i],vertices_y[1][i],vertices_z[1][i]);
    				glTexCoord2f(1,1); glVertex3f(vertices_x[2][i],vertices_y[2][i],vertices_z[2][i]);
    				glTexCoord2f(0,1); glVertex3f(vertices_x[3][i],vertices_y[3][i],vertices_z[3][i]);
    				glTexCoord2f(0,0); glVertex3f(vertices_x[4][i],vertices_y[4][i],vertices_z[4][i]);
    				glTexCoord2f(1,1); glVertex3f(vertices_x[5][i],vertices_y[5][i],vertices_z[5][i]);
    			}
    		glEnd();
       glPopMatrix();
    }
     
    void loadQuad(LPSTR strName,int QUAD_ID) //POSSIBLE PROBLEM
    {
    	LoadRawFile(strName, MAP_SIZE * MAP_SIZE, g_HeightMap);
    	buildVertex(g_HeightMap,15,QUAD_ID);
    }

  2. #2
    Member Contributor
    Join Date
    May 2001
    Posts
    54

    Re: Help me please - heigh map problem

    Couple of things you could check...

    Winding...glFrontFace(GL_CW) or (GL_CCW);
    Culling...glCullFace(GL_FRONT) or GL_BACK
    call glGetError check if it is 0.


Similar Threads

  1. Replies: 1
    Last Post: 09-23-2016, 02:24 PM
  2. Shading problem? (pyglet-problem?, my problem?)
    By H2OBrain in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-03-2009, 08:31 AM
  3. Replies: 4
    Last Post: 09-27-2004, 06:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean