## 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 = 0, Y = 0;                                int x, y, z;            // Create Some Variables For Readability    if(!pHeightMap) return;        // Make Sure Our Height Data Is Valid        if(bRender)                // What We Want To Render        glBegin( GL_QUADS );                                else         glBegin( GL_LINES );                                                                                 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            mapquad[n].x1 = X;                                    mapquad[n].y1 = Height(pHeightMap, X, Y );                mapquad[n].z1 = Y;                                                            // Get The (X, Y, Z) Value For The Top Left Vertex            mapquad[n].x2 = X;                                    mapquad[n].y2 = Height(pHeightMap, X, Y + STEP_SIZE );              mapquad[n].z2 = Y + STEP_SIZE ;                                                                                                                        // Get The (X, Y, Z) Value For The Top Right Vertex            mapquad[n].x3 = X + STEP_SIZE;             mapquad[n].y3 = Height(pHeightMap, X + STEP_SIZE, Y + STEP_SIZE );             mapquad[n].z3 = Y + STEP_SIZE ;                                mapquad[n].x4 = X + STEP_SIZE;             mapquad[n].y4 = Height(pHeightMap, X + STEP_SIZE, Y );             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.0, 0.0);                        glVertex3i(mapquad[n].x1, mapquad[n].y1, mapquad[n].z1);                                                glTexCoord2f(0.0, 1.0);                        glVertex3i(mapquad[n].x2, mapquad[n].y2, mapquad[n].z2);                                                    glTexCoord2f(1.0, 1.0);                        glVertex3i(mapquad[n].x3, mapquad[n].y3, mapquad[n].z3);                                                  glTexCoord2f(1.0, 0.0);                        glVertex3i(mapquad[n].x4, mapquad[n].y4, mapquad[n].z4);                            }                                                                              if (mapquad[n].y1 < 141 && mapquad[n].y2< 141 && mapquad[n].y3< 141 &&         mapquad[n].y4< 141 )            {                heighttex = 3;                                                                      glTexCoord2f(0.0, 0.0);                        glVertex3i(mapquad[n].x1, mapquad[n].y1, mapquad[n].z1);                                                glTexCoord2f(0.0, 1.0);                        glVertex3i(mapquad[n].x2, mapquad[n].y2, mapquad[n].z2);                                                    glTexCoord2f(1.0, 1.0);                        glVertex3i(mapquad[n].x3, mapquad[n].y3, mapquad[n].z3);                                                  glTexCoord2f(1.0, 0.0);                        glVertex3i(mapquad[n].x4, mapquad[n].y4, mapquad[n].z4);            }                                                                                                          }                                      glEnd();              n++;     }IN THE DRAWGLSCENE I HAVE:    glEnable(GL_TEXTURE_2D);    glBindTexture(GL_TEXTURE_2D, texName[heighttex]);         glTranslatef(0.0f, -300.0f, 0.0f);        glScalef(1*2, 1*2, 1*2);          RenderHeightMap(g_HeightMap);            glDisable(GL_TEXTURE_2D); `

So please someone help me out. THanks, Nahid
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
Member
Posts: 36
Joined: 2004.10
Post: #3
Ok i fixed, sorry about that i didnt know
thanks aarku
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.
Moderator
Posts: 767
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
Member
Posts: 36
Joined: 2004.10
Post: #6
Its ok i fixed that problem, thanks anyways you guys.
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.