Exemple #1
0
    //public CollisionData collisionData;

    public void Render()
    {
        GraphicsHelperGl g = new GraphicsHelperGl();

        g.SetMaterialColor(new double[] { 1, 1, 1, 1 });
        g.PushMatrix();
        //g.Translate(0, 0, 10);
        Gl.glRotated(90, 1, 0, 0);
        g.EnableTexture2d();
        g.CheckError();
        texture1.Apply();
        unitpart.Render();
        g.PopMatrix();
        g.Bind2DTexture(0);
        g.CheckError();
    }
        // applies texture stage setup to gl.  texturestagenum will be 0 except for blend
        // where it will be either 0 or 1
        // texture coordinates are handled independently (?)
        // either we're using multipass or we're using multitexture.  multipass still uses 2 multitexture units, but not 4, 6, 8, ...
        public void Apply(int texturestagenum, bool UsingMultipass, int mapwidth, int mapheight)
        {
            //Console.WriteLine( "MapTextureStageView for " + maptexturestagemodel + " " + ((GlTexture)splattexture).GlReference +  " Apply" );
            GlTextureCombine texturecombine;
            GraphicsHelperGl g = new GraphicsHelperGl();

            switch (maptexturestagemodel.Operation)
            {
            case MapTextureStageModel.OperationType.NoTexture:
                g.DisableTexture2d();
                g.EnableModulate();
                break;

            case MapTextureStageModel.OperationType.Add:
                splattexture.Apply();
                SetTextureScale(1 / (double)maptexturestagemodel.Tilesize);
                texturecombine           = new GlTextureCombine();
                texturecombine.Operation = GlTextureCombine.OperationType.Add;
                texturecombine.Args[0].SetRgbaSource(GlCombineArg.Source.Previous);
                texturecombine.Args[1].SetRgbaSource(GlCombineArg.Source.Texture);
                texturecombine.Apply();
                break;

            case MapTextureStageModel.OperationType.Blend:
                if (UsingMultipass)
                {
                    if (texturestagenum == 0)
                    {
                        blendtexture.Apply();
                        SetTextureScale(1 / (double)mapwidth);
                        texturecombine           = new GlTextureCombine();
                        texturecombine.Operation = GlTextureCombine.OperationType.Replace;
                        texturecombine.Args[0].SetAlphaSource(GlCombineArg.Source.Texture, GlCombineArg.Operand.Alpha);
                        texturecombine.Apply();
                    }
                    else
                    {
                        splattexture.Apply();
                        SetTextureScale(1 / (double)maptexturestagemodel.Tilesize);
                        new GraphicsHelperGl().EnableModulate();
                    }
                }
                else
                {
                    if (texturestagenum == 0)
                    {
                        blendtexture.Apply();
                        SetTextureScale(1 / (double)mapwidth);
                        texturecombine           = new GlTextureCombine();
                        texturecombine.Operation = GlTextureCombine.OperationType.Replace;
                        texturecombine.Args[0].SetRgbSource(GlCombineArg.Source.Previous, GlCombineArg.Operand.Rgb);
                        texturecombine.Args[0].SetAlphaSource(GlCombineArg.Source.Texture, GlCombineArg.Operand.Alpha);
                        texturecombine.Apply();
                    }
                    else
                    {
                        splattexture.Apply();
                        SetTextureScale(1 / (double)maptexturestagemodel.Tilesize);
                        texturecombine           = new GlTextureCombine();
                        texturecombine.Operation = GlTextureCombine.OperationType.Interpolate;
                        texturecombine.Args[0].SetRgbaSource(GlCombineArg.Source.Previous);
                        texturecombine.Args[1].SetRgbaSource(GlCombineArg.Source.Texture);
                        texturecombine.Args[2].SetRgbSource(GlCombineArg.Source.Previous, GlCombineArg.Operand.Alpha);
                        texturecombine.Args[2].SetAlphaSource(GlCombineArg.Source.Previous, GlCombineArg.Operand.Alpha);
                        texturecombine.Apply();
                    }
                }
                break;

            case MapTextureStageModel.OperationType.Multiply:
                splattexture.Apply();
                SetTextureScale(1 / (double)maptexturestagemodel.Tilesize);
                texturecombine           = new GlTextureCombine();
                texturecombine.Operation = GlTextureCombine.OperationType.Modulate;
                texturecombine.Args[0].SetRgbaSource(GlCombineArg.Source.Previous);
                texturecombine.Args[1].SetRgbaSource(GlCombineArg.Source.Texture);
                texturecombine.Apply();
                break;

            case MapTextureStageModel.OperationType.Subtract:
                splattexture.Apply();
                SetTextureScale(1 / (double)maptexturestagemodel.Tilesize);
                texturecombine           = new GlTextureCombine();
                texturecombine.Operation = GlTextureCombine.OperationType.Subtract;
                texturecombine.Args[0].SetRgbaSource(GlCombineArg.Source.Previous);
                texturecombine.Args[1].SetRgbaSource(GlCombineArg.Source.Texture);
                texturecombine.Apply();
                break;

            case MapTextureStageModel.OperationType.Replace:
                splattexture.Apply();
                SetTextureScale(1 / (double)maptexturestagemodel.Tilesize);
                texturecombine           = new GlTextureCombine();
                texturecombine.Operation = GlTextureCombine.OperationType.Modulate;
                texturecombine.Args[0].SetRgbaSource(GlCombineArg.Source.Texture);
                texturecombine.Args[1].SetRgbaSource(GlCombineArg.Source.Fragment);
                texturecombine.Apply();
                break;
            }
        }