Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Multitexturing problem in Age of Empires

  1. #1
    Intern Newbie
    Join Date
    Jul 2006
    Posts
    39

    Multitexturing problem in Age of Empires

    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_CO MBINE_EXT);
    glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT, GL_MODULATE );

    glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_EXT,GL_P REVIOUS_EXT);
    glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA_EXT,GL_ SRC_ALPHA);

    glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_EXT,GL_TEX TURE);
    glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_EXT,GL_SR C_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?

  2. #2
    Intern Newbie
    Join Date
    Jul 2006
    Posts
    39

    Re: Multitexturing problem in Age of Empires

    Somebody told me to try this

    // render grass
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glBindTexture(GL_TEXTURE_2D, grassID);

    RenderTerrain();

    // render dirt
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glBindTexture(GL_TEXTURE_2D, alphaMapID);

    glActiveTextureARB(GL_TEXTURE1_ARB);
    glBindTexture(GL_TEXTURE_2D, dirtID);
    glEnable(GL_TEXTURE_2D);
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_CO MBINE_EXT);
    glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_EXT, GL_MODULATE );

    glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_EXT,GL_P REVIOUS);
    glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA_EXT,GL_ SRC_ALPHA);
    glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_ALPHA_EXT,GL_P REVIOUS);
    glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_ALPHA_EXT,GL_ SRC_ALPHA);

    glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_EXT,GL_TEX TURE);
    glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_EXT,GL_SR C_COLOR);
    glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_EXT,GL_TEX TURE);
    glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_EXT,GL_SR C_COLOR);

    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);


    But i cannot understand for the dirt+alpha map part...why he has multiplied the alpha channel of tex unit 1 with itself in :-
    glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_EXT,GL_P REVIOUS);
    glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA_EXT,GL_ SRC_ALPHA);
    glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_ALPHA_EXT,GL_P REVIOUS);
    glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_ALPHA_EXT,GL_ SRC_ALPHA);


    Then the rgb of tex unit 2 with itself in:-
    glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_EXT,GL_TEX TURE);
    glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_EXT,GL_SR C_COLOR);
    glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_EXT,GL_TEX TURE);
    glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_EXT,GL_SR C_COLOR);

    ....i dont get why this has to be done

    Also 1 more question.The following segment is to blend in the alpha modulated dirt texture with the already existing grass texture in frame buffer right?

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    RenderTerrain();

    glDisable(GL_BLEND);


    And of course i would like to store the alpha map as 8 bit textures....can i mix that with my 24 bit dirt texture?(i dont need alpha channel in dirt texture ...so 24 bit)

  3. #3
    Intern Newbie
    Join Date
    Jul 2006
    Posts
    39

    Re: Multitexturing problem in Age of Empires

    Also currently my alpha map is done like this
    Code :
    //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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •