jagarciauceda's picture

Alpha function and textures

Hello everybody, I am new working with OpenTK and I would like to know how can apply the alpha funtion at one texture, wiht an example please?¿?

now I am doing this to put a texture/image in my game: I use the color to put a alpha in a texture but after to use this....all my images change of colour!!!! I am a little desesperate... :(

     public static void DImage(int image, float x, float y, int sizeW, int sizeH,bool flag_alfa, float alfa)
        {
 
 
            GL.MatrixMode(MatrixMode.Projection);
            GL.PushMatrix();
            GL.LoadIdentity();
 
            // esto es una movida mejor no tocarlo  
            GL.Ortho(0, 800, 600, 0, -1, 1);
 
 
            GL.MatrixMode(MatrixMode.Modelview);
            GL.PushMatrix();
            GL.LoadIdentity();
 
            GL.Disable(EnableCap.Lighting);
 
            GL.Enable(EnableCap.Texture2D);
 
            //movemos la imagen por la pantalla con esto
            GL.Translate(x, y, 0f);
 
            GL.BindTexture(TextureTarget.Texture2D, image);
 
            if (flag_alfa)
            {
                GL.Color4(0.0f, 0.0f, 0.0f, alfa);
            }
 
            GL.Begin(BeginMode.Quads);
 
                    GL.TexCoord2(0, 0);
                    GL.Vertex3(0, 0, 0);
 
                    GL.TexCoord2(1, 0);
                    GL.Vertex3(sizeW, 0, 0);
 
                    GL.TexCoord2(1, 1);
                    GL.Vertex3(sizeW, sizeH, 0);
 
                    GL.TexCoord2(0, 1);
                    GL.Vertex3(0, sizeH, 0);
 
            GL.End();
 
 
            GL.Disable(EnableCap.Texture2D);
            GL.PopMatrix();
 
            GL.MatrixMode(MatrixMode.Projection);
            GL.PopMatrix();
 
            GL.MatrixMode(MatrixMode.Modelview);
 
 
        }

Thank you in advance!!


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

You need to enable blending and set the blending factors before rendering your texture. Disable blending afterwards to avoid affecting other textures.

Take a look here for more information: http://www.opentk.com/doc/chapter/2/opengl/fragment-ops/blending