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:
- the initialization of OpenGL (i checked for the multitexture extension and the number of texture units),
- 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?