PDA

View Full Version : VBO and Multitexturing with a Cubemap



Swiftless
05-06-2006, 12:01 AM
I have recently switched over the VBO's and have implemented Multitexturing.

I have just tried adding Dot3 bump mapping using other extensions and all I see now is black, unless I change the texture environment variables, then I see purple or a green that fades to red.

The code for the bump mapping works perfectly using normal glVertex3f and glMultiTexCoord3fARB calls:


vertex_position = get_vec3( ((float)mapX+LOD)/(float)MapWidth, Height, (float)mapZ/(float)MapHeight);
vertex_to_light[0] = light_position[0] - vertex_position[0];
vertex_to_light[1] = light_position[1] - vertex_position[1];
vertex_to_light[2] = light_position[2] - vertex_position[2];

glMultiTexCoord3fARB(GL_TEXTURE0_ARB, vertex_to_light[0], vertex_to_light[1], vertex_to_light[2]);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, (float)mapX/(float)MapWidth, ((float)mapZ)/(float)MapHeight);
glMultiTexCoord2fARB(GL_TEXTURE2_ARB, (float)mapX/(float)MapWidth, ((float)mapZ)/(float)MapHeight);
glMultiTexCoord2fARB(GL_TEXTURE3_ARB, 0, 0);
glVertex3f(mapX*scale*3,Height*scaleheight,mapZ*sc ale); I am using the same code in the VBO version to create the normalisation cube map and the code for implementing it is as:

glActiveTextureARB(GL_TEXTURE0);
glEnable(GL_TEXTURE_CUBE_MAP_ARB);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, normalization_cube_map);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE) ;
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoordsNorm );
glTexCoordPointer( 3, GL_FLOAT, 0, (char *) NULL );
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glActiveTextureARB(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[tGNormalMap]);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS) ;
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE) ;
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoordsGround );
glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glActiveTextureARB(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[tGround]);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoordsGround );
glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glActiveTextureARB(GL_TEXTURE3);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[tGDetailMap]);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoordsGround );
glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );
glEnableClientState(GL_TEXTURE_COORD_ARRAY); Followed by the required glDisable calls after the drawing.

The only difference is that the texture coordinates for the VBO normalisation cube map is generated at run time with all the other vertex and texture coordinates while in the old version, it sets the coordinates in real time, during the code to create my object.

Can anyone tell me what is wrong with this for it to not work...

I have been trying to find what is wrong since last night and it is really frustrating, especially when other people code that I find, looks similar to mine, but still does not work.

The code I am using to create the normalisation map is the code on NeHe, if that helps.

brtnrdr
05-06-2006, 12:48 AM
when setting the texture coordinate pointers try using glClientActiveTexture(GL_TEXTUREX), check the documention on that function, it should do what you're trying to do above (replace X above with the number you need).

Swiftless
05-06-2006, 03:25 AM
Thanks, I will give it a go.

Which texture should I use it on though?

All of them or just the cube map?

Swiftless
05-07-2006, 05:04 AM
I have figured it out.
I have changed left all the:
glActiveTextureARB(GL_TEXTUREX);
but have called the line:
glClientActiveTexture(GL_TEXTUREX);
before every glActiveTexture call.

Now it works.
For people who want to know, the code now looks like:

glClientActiveTexture(GL_TEXTURE3);
glActiveTextureARB(GL_TEXTURE3);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[tGDetailMap]);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 2);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoordsGround );
glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );
glEnableClientState(GL_TEXTURE_COORD_ARRAY); for all my texture calls.

Thanks for your help brtnrdr.

jide
05-07-2006, 11:01 AM
Have a deeper look for when to use client or server side functions. It will really help you understand some basic points about the GL state machine.