Texturing height map problems

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

i am doing texturing for my height maps and well i did it so it would take the height and depending on the height give it a different texture so if its less then 150 then grass over than then rock.

I do if statements to draw the specific things so if its <150 then heighttex = 2; which means its gass and if its >150 then heighttex = 3; which means rock. so i do that and then i draw in the if statement.

Then in my drawglscene i have the glbindtexture with heighttex in there and then renderheightmap so it draws.

the problems is that its only Texturing what the 1st heighttex says so it would be 2, it isnt switching from textures.
Here is my Code:


PHP Code:
#define         MAP_SIZE       1024
#define         STEP_SIZE         16                             
#define         HEIGHT_RATIO    0.5f  

quad mapquad [MAP_SIZE*MAP_SIZE];
int heighttex;
int n =0;


void RenderHeightMap(GLubyte pHeightMap[])                    
{

    
int X 00;                                int xyz;            // Create Some Variables For Readability

    
if(!pHeightMap) return;        // Make Sure Our Height Data Is Valid
        
if(bRender)                // What We Want To Render
        
glBeginGL_QUADS );                                else 
        
glBeginGL_LINES );                                                                             
    for ( 
0< (MAP_SIZE-STEP_SIZE); += STEP_SIZE )
            for ( 
0< (MAP_SIZE-STEP_SIZE); += STEP_SIZE )
        {
            
                   
                         
// Get The (X, Y, Z) Value For The Bottom Left Vertex
            
mapquad[n].x1 X;                                    mapquad[n].y1 Height(pHeightMapX);    
            
mapquad[n].z1 Y;                                    
                        
// Get The (X, Y, Z) Value For The Top Left Vertex
            
mapquad[n].x2 X;                                    mapquad[n].y2 Height(pHeightMapXSTEP_SIZE );  
            
mapquad[n].z2 STEP_SIZE ;                                                                                                            
            
// Get The (X, Y, Z) Value For The Top Right Vertex
            
mapquad[n].x3 STEP_SIZE
            
mapquad[n].y3 Height(pHeightMapSTEP_SIZESTEP_SIZE ); 
            
mapquad[n].z3 STEP_SIZE ;
                    

            
mapquad[n].x4 STEP_SIZE
            
mapquad[n].y4 Height(pHeightMapSTEP_SIZE); 
            
mapquad[n].z4 Y;
                        
                        
                         if (
mapquad[n].y1 140 && mapquad[n].y2 140 && 
                         
mapquad[n].y3 >140 &&     mapquad[n].y4 140 )
                {
                        
heighttex 2;

                   
                     

                        
glTexCoord2f(0.00.0);
                        
glVertex3i(mapquad[n].x1mapquad[n].y1mapquad[n].z1);
                        
                        
glTexCoord2f(0.01.0);
                        
glVertex3i(mapquad[n].x2mapquad[n].y2mapquad[n].z2);    
                      
                          
glTexCoord2f(1.01.0);
                        
glVertex3i(mapquad[n].x3mapquad[n].y3mapquad[n].z3);    
                      
                        
glTexCoord2f(1.00.0);
                        
glVertex3i(mapquad[n].x4mapquad[n].y4mapquad[n].z4);
            
                }
                   
     
                                                
      if (
mapquad[n].y1 141 && mapquad[n].y2141 && mapquad[n].y3141 &&         mapquad[n].y4141 )
            {
                
heighttex 3;

                 
                            
                         
glTexCoord2f(0.00.0);
                        
glVertex3i(mapquad[n].x1mapquad[n].y1mapquad[n].z1);
                        
                        
glTexCoord2f(0.01.0);
                        
glVertex3i(mapquad[n].x2mapquad[n].y2mapquad[n].z2);    
                      
                          
glTexCoord2f(1.01.0);
                        
glVertex3i(mapquad[n].x3mapquad[n].y3mapquad[n].z3);    
                      
                        
glTexCoord2f(1.00.0);
                        
glVertex3i(mapquad[n].x4mapquad[n].y4mapquad[n].z4);

            }
           
                   
                                                                    
        }
                        


              
glEnd();
              
n++;     

}


IN THE DRAWGLSCENE I HAVE:

    
glEnable(GL_TEXTURE_2D);
    
glBindTexture(GL_TEXTURE_2DtexName[heighttex]);
 

        
glTranslatef(0.0f, -300.0f0.0f);
        
glScalef(1*21*21*2);


      
    
RenderHeightMap(g_HeightMap);    

       
 
glDisable(GL_TEXTURE_2D); 



So please someone help me out. THanks, Nahid
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #2
Could you please stick that in proper code or php tags so there is formatting? (Go back an edit your post)

I bet you'd get better help.
-Jon
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #3
Ok i fixed, sorry about that i didnt know
thanks aarku
Quote this message in a reply
Member
Posts: 153
Joined: 2004.12
Post: #4
You need to bind the textures inside the if statements. It looks like your binding one texture before you draw your entire height map.

so after you assign heighttex, do glBindTexture(GL_TEXTURE_2D, heighttex);

There was a long silence...
'I claim them all,' said the Savage at last.
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #5
Nahid, if you still need help you should probably post your updated code, otherwise you will get more comments about things that are fixed already Wink
Quote this message in a reply
Member
Posts: 36
Joined: 2004.10
Post: #6
Its ok i fixed that problem, thanks anyways you guys.
Quote this message in a reply
Member
Posts: 153
Joined: 2004.12
Post: #7
You should post the fix in that case.

There was a long silence...
'I claim them all,' said the Savage at last.
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,238 Jan 4, 2010 05:36 AM
Last Post: mikey
  Height Map Loader, problem nahid 25 8,246 Oct 12, 2005 07:52 AM
Last Post: nahid
  Trouble Calculating Height Field Normals Nick 15 6,170 Jul 21, 2005 07:27 AM
Last Post: Nick