using multitexturing

Hi,
I’m trying to get multitexturing done using the ARB_multitexture extension, but something went wrong.
In the first version of my program, I did not use multitexturing and created a display list for a sphere with a texture of earth. Texture relevant calls have been:
glBindTexture( GL_TEXTURE_2D, texture[0] );
and between glBegin / glEnd:
glTexCoord2f( s, t );
That worked fine.

Now instead of using glBindTexture, I’m using code that makes use of the multitexture extension:
glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture[0] );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
and between glBegin / glEnd:
glMultiTexCoord2fARB( GL_TEXTURE0_ARB, s, t);

Now instead of a nice earth I do have some blue globe (maybe a small part of the texture, a very small part in this case).

What am I doing wrong?

EDIT: digging deeper into the forums, i found out that i had to disable the other texture units. But there’s still a graphical glitch, on one quarter of my sphere I have streaks which i cannot explain.

Here’s the render of the image with multitexture:

Here’s the render of the image without multitexture:

Anyone knows what i’m doing wrong?

From what you said it should work the same way as without using texture units. Also, just a note, you’re not obliged to use the ARB/EXT extensions of the functions since it is now full part of GL 1.2. But that’s not the problem thought.

The other texture units are disable by default just as the first texture unit (or the texture when not using multitexture).

Did you ensure the texture is displaid fine everywhere when not using multitexturing ?

Can you give more information ? Are there the only changes you made ? Give more code ?

Hi,
thx for the quick reply. The only thing I changed between the two codebases is I switched to multitexture rendering. The only changes I made in code are:

  1. the initialization of OpenGL (i checked for the multitexture extension and the number of texture units),
  2. the way the sphere gets rendered.

Ok, here comes more code.
Thats how i generate a texture (all textures are generated the same):
glGenTextures( 1, &texture[0] );
glBindTexture( GL_TEXTURE_2D, texture[0] );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, texImage[0]->w, texImage[0]->h, 0, GL_BGR, GL_UNSIGNED_BYTE, texImage[0]->pixels );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

Now here’s my code for the sphere (stripped of the triangle strip stuff):
sphere_strip = glGenLists( 1 );
glNewList( sphere_strip, GL_COMPILE );

// init first texture unit
glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture[0] );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

// init second texture unit
glActiveTextureARB( GL_TEXTURE1_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture[3] );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

// disable the last 2 texture units
glActiveTextureARB( GL_TEXTURE2_ARB );
glDisable( GL_TEXTURE_2D );
glActiveTextureARB( GL_TEXTURE3_ARB );
glDisable( GL_TEXTURE_2D );

[snip]
triangle strips and fans go here
[snap]

glEndList();

Here’s a small example how I set the texture coordinates:
alpha = 0.0f;
delta = y / SPHERE_Y_SEG * M_PI;
alpha2 = 1.0f / SPHERE_X_SEG * 2 * M_PI;
delta2 = (y+1.0f) / SPHERE_Y_SEG * M_PI;

glNormal3f( cos( alpha ) * cos( delta ), sin( delta ), sin( alpha ) * cos( delta ) );

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, x / SPHERE_X_SEG, 0.5f + (y / SPHERE_Y_SEG) );
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, x / SPHERE_X_SEG, 0.5f + (y / SPHERE_Y_SEG) );
glVertex3f( cos( alpha )*cos( delta ), sin( delta ), sin( alpha ) * cos( delta ) );

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, x / SPHERE_X_SEG, 0.5f + ((y+1) / SPHERE_Y_SEG) );
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, x / SPHERE_X_SEG, 0.5f + ((y+1) / SPHERE_Y_SEG) );
glVertex3f( cos( alpha )*cos( delta2 ), sin( delta2 ), sin( alpha ) * cos( delta2 ) );

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, (x+1) / SPHERE_X_SEG, 0.5f + (y / SPHERE_Y_SEG) );
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, (x+1) / SPHERE_X_SEG, 0.5f + (y / SPHERE_Y_SEG) );
glVertex3f( cos( alpha2 )*cos( delta ), sin( delta ), sin( alpha2 ) * cos( delta ) );

The render part:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glLoadIdentity();

glTranslatef( tranx, trany, depth );
glRotatef( 170.0f , 0.0f, 0.0f, 1.0f );
glRotatef( -rsphere, 0.0f, 1.0f, 0.0f );

glCallList( sphere_strip );

SDL_GL_SwapBuffers( );

Am I doing something wrong?

ARGH, I found the problem after compiling in console (and not in kdevelop) … I had to define GL_GLEXT_PROTOTYPES at the top of my code …

Perhaps move this thread into the linux section.

or as I said, avoid using the functions with ARB/EXt suffixes.

Anyways, it’s strange you’ve got some “working” stuff without having properly initialized the extension functions. I would have expect other kind of errors.