GL_INTERPOLATE & VBO

Hi,
I am having difficulties with interpolating two textures using ARB_texture_env_combine.

I know exactly what i want but i can’t figure out
how to deal with vertex buffer objet and multitexturing at the same time.
it’s maybe too much for me ^^

If you are eager to help, i made a small application to show my problems.

http://gorre.nerim.net/vbo_env_combine.rar ( 2 149 kB)

One of the two textures doesn’t show up (grass).
I want a simple interpolation between the two textures using alpha.
(the heightfield is made of 130k triangles in 256 triangle_strips in VBOs)

I have ~400 FPS in 640x480 (~50Mtris/s)

Barton AthlonXP 2700 @(10*200MHz FSB)
Radeon9700 Pro
512 MB DDR 3200
Win2K SP4
Catalyst 4.5

Originally posted by brucemangy:
[b]

One of the two textures doesn’t show up (grass).

[/b]
Actually the grass texture seems to be there but the tiling is so small that it appear full green…
I didn’t look deeply in you’r code but it seems that you forget to call glEnableClientState(GL_TEXCOORD_ARRAY) for each texture unit

cheers

Didn’t look at your code, but I’d go for the same reason as glitch.

glClientActiveTextureARB is what you need to properly setup vertex arrays with multiple texcoord sets. The mechanism is the same for VBOs.

Popular topic, a search for “multitexture” and “array” should turn up plenty of material :slight_smile:

Basically you do this

glClientActiveTextureARB(GL_TEXTURE0_ARB);
glBindBufferARB(bla);       //optional ...
glTexCoordPointer(bla);     //affects texture0 texcoords
glEnableClientState(GL_TEXTURE_COORDINATE_ARRAY); //affects texture0 texcoords

glClientActiveTextureARB(GL_TEXTURE1_ARB);
glBindBufferARB(bla);       //extremely optional
glTexCoordPointer(bla);     //affects texture1 texcoords
glEnableClientState(GL_TEXTURE_COORDINATE_ARRAY); //affects texture1 texcoords

etc

ok thx to your help and a few search
i did it ^^.
i was using glActiveTextureARB(GL_TEXTUREn_ARB)
in spite of glClientActiveTextureARB(GL_TEXTUREn_ARB)

http://gorre.nerim.net/vbo_env_combine_working_no_lighting.rar

 

  // enabling vertex arrays
  glEnableClientState(GL_VERTEX_ARRAY);
  glEnableClientState(GL_COLOR_ARRAY);
  glEnableClientState(GL_TEXTURE_COORD_ARRAY);

  // go multitexturing !
    // T0
  glActiveTextureARB(GL_TEXTURE0_ARB);
  glBindTexture(GL_TEXTURE_2D, textures[0]);
  glEnable(GL_TEXTURE_2D);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

    // T1
  glActiveTextureARB(GL_TEXTURE1_ARB);
  glBindTexture(GL_TEXTURE_2D, textures[1]);
  glEnable(GL_TEXTURE_2D);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
  glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB , GL_INTERPOLATE_ARB);
  
  glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB , GL_PREVIOUS_ARB);		
  glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
  glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB , GL_TEXTURE);				
  glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);			
  glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB , GL_PRIMARY_COLOR_ARB);	
  glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);	

  for (k=0;k<255;k++)
  {
      glBindBufferARB(GL_ARRAY_BUFFER_ARB, brucevbo[k].vboaddress);    // "vertex buffer object"
      glVertexPointer  (3, GL_FLOAT, 0, NULL );				     //
      glBindBufferARB(GL_ARRAY_BUFFER_ARB, brucevbo[k].cboaddress);    // "color buffer object"
      glColorPointer   (4, GL_FLOAT, 0, NULL );				     //

	  glClientActiveTextureARB(GL_TEXTURE0_ARB);
	  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	  glBindBufferARB(GL_ARRAY_BUFFER_ARB, brucevbo[k].t1boaddress);
        glTexCoordPointer(2, GL_FLOAT, 0, NULL );                      // "tex coord 1 buffer object"

	  glClientActiveTextureARB(GL_TEXTURE1_ARB);
	  glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	  glBindBufferARB(GL_ARRAY_BUFFER_ARB, brucevbo[k].t2boaddress);
        glTexCoordPointer(2, GL_FLOAT, 0, NULL );                      // "tex coord 2 buffer object"

      glDrawArrays(GL_TRIANGLE_STRIP, 0, 512);

  	  glClientActiveTextureARB(GL_TEXTURE0_ARB);
	  glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	  glClientActiveTextureARB(GL_TEXTURE1_ARB);
	  glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  }

  // return to single texturing
  glActiveTextureARB(GL_TEXTURE1_ARB);
  glDisable(GL_TEXTURE_2D);
  glActiveTextureARB(GL_TEXTURE0_ARB);
  glEnable(GL_TEXTURE_2D);

  // Disabling vertex arrays
  glDisableClientState(GL_VERTEX_ARRAY);
  glDisableClientState(GL_COLOR_ARRAY);
  glDisableClientState(GL_TEXTURE_COORD_ARRAY);

 

the blending is ok but i lost the lighting :confused:
is there any way to get it back?

P.S.: Glitch, we have a friend in common ^^.
I’m working with Nounours on this project.

Originally posted by brucemangy:
[b]

the blending is ok but i [b] lost the lighting [/b]:/
is there any way to get it back?
[/b]

It would be probably better if you setup a light (glEnable(GL_LIGHTING); glEnable(GL_LIGHT0) …) :wink:
Then u probably need to set the TEX_ENV_COMBINE of texture0 to GL_MODULATE (it modulate the result of the previous texture unit operation (gl lighting for tu0) with the color of the texel)


P.S.: Glitch, we have a friend in common ^^.
I’m working with Nounours on this project.

I know; if u need on site support :wink: nounours knows where to find me (or mail)

with interpolate you wont have light in the second tex unit

but you could try following combines:
in tex0 and tex1 your textures are bound

tex 0 = replace: texture
tex 1 = interpolate: previous & texture
tex 2 = modulate: previous * primary color (it wont matter what tex is bound here)

or if you have arb_tex_env_route or nv_combine4

tex 0 = interpolate : tex0 & tex1
tex 1 = modulate: previous * primary color

I made this little app to expose my problems.
In my project, lighting is already enabled correctly.

i do not understand how to obtain this equation :
“modulate: previous * primary color”

i do not think this is a simple
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE);

maybe :

  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
  glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB , GL_MODULATE);

  glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB , GL_PREVIOUS_ARB);		
  glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
  glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB , GL_PRIMARY_COLOR_ARB);				
  glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

would make sense ?
(doesn’t work anyway ^^)

I can’t find any ARB_texture_env_route
but ARB_texture_env_crossbar seems to be what you were talking about.

http://gorre.nerim.net/OpenGL/
algorithms & screenshots
my glTexEnv must be wrong ^^

PS.: i need to do that with 2 TMUs max with ARB_texture_env_crossbar.

Thx

brucemangy

ah yeah crossbar it was :slight_smile:

they are all gl_combine
so not modulate directly but thru combine

which imo should work, at least does for me

looked at your 1st pass:

      glBindBufferARB(GL_ARRAY_BUFFER_ARB, brucevbo[k].vboaddress);// "vertex buffer object"
      glVertexPointer  (3, GL_FLOAT, 0, NULL );					   //
      glBindBufferARB(GL_ARRAY_BUFFER_ARB, brucevbo[k].nboaddress);// "normal buffer object"
      glColorPointer   (4, GL_FLOAT, 0, NULL );					   //
      glBindBufferARB(GL_ARRAY_BUFFER_ARB, brucevbo[k].cboaddress);// "color buffer object"
      glColorPointer   (4, GL_FLOAT, 0, NULL );   

you point 2 times to color pointer, hence your normals go wrong and the lighting looks so off

good old copy/paste bug hehe

you rox dude ! :smiley:
well yeah good old copy/paste bug like you said :rolleyes:

Sometimes the mistake is really obvious but you do not look at the right place.

Thanks a lot guys.
It’s faster almost by a factor of 2.
Amazing !


brucemangy