Exemplo n.º 1
0
        void RenderPlanetInToTexture()
        {
            TColor4 c = TColor4.ColorWhite(0); // set clear color here because SetRenderTarget will clear color buffer for us

            pRender.SetClearColor(ref c);
            pRender.SetRenderTarget(pTexPlanetRenderIn);

            pRender2D.Begin2D();

            TPoint2 pos = new TPoint2();
            TPoint2 dim = new TPoint2(256f, 256f);

            pRender2D.DrawTexture(pTexMask, ref pos, ref dim, 0f, E_EFFECT2D_FLAGS.EF_BLEND);

            pRender2D.SetBlendMode(E_BLENDING_EFFECT.BE_MASK);

            float texOffsetX = counter / 200f;

            // generate two triangles to form a quad and move their texture coordinates horizontally
            TVertex2[] quad =
            {
                new TVertex2(0f,     0f, texOffsetX,      0f, 1f, 1f, 1f, 1f),
                new TVertex2(256f,   0f, 1f + texOffsetX, 0f, 1f, 1f, 1f, 1f),
                new TVertex2(256f, 256f, 1f + texOffsetX, 1f, 1f, 1f, 1f, 1f),
                new TVertex2(0f,     0f, texOffsetX,      0f, 1f, 1f, 1f, 1f),
                new TVertex2(256f, 256f, 1f + texOffsetX, 1f, 1f, 1f, 1f, 1f),
                new TVertex2(0f,   256f, 0f + texOffsetX, 1f, 1f, 1f, 1f, 1f)
            };

            pRender2D.DrawTriangles(pTexPlanet, ref quad[0], (uint)quad.Length, E_PRIMITIVE2D_FLAGS.PF_FILL);

            pRender2D.End2D();

            c = TColor4.ColorOfficialBlack();
            pRender.SetClearColor(ref c); // set clear color back
            pRender.SetRenderTarget(null);
        }
Exemplo n.º 2
0
        void Init(IntPtr pParam)
        {
            IEngineSubSystem pSubSys;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RENDER, out pSubSys);
            pRender = (IRender)pSubSys;
            TColor4 c = TColor4.ColorOfficialBlack();

            pRender.SetClearColor(ref c);
            pRender.GetRender2D(out pRender2D);

            IResourceManager pResMan;

            pEngineCore.GetSubSystem(E_ENGINE_SUB_SYSTEM.ESS_RESOURCE_MANAGER, out pSubSys);
            pResMan = (IResourceManager)pSubSys;

            IEngineBaseObject pBaseObj = null;

            // for fonts part
            pResMan.Load(ResPath + "fonts\\Times_New_Roman_12_rus.dft", out pBaseObj, 0);
            pFont = (IBitmapFont)pBaseObj;
            pResMan.Load(ResPath + "fonts\\Times_New_Roman_18_Bold.dft", out pBaseObj, 0);
            pFontBold = (IBitmapFont)pBaseObj;
            pResMan.Load(ResPath + "fonts\\TheHard_18.dft", out pBaseObj, 0);
            pFontHard = (IBitmapFont)pBaseObj;

            // for sprites part
            const uint unfiltered_2d_flag = (uint)(E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_NONE /* for cool old-school pixelized image */ |
                                                   E_TEXTURE_LOAD_FLAGS.TLF_COORDS_CLAMP);

            pResMan.Load(ResPath + "textures\\cartoon_grass.tga", out pBaseObj, unfiltered_2d_flag |
                         (uint)E_TEXTURE_LOAD_FLAGS.TLF_DECREASE_QUALITY_MEDIUM /* decrease texture size to make it more pixelized */);
            pTexGrass = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\cartoon_tank_body.png", out pBaseObj, unfiltered_2d_flag);
            pTexTankBody = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\cartoon_tank_turret.png", out pBaseObj, unfiltered_2d_flag);
            pTexTankTurret = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\cartoon_anime_girl.png", out pBaseObj, unfiltered_2d_flag);
            pTexGirl = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\cartoon_mistery_light.jpg", out pBaseObj, unfiltered_2d_flag |
                         (uint)E_TEXTURE_LOAD_FLAGS.TLF_DECREASE_QUALITY_HIGH);
            pTexLight = (ITexture)pBaseObj;

            pTexGirl.SetFrameSize(55, 117);
            pTexLight.SetFrameSize(64, 128);

            // for advanced part
            pResMan.Load(ResPath + "meshes\\planets\\asteroid.jpg", out pBaseObj, (uint)(E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR |
                                                                                         E_TEXTURE_LOAD_FLAGS.TLF_COORDS_MIRROR_REPEAT));
            pTexPlanet = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\light.jpg", out pBaseObj, 0);
            pTexLightRound = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\sphere_mask.png", out pBaseObj, 0);
            pTexMask = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\cartoon_cloudy_night_sky.jpg", out pBaseObj, 0);
            pTexBg = (ITexture)pBaseObj;
            pResMan.Load(ResPath + "sprites\\jellyfish.png", out pBaseObj, 0);
            pTexJellyFish = (ITexture)pBaseObj;

            for (int i = 0; i < 11; i++)
            {
                pResMan.Load(ResPath + "textures\\water\\water_" + i + ".tga", out pBaseObj, (uint)(E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR |
                                                                                                    E_TEXTURE_LOAD_FLAGS.TLF_COORDS_MIRROR_REPEAT /* let's repeat the texture this way to make it little weird */));
                pTexAnimWater[i] = (ITexture)pBaseObj;
            }

            pResMan.CreateTexture(out pTexPlanetRenderIn, null, 256, 256, E_TEXTURE_DATA_FORMAT.TDF_RGBA8,
                                  E_TEXTURE_CREATE_FLAGS.TCF_DEFAULT, E_TEXTURE_LOAD_FLAGS.TLF_FILTERING_BILINEAR |
                                  E_TEXTURE_LOAD_FLAGS.TLF_COORDS_CLAMP);
        }