コード例 #1
0
        void Render(IntPtr pParameter)
        {
            TRectF  sectionRect;
            uint    txt_w, txt_h;
            TColor4 white = TColor4.ColorWhite();;

            pRender2D.Begin2D();

            // First section with primitives. //
            sectionRect = new TRectF(0f, 0f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect); // here and below scissor test is used to prevent drawing something to another section of the screen

            DrawPrimitives(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec1 = "Primitives";

            pFont.GetTextDimensions(txtSec1, out txt_w, out txt_h);
            // here and below draw section label near the end of each section
            pFont.Draw2DSimple((int)((ScreenWidth / 2 - txt_w) / 2), (int)(ScreenHeight / 2 - txt_h), txtSec1, ref white);

            // Second section with font rendering. //
            sectionRect = new TRectF(ScreenWidth / 2f, 0f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect);

            DrawFont(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec2 = "Fonts";

            pFont.GetTextDimensions(txtSec2, out txt_w, out txt_h);
            pFont.Draw2DSimple((int)(ScreenWidth / 2 + (ScreenWidth / 2 - txt_w) / 2),
                               (int)(ScreenHeight / 2 - txt_h), txtSec2, ref white);

            // Third section with sprites. //
            sectionRect = new TRectF(0f, ScreenHeight / 2f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect);

            DrawSprites(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec3 = "Sprites";

            pFont.GetTextDimensions(txtSec3, out txt_w, out txt_h);
            pFont.Draw2DSimple((int)((ScreenWidth / 2 - txt_w) / 2f), (int)(ScreenHeight - txt_h - 25), txtSec3, ref white);

            // Fourth section with advanced techniques. //
            sectionRect = new TRectF(ScreenWidth / 2f, ScreenHeight / 2f, ScreenWidth / 2f, ScreenHeight / 2f);
            pRender.EnableScissor(ref sectionRect);

            DrawAdvanced(sectionRect);
            pRender2D.DrawRectangle(ref sectionRect, ref white);

            const string txtSec4 = "Advanced";

            pFont.GetTextDimensions(txtSec4, out txt_w, out txt_h);
            pFont.Draw2DSimple((int)(ScreenWidth / 2 + (ScreenWidth / 2 - txt_w) / 2f), (int)(ScreenHeight - txt_h - 25), txtSec4, ref white);

            pRender.DisableScissor(); // The way to turn off scissor test, you must do it manually before the end of the frame.

            pRender2D.End2D();
        }