Jump to content


Multitexturing Problem in Age of empires


1 reply to this topic

#1 madmax

    New Member

  • Members
  • PipPip
  • 10 posts

Posted 19 December 2006 - 04:39 PM

I am trying to make a terrain engine like age of empires. Its 2D isometric.I plan to produce the terrain like this.
1.Render a base texture like grass
2.Render another texture on top like sand but control its alpha using an alpha texture(or map i think its called).

i tried this



// render grass

glActiveTextureARB(GL_TEXTURE0_ARB);

glBindTexture(GL_TEXTURE_2D, textures[0]);


RenderTerrain();


// render dirt


// TEXTURE-UNIT #0:Alpha Map

glActiveTextureARB(GL_TEXTURE0_ARB);

glBindTexture(GL_TEXTURE_2D, textures[2]);


// TEXTURE-UNIT #1:Farm

glActiveTextureARB(GL_TEXTURE1_ARB);

glBindTexture(GL_TEXTURE_2D, textures[1]);


glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE_EXT);

glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT, GL_MODULATE );


glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_EXT,GL_PREVIOUS_EXT);

glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA_EXT,GL_SRC_ALPHA);


glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_EXT,GL_TEXTURE);

glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_EXT,GL_SRC_COLOR);



glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glBegin(GL_QUADS);


glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.0,0.0);

glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.0,0.0);

glVertex2i(0,0);


glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.378,0.0);

glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.378,0.0);

glVertex2i(TILE_WIDTH,0.0);


glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.378,0.765);

glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.378,0.765);

glVertex2i(TILE_WIDTH,TILE_HEIGHT);


glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0.0,0.765);

glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0.0,0.765);

glVertex2i(0.0,TILE_HEIGHT);



glEnd();


glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


RenderTerrain();


glDisable(GL_BLEND);


// disable 2nd texture unit

glActiveTextureARB(GL_TEXTURE1_ARB);

glDisable(GL_TEXTURE_2D);



This should render the base grass texture.Then multiply the alpha channel from textures[2] with rgb channel of textures[1]but i only get the 1st texture(grass) on the screen....yet i have seen other programs use multitexturing perfectly on my card.But no matter wat i use i seem to get only the 1st texture.....am i missing something?



Also currently my alpha map is done like this



//Texture 3-------------Alpha Map

SDL_LockSurface(TextureImage[2]);

for( i=0; i<TextureImage[2]->h; i++)

  for( j=0; j<TextureImage[2]->w; j++){

    x = Uint32( 128<<24 | 0<<16 | 0<<8 | 0<<0);

    printf("\nAlpha set:%p",x);

    ((unsigned int*)TextureImage[2]->pixels)[i*TextureImage[2]->w+j] = x;

  }

SDL_UnlockSurface(TextureImage[2]);



i simply take an rgb image loaded using SDL_image & make the alpha component 128 & rgb=0 in all pixels....but surely there is a better way to produce alpha maps...because here i am wasting space.Ideally there shud be only 1 8bit component(the alpha values)...but then how do i multiply it with the rgb of the other texture unit?

#2 Nils Pipenbrinck

    Senior Member

  • Members
  • PipPipPipPip
  • 597 posts

Posted 19 December 2006 - 07:40 PM

Do you have called glEnable (GL_TEXTURE_2D) for all active texture units? glEnable (GL_TEXTURE_2D) is in the scope of glActiveTexture, and it's easy to forget to just enable it.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users