MiniGL and glTexEnvi/f() parameters

This forum is for general developer support questions.
Post Reply
AmiDARK
Posts: 40
Joined: Thu Oct 20, 2011 10:23 am

MiniGL and glTexEnvi/f() parameters

Post by AmiDARK »

Hello.

I'd like to make textures combination using 2 textures (double-texturing) but I never get a good result.
I've found a tutorial explaining some of the requirements :
http://www.informit.com/articles/articl ... 9&seqNum=6

It seem well explained so, I did this :

Code: Select all

      glActiveTexture(GL_TEXTURE0);
      glEnable( GL_TEXTURE_2D );
      TrueIndex = MyImagePTR->TrueImageIndex;
      glBindTexture( GL_TEXTURE_2D, ImageTexture[ TrueIndex ] );
      glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

      UpdateMyImagePTR( mRaster[ RasterID ].iRaster );
      glActiveTexture(GL_TEXTURE1);
      glEnable( GL_TEXTURE_2D );
      TrueIndex = MyImagePTR->TrueImageIndex;
      glBindTexture( GL_TEXTURE_2D, ImageTexture[ TrueIndex ] );
        switch( Transparency ){
          case 0:
            glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
           break;
          case 1:
            glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
           break;
          case 2:
            glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD );
           break;
          case 3:
            glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD_SIGNED );
           break;
          case 4:
            glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_INTERPOLATE );
           break;
          case 5:
            glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_SUBTRACT );
           break;
          case 6:
            glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DOT3_RGB );
           break;
          case 7:
            glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DOT3_RGBA );
           break;
         }
      glActiveTexture( GL_TEXTURE0 );
In all case I get the same result. the combination of the 2 textures but really dark.
Excepted case 4 for transparency where I only get the 2nd texture really dark.
Do you know exactly what can cause this ?

The wanted result is absolut adding of RED, GREEN & BLUE.
For example:
Texture 1 : RGB : 64, 80, 100
Texture 2 : RGB : 64, 10, 10
Result : RGB : 128, 90, 110
Do you understand ?
Is there someone that know how I can do this ?

EDIT : I've made changes to setup textures like opengl samples do. (source code edited)
in all case the texture remain dark excepted one where it appear bright but the result is not the one wanted.

Thank you.

Regards,
AmiDARK
Sam440EP - AmigaOS 4.1 Final Edition
User avatar
Hans-Joerg Frieden
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 223
Joined: Wed Dec 08, 2010 3:52 pm

Re: MiniGL and glTexEnvi/f() parameters

Post by Hans-Joerg Frieden »

You need to set the TEXTURE_ENV_MODE to GL_COMBINE, and then set the GL_COMBINE_RGB and GL_COMBINE_ALPHA to the combiner functions you want.

GL_TEXTURE_ENV_COMBINE can only take the values MODULATE, DECAL, BLEND, REPLACE or COMBINE. If you set it to COMBINE, it will be able to use the GL_COMBINE_RGB and GL_COMBINE_ALPHA functions for multitexturing. If you want to add two textures, you would set

glActiveTexture( GL_TEXTURE0 );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
glActiveTexture( GL_TEXTURE1 );
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD );
EDIT: to be sure, you should also add
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE );
NOTICE: If you want to contact me, use E-Mail. I cannot be contacted via the forum/private messages anymore
AmiDARK
Posts: 40
Joined: Thu Oct 20, 2011 10:23 am

Re: MiniGL and glTexEnvi/f() parameters

Post by AmiDARK »

Thank you Hans for your answer.

I will test this now :)

Regards,
AmiDARK
Sam440EP - AmigaOS 4.1 Final Edition
Post Reply