Advertisement

Multitexture with Vertex Arraeys

Started by July 22, 2003 10:04 AM
1 comment, last by Missing Name 21 years, 7 months ago
Hello, I''m working on a terrain engine at the moment, and I want to add a detail texture. I''m drawing it with vertex arrays at the moment. But I haven''t been able to find any real info about how to use multitexture WITH vertex arrays. I kind of had to guess at the syntax, and here''s what I have so far.

	glEnable (GL_VERTEX_ARRAY);
	glEnable (GL_TEXTURE_COORD_ARRAY);
	glDisable (GL_COLOR_ARRAY);
      glDisable (GL_NORMAL_ARRAY);

      if (IsMultitexSupported())
      {

            glColor4f (1, 1, 1, 1);

            //if we gots any points

            if (m_hMapArray[0].numPoints > 0)
            {
      	      glActiveTextureARB(GL_TEXTURE0_ARB);
      	      glEnable(GL_TEXTURE_2D);
                  bind_texture (1, 0);

                  //draw with vertex arrays

      	      glActiveTextureARB(GL_TEXTURE1_ARB);
      	      glEnable(GL_TEXTURE_2D);
                  bind_texture (m_detailTex.party, m_detailTex.tex);

                  glEnable (GL_VERTEX_ARRAY);
      	      glEnable (GL_TEXTURE_COORD_ARRAY);

                  glClientActiveTextureARB(GL_TEXTURE0_ARB);
                  glVertexPointer   (3, GL_FLOAT, 0, m_hMapArray[0].vertex);
                  glTexCoordPointer (2, GL_FLOAT, 0, m_hMapArray[0].texCoord);

                  glClientActiveTextureARB(GL_TEXTURE1_ARB);
                  glTexCoordPointer (2, GL_FLOAT, 0, m_hMapArray[0].texCoord1);

                  glDrawArrays (GL_TRIANGLES, 0, m_hMapArray[0].numPoints);
            }

            //shutdown the multitextures

            glActiveTextureARB(GL_TEXTURE1_ARB);
            glDisable(GL_TEXTURE_2D);
            glActiveTextureARB(GL_TEXTURE0_ARB);
            glDisable(GL_TEXTURE_2D);

            //turn on the standard texture

            glActiveTextureARB(GL_TEXTURE0);
            glEnable (GL_TEXTURE_2D);
//            glClientActiveTextureARB (GL_TEXTURE0);

      }
The problem is that I''m trying to also draw a model (also with vertex arrays) using single texturing after I draw the terrain. If I un-comment the last line "glClientActiveTextureARB(GL_TEXTURE0)" then the model is drawn properly with it''s one texture but the terrain only draws the base texture and not the detail texture. But if I keep the "ClientActiveTexture" commented out, then the terrain is multitextured, but the model isn''t textured at all. Can anyone help me out? Thanks. (and don''t worry about the "bind_texture" calls, it''s just calls glBindTexture)
You have to enable texture arrays for each texture unit you are using:
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_COORD_ARRAY);

And you will have to enable texturing for each texture unit:
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);

And when rendering, you have to specify the texture coordinate array for every texture unit:
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer (2, GL_FLOAT, 0, &TexCoords1[0]);
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer (2, GL_FLOAT, 0, &Texcoords2[0]);


hmm.... In the end there your code looks a bit strange...
You''re disabling texture unit zero, and then enabling it again right after... You only need to disable texture unit one...
Advertisement
Yup, that did the trick, Thanks so much for helping me out.

This topic is closed to new replies.

Advertisement